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

Commit 71cf350f authored by Winson's avatar Winson
Browse files

Update LoadedApk instead of re-creating on outdated cache

Recreating the entire object drops the mApplication inside,
so multiple Application instances are unexpectedly created.

Instead, call into updateApplicationInfo to replace
the Resources object manually.

Bug: 129890769

Test: device boots, applies overlay paths correctly; was unable
to reproduce a case where the overlays are missing from the
system itself, other Resources/caching changes may have
decreased the occurrence rate

Change-Id: Ib5e7d6ca79ac5b37d5691ce327e3b66cc4672335
parent e8c5311c
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -2121,7 +2121,11 @@ public final class ActivityThread extends ClientTransactionHandler {
            }

            LoadedApk packageInfo = ref != null ? ref.get() : null;
            if (ai != null && packageInfo != null && isLoadedApkUpToDate(packageInfo, ai)) {
            if (ai != null && packageInfo != null) {
                if (!isLoadedApkResourceDirsUpToDate(packageInfo, ai)) {
                    packageInfo.updateApplicationInfo(ai, null);
                }

                if (packageInfo.isSecurityViolation()
                        && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) {
                    throw new SecurityException(
@@ -2205,9 +2209,11 @@ public final class ActivityThread extends ClientTransactionHandler {

            LoadedApk packageInfo = ref != null ? ref.get() : null;

            boolean isUpToDate = packageInfo != null && isLoadedApkUpToDate(packageInfo, aInfo);
            if (packageInfo != null) {
                if (!isLoadedApkResourceDirsUpToDate(packageInfo, aInfo)) {
                    packageInfo.updateApplicationInfo(aInfo, null);
                }

            if (isUpToDate) {
                return packageInfo;
            }

@@ -2243,11 +2249,8 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
    }

    /**
     * Compares overlay/resource directories for a LoadedApk to determine if it's up to date
     * with the given ApplicationInfo.
     */
    private boolean isLoadedApkUpToDate(LoadedApk loadedApk, ApplicationInfo appInfo) {
    private static boolean isLoadedApkResourceDirsUpToDate(LoadedApk loadedApk,
            ApplicationInfo appInfo) {
        Resources packageResources = loadedApk.mResources;
        String[] overlayDirs = ArrayUtils.defeatNullable(loadedApk.getOverlayDirs());
        String[] resourceDirs = ArrayUtils.defeatNullable(appInfo.resourceDirs);