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

Commit d2a63e18 authored by jsong.song's avatar jsong.song Committed by Song Chun Fan
Browse files

Clean component settings while updating an app

The component which was removed in the updated app are still in the
enabled/disabled component list. It needs to be checked if the component
is still existed while updating.

Bug: 310064823
Test: Manually tested with below steps
      1. Install an app
      2. Disable a component
      3. Update the app w/o the component
(cherry picked from https://partner-android-review.googlesource.com/q/commit:fda800fd575226b02c4bd4e8888fffa22b7a8265)
Change-Id: I7f27ebfde553fb4b1d54b815ab78c2b50f7d9763
parent ceed5a76
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -575,6 +575,12 @@ final class InstallPackageHelper {
                mApexManager.registerApkInApex(pkg);
            }

            if ((mPm.isDeviceUpgrading() && pkgSetting.isSystem()) || isReplace) {
                for (int userId : mPm.mUserManager.getUserIds()) {
                    pkgSetting.restoreComponentSettings(userId);
                }
            }

            // Don't add keysets for APEX as their package settings are not persisted and will
            // result in orphaned keysets.
            if ((scanFlags & SCAN_AS_APEX) == 0) {
+23 −0
Original line number Diff line number Diff line
@@ -1112,6 +1112,29 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return changed;
    }

    void restoreComponentSettings(int userId) {
        PackageUserStateImpl state = modifyUserStateComponents(userId, true, true);
        WatchedArraySet<String> enabledComponents = state.getEnabledComponentsNoCopy();
        WatchedArraySet<String> disabledComponents = state.getDisabledComponentsNoCopy();

        boolean changed = false;
        for (int i = enabledComponents.size() - 1; i >= 0; i--) {
            if (!AndroidPackageUtils.hasComponentClassName(pkg, enabledComponents.valueAt(i))) {
                enabledComponents.removeAt(i);
                changed = true;
            }
        }
        for (int i = disabledComponents.size() - 1; i >= 0; i--) {
            if (!AndroidPackageUtils.hasComponentClassName(pkg, disabledComponents.valueAt(i))) {
                disabledComponents.removeAt(i);
                changed = true;
            }
        }
        if (changed) {
            onChanged();
        }
    }

    int getCurrentEnabledStateLPr(String componentName, int userId) {
        PackageUserStateInternal state = readUserState(userId);
        if (state.getEnabledComponentsNoCopy() != null