diff options
| author | Alan Viverette <alanv@google.com> | 2015-09-03 14:55:27 -0400 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2015-09-03 14:55:27 -0400 |
| commit | 2107d69d35191c8e16e61720da62ff33290f5a8a (patch) | |
| tree | 097262a0f28d1ffa4c17a6d58a12ffb25a5bdc47 /core/java | |
| parent | 3916e7e757c8d157ee736a86b25c41a0a74015f6 (diff) | |
Postpone loading app context until instrumentation is set up
The application context needs instrumentation data to be in place
prior to construction so that the class loader is initialized using
the correct paths.
Removes unnecessary clearClassLoader() workaround that was previously
added to fix instrumentation tests.
Bug: 22627299
Change-Id: Ibf8e69e037189a9a563f0b68cfe333461726b71d
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 63 | ||||
| -rw-r--r-- | core/java/android/app/LoadedApk.java | 7 |
2 files changed, 30 insertions, 40 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index e15ba742b8b6..d2c2fa78df35 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4593,27 +4593,6 @@ public final class ActivityThread { } updateDefaultDensity(); - final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); - if (!Process.isIsolated()) { - final File cacheDir = appContext.getCacheDir(); - - if (cacheDir != null) { - // Provide a usable directory for temporary files - System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); - } else { - Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property due to missing cache directory"); - } - - // Use codeCacheDir to store generated/compiled graphics code - final File codeCacheDir = appContext.getCodeCacheDir(); - if (codeCacheDir != null) { - setupGraphicsSupport(data.info, codeCacheDir); - } else { - Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); - } - } - - final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24)); DateFormat.set24HourTimePref(is24Hr); @@ -4697,17 +4676,16 @@ public final class ActivityThread { } catch (RemoteException e) {} } + // Instrumentation info affects the class loader, so load it before + // setting up the app context. + final InstrumentationInfo ii; if (data.instrumentationName != null) { - InstrumentationInfo ii = null; try { - ii = appContext.getPackageManager(). - getInstrumentationInfo(data.instrumentationName, 0); + ii = new ApplicationPackageManager(null, getPackageManager()) + .getInstrumentationInfo(data.instrumentationName, 0); } catch (PackageManager.NameNotFoundException e) { - } - if (ii == null) { throw new RuntimeException( - "Unable to find instrumentation info for: " - + data.instrumentationName); + "Unable to find instrumentation info for: " + data.instrumentationName); } mInstrumentationPackageName = ii.packageName; @@ -4717,13 +4695,32 @@ public final class ActivityThread { mInstrumentedAppDir = data.info.getAppDir(); mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); mInstrumentedLibDir = data.info.getLibDir(); + } else { + ii = null; + } + + final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); + if (!Process.isIsolated()) { + final File cacheDir = appContext.getCacheDir(); + if (cacheDir != null) { + // Provide a usable directory for temporary files + System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); + } else { + Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " + + "due to missing cache directory"); + } - // The app context's info was created against this thread, but - // the class loader may have already been loaded and cached with - // outdated paths. Clear it so we can load it again using the - // instrumentation paths. - data.info.clearClassLoader(); + // Use codeCacheDir to store generated/compiled graphics code + final File codeCacheDir = appContext.getCodeCacheDir(); + if (codeCacheDir != null) { + setupGraphicsSupport(data.info, codeCacheDir); + } else { + Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); + } + } + // Continue loading instrumentation. + if (ii != null) { final ApplicationInfo instrApp = new ApplicationInfo(); instrApp.packageName = ii.packageName; instrApp.sourceDir = ii.sourceDir; diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 3b1c60b1501f..c2bf28a931c8 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -255,13 +255,6 @@ public final class LoadedApk { return ai.sharedLibraryFiles; } - /** @hide */ - public void clearClassLoader() { - synchronized (this) { - mClassLoader = null; - } - } - public ClassLoader getClassLoader() { synchronized (this) { if (mClassLoader != null) { |
