From cb383183d722a9ef03ab8b8cb0d0e419efd96598 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 29 Oct 2014 17:56:42 +0000 Subject: [PATCH] Fix getPackageInfo("android") in the system server. The fix for bug 16555230 attempted to return the same LoadedApk object between the system context object and the activity thread's list of opened packaged. This ensured that we used the same classLoader on both these objects (among other things). However, the object the Context owns is actually incomplete (and necessarily so) because it might be created before the package manager is and we need the package manager to construct a complete LoadedApk object. Work around this by manually setting the classloader and aInfo for "android" contexts created by the system server's activity thread. bug: 18167468 Change-Id: I623634f912111f89eaf716b8258d1926d2513dcd --- core/java/android/app/ActivityThread.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index fa15ad758cc69..cf6c04959de84 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1742,6 +1742,12 @@ public final class ActivityThread { new LoadedApk(this, aInfo, compatInfo, baseLoader, securityViolation, includeCode && (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); + + if (mSystemThread && "android".equals(aInfo.packageName)) { + packageInfo.installSystemApplicationInfo(aInfo, + getSystemContext().mPackageInfo.getClassLoader()); + } + if (includeCode) { mPackages.put(aInfo.packageName, new WeakReference(packageInfo)); @@ -1802,10 +1808,6 @@ public final class ActivityThread { synchronized (this) { getSystemContext().installSystemApplicationInfo(info, classLoader); - // The code package for "android" in the system server needs - // to be the system context's package. - mPackages.put("android", new WeakReference(getSystemContext().mPackageInfo)); - // give ourselves a default profiler mProfiler = new Profiler(); }