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

Commit 61fe40c6 authored by Winson's avatar Winson
Browse files

Force notify overlay paths on package replaced due to system update uninstall

Tracks system update downgrades through a new ACTION_PACKAGE_REMOVED
broadcast extra and forces OMS to re-call into PMS with the target's
overlay paths by updating the overlay settings state to
STATE_SYSTEM_UPDATE_UNINSTALL.

This allows overlays to be re-propagated to the newly enabled,
previously system PackageSetting once onPackageReplaced is invoked,
to bring its state up to the latest known by OMS.

This also fixes a bug with Watchable tracking in PackageUserStateImpl,
which was causing overlay path updates to not propagate to the snapshot.
User states are shared between copied PackageSettings, which is probably
worth fixing, but that means their parent Watchable references can be
out of date if they reference the pre-copy PackageSetting.

This attempts to fix that in 2 places, during commit and during copy,
until a better solution can be designed.

Bug: 197759786

Test: Install app update to a system app, then run
    adb shell pm uninstall-system-updates com.example.app,
    adb shell dumpsys package com.example.app | grep -A 5 "overlay paths:"
Test: atest OverlayManagerServiceImplTests

Change-Id: Ibccafcf7b3dc9b584f412a92a233048d2a8ae592
parent 9dc94dcd
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -6092,6 +6092,14 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";

    /**
     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
     * intents to indicate that this is a system update uninstall.
     * @hide
     */
    public static final String EXTRA_SYSTEM_UPDATE_UNINSTALL =
            "android.intent.extra.SYSTEM_UPDATE_UNINSTALL";

    /**
     * Used as an int extra field in {@link android.app.AlarmManager} pending intents
     * to tell the application being invoked how many pending alarms are being
+9 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public final class OverlayInfo implements CriticalOverlayInfo, Parcelable {
            STATE_ENABLED_IMMUTABLE,
            // @Deprecated STATE_TARGET_IS_BEING_REPLACED,
            STATE_OVERLAY_IS_BEING_REPLACED,
            STATE_SYSTEM_UPDATE_UNINSTALL,
    })
    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
@@ -127,6 +128,14 @@ public final class OverlayInfo implements CriticalOverlayInfo, Parcelable {
    @Deprecated
    public static final int STATE_ENABLED_IMMUTABLE = 6;

    /**
     * The target package needs to be refreshed as a result of a system update uninstall, which
     * must recalculate the state of overlays against the newly enabled system package, which may
     * differ in resources/policy from the /data variant that was uninstalled.
     * @hide
     */
    public static final int STATE_SYSTEM_UPDATE_UNINSTALL = 7;

    /**
     * Overlay category: theme.
     * <p>
+6 −4
Original line number Diff line number Diff line
@@ -379,6 +379,8 @@ public final class OverlayManagerService extends SystemService {
            final String packageName = data.getSchemeSpecificPart();

            final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
            final boolean systemUpdateUninstall =
                    intent.getBooleanExtra(Intent.EXTRA_SYSTEM_UPDATE_UNINSTALL, false);

            final int[] userIds;
            final int extraUid = intent.getIntExtra(Intent.EXTRA_UID, UserHandle.USER_NULL);
@@ -405,7 +407,7 @@ public final class OverlayManagerService extends SystemService {
                    break;
                case ACTION_PACKAGE_REMOVED:
                    if (replacing) {
                        onPackageReplacing(packageName, userIds);
                        onPackageReplacing(packageName, systemUpdateUninstall, userIds);
                    } else {
                        onPackageRemoved(packageName, userIds);
                    }
@@ -463,7 +465,7 @@ public final class OverlayManagerService extends SystemService {
        }

        private void onPackageReplacing(@NonNull final String packageName,
                @NonNull final int[] userIds) {
                boolean systemUpdateUninstall, @NonNull final int[] userIds) {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#onPackageReplacing " + packageName);
                for (int userId : userIds) {
@@ -472,8 +474,8 @@ public final class OverlayManagerService extends SystemService {
                                packageName, userId);
                        if (pkg != null && !mPackageManager.isInstantApp(packageName, userId)) {
                            try {
                                updateTargetPackagesLocked(
                                        mImpl.onPackageReplacing(packageName, userId));
                                updateTargetPackagesLocked(mImpl.onPackageReplacing(packageName,
                                        systemUpdateUninstall, userId));
                            } catch (OperationFailedException e) {
                                Slog.e(TAG, "onPackageReplacing internal error", e);
                            }
+13 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.content.om.OverlayInfo.STATE_ENABLED;
import static android.content.om.OverlayInfo.STATE_MISSING_TARGET;
import static android.content.om.OverlayInfo.STATE_NO_IDMAP;
import static android.content.om.OverlayInfo.STATE_OVERLAY_IS_BEING_REPLACED;
import static android.content.om.OverlayInfo.STATE_SYSTEM_UPDATE_UNINSTALL;
import static android.content.om.OverlayInfo.STATE_TARGET_IS_BEING_REPLACED;
import static android.os.UserHandle.USER_SYSTEM;

@@ -78,6 +79,7 @@ final class OverlayManagerServiceImpl {

    // Flags to use in conjunction with updateState.
    private static final int FLAG_OVERLAY_IS_BEING_REPLACED = 1 << 1;
    private static final int FLAG_SYSTEM_UPDATE_UNINSTALL = 1 << 2;

    private final PackageManagerHelper mPackageManager;
    private final IdmapManager mIdmapManager;
@@ -275,9 +277,13 @@ final class OverlayManagerServiceImpl {
    }

    @NonNull
    Set<UserPackage> onPackageReplacing(@NonNull final String pkgName, final int userId)
            throws OperationFailedException {
        return reconcileSettingsForPackage(pkgName, userId, FLAG_OVERLAY_IS_BEING_REPLACED);
    Set<UserPackage> onPackageReplacing(@NonNull final String pkgName,
            boolean systemUpdateUninstall, final int userId) throws OperationFailedException {
        int flags = FLAG_OVERLAY_IS_BEING_REPLACED;
        if (systemUpdateUninstall) {
            flags |= FLAG_SYSTEM_UPDATE_UNINSTALL;
        }
        return reconcileSettingsForPackage(pkgName, userId, flags);
    }

    @NonNull
@@ -840,6 +846,10 @@ final class OverlayManagerServiceImpl {
            return STATE_OVERLAY_IS_BEING_REPLACED;
        }

        if ((flags & FLAG_SYSTEM_UPDATE_UNINSTALL) != 0) {
            return STATE_SYSTEM_UPDATE_UNINSTALL;
        }

        if (targetPackage == null) {
            return STATE_MISSING_TARGET;
        }
+1 −0
Original line number Diff line number Diff line
@@ -7269,6 +7269,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }

            consumer.accept(mPackageStateMutator);
            mPackageStateMutator.onFinished();
            onChanged();
        }

Loading