Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2107d69d authored by Alan Viverette's avatar Alan Viverette
Browse files

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
parent 3916e7e7
Loading
Loading
Loading
Loading
+30 −33
Original line number Diff line number Diff line
@@ -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;
+0 −7
Original line number Diff line number Diff line
@@ -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) {