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

Commit f9de5e97 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

Keep overlay info for the android app info up to date

Bug: 230890975
Test: manually update the wallpaper shade and check resolver
Change-Id: I851ba79bed0c70ac40a615cbaac9ed1c92a5e800
Merged-In: I851ba79bed0c70ac40a615cbaac9ed1c92a5e800
parent 0dfb582d
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
@@ -803,6 +803,13 @@ public class PackageManagerService implements PackageSender, TestUtilityService
    private AndroidPackage mPlatformPackage;
    ComponentName mCustomResolverComponentName;

    // Recorded overlay paths configuration for the Android app info.
    private String[] mPlatformPackageOverlayPaths = null;
    private String[] mPlatformPackageOverlayResourceDirs = null;
    // And the same paths for the replaced resolver activity package
    private String[] mReplacedResolverPackageOverlayPaths = null;
    private String[] mReplacedResolverPackageOverlayResourceDirs = null;

    private boolean mResolverReplaced = false;

    @NonNull
@@ -6562,11 +6569,61 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            });
        }

        if (userId == UserHandle.USER_SYSTEM) {
            // Keep the overlays in the system application info (and anything special cased as well)
            // up to date to make sure system ui is themed correctly.
            maybeUpdateSystemOverlays(targetPackageName, newOverlayPaths);
        }

        invalidatePackageInfoCache();

        return true;
    }

    private void maybeUpdateSystemOverlays(String targetPackageName, OverlayPaths newOverlayPaths) {
        if (!mResolverReplaced) {
            if (targetPackageName.equals("android")) {
                if (newOverlayPaths == null) {
                    mPlatformPackageOverlayPaths = null;
                    mPlatformPackageOverlayResourceDirs = null;
                } else {
                    mPlatformPackageOverlayPaths = newOverlayPaths.getOverlayPaths().toArray(
                            new String[0]);
                    mPlatformPackageOverlayResourceDirs = newOverlayPaths.getResourceDirs().toArray(
                            new String[0]);
                }
                applyUpdatedSystemOverlayPaths();
            }
        } else {
            if (targetPackageName.equals(mResolveActivity.applicationInfo.packageName)) {
                if (newOverlayPaths == null) {
                    mReplacedResolverPackageOverlayPaths = null;
                    mReplacedResolverPackageOverlayResourceDirs = null;
                } else {
                    mReplacedResolverPackageOverlayPaths =
                            newOverlayPaths.getOverlayPaths().toArray(new String[0]);
                    mReplacedResolverPackageOverlayResourceDirs =
                            newOverlayPaths.getResourceDirs().toArray(new String[0]);
                }
                applyUpdatedSystemOverlayPaths();
            }
        }
    }

    private void applyUpdatedSystemOverlayPaths() {
        if (mAndroidApplication == null) {
            Slog.i(TAG, "Skipped the AndroidApplication overlay paths update - no app yet");
        } else {
            mAndroidApplication.overlayPaths = mPlatformPackageOverlayPaths;
            mAndroidApplication.resourceDirs = mPlatformPackageOverlayResourceDirs;
        }
        if (mResolverReplaced) {
            mResolveActivity.applicationInfo.overlayPaths = mReplacedResolverPackageOverlayPaths;
            mResolveActivity.applicationInfo.resourceDirs =
                    mReplacedResolverPackageOverlayResourceDirs;
        }
    }

    private void enforceAdjustRuntimePermissionsPolicyOrUpgradeRuntimePermissions(
            @NonNull String message) {
        if (mContext.checkCallingOrSelfPermission(
@@ -7043,6 +7100,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }
            PackageManagerService.onChanged();
        }
        applyUpdatedSystemOverlayPaths();
    }

    ApplicationInfo getCoreAndroidApplication() {