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

Commit 8987e830 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Only update overlays for target

When a target package would update, the OMS would update the stat of
overlays that target android as if the android overlays targeted the
target package. This would cause the overlay state to change to
STATE_MISSING_TARGET for android overlays.

This change will only update state for overlays that target the updated
package.

Bug: 137038000
Bug: 136549878
Test: manual debugging
Change-Id: I0430426d8e8588a0fb97096a1f2570a7930069b3
Merged-In: I0d545253179b3545307b88b3151d11fd9e6cbd5b
parent 486503c7
Loading
Loading
Loading
Loading
+24 −20
Original line number Diff line number Diff line
@@ -296,22 +296,12 @@ final class OverlayManagerServiceImpl {
     */
    private void updateAndRefreshOverlaysForTarget(@NonNull final String targetPackageName,
            final int userId, final int flags) {
        final List<OverlayInfo> ois = new ArrayList<>();

        // Framework overlays added first because order matters when resolving a resource
        if (!"android".equals(targetPackageName)) {
            ois.addAll(mSettings.getOverlaysForTarget("android", userId));
        }

        // Then add the targeted, non-framework overlays which have higher priority
        ois.addAll(mSettings.getOverlaysForTarget(targetPackageName, userId));

        final List<String> enabledBaseCodePaths = new ArrayList<>(ois.size());
        final List<OverlayInfo> targetOverlays = mSettings.getOverlaysForTarget(targetPackageName,
                userId);

        // Update the state for any overlay that targets this package.
        boolean modified = false;
        final int n = ois.size();
        for (int i = 0; i < n; i++) {
            final OverlayInfo oi = ois.get(i);
        for (final OverlayInfo oi : targetOverlays) {
            final PackageInfo overlayPackage = mPackageManager.getPackageInfo(oi.packageName,
                    userId);
            if (overlayPackage == null) {
@@ -324,25 +314,39 @@ final class OverlayManagerServiceImpl {
                    Slog.e(TAG, "failed to update settings", e);
                    modified |= mSettings.remove(oi.packageName, userId);
                }
            }
        }

                if (oi.isEnabled() && overlayPackage.applicationInfo != null) {
                    enabledBaseCodePaths.add(overlayPackage.applicationInfo.getBaseCodePath());
        if (!modified) {
            // Update the overlay paths of the target within package manager if necessary.
            final List<String> enabledOverlayPaths = new ArrayList<>(targetOverlays.size());

            // Framework overlays are first in the overlay paths of a package within PackageManager.
            for (final OverlayInfo oi : mSettings.getOverlaysForTarget("android", userId)) {
                if (oi.isEnabled()) {
                    enabledOverlayPaths.add(oi.baseCodePath);
                }
            }

            for (final OverlayInfo oi : targetOverlays) {
                if (oi.isEnabled()) {
                    enabledOverlayPaths.add(oi.baseCodePath);
                }
            }

        if (!modified) {
            // TODO(): Use getEnabledOverlayPaths(userId, targetPackageName) instead of
            // resourceDirs if in the future resourceDirs contains APKs other than overlays
            PackageInfo packageInfo = mPackageManager.getPackageInfo(targetPackageName, userId);
            ApplicationInfo appInfo = packageInfo == null ? null : packageInfo.applicationInfo;
            String[] resourceDirs = appInfo == null ? null : appInfo.resourceDirs;

            // If the lists aren't the same length, the enabled overlays have changed
            if (ArrayUtils.size(resourceDirs) != enabledBaseCodePaths.size()) {
            if (ArrayUtils.size(resourceDirs) != enabledOverlayPaths.size()) {
                modified = true;
            } else if (resourceDirs != null) {
                // If any element isn't equal, an overlay or the order of overlays has changed
                for (int index = 0; index < resourceDirs.length; index++) {
                    if (!resourceDirs[index].equals(enabledBaseCodePaths.get(index))) {
                    if (!resourceDirs[index].equals(enabledOverlayPaths.get(index))) {
                        modified = true;
                        break;
                    }