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

Commit ef96992b authored by Jeongsik Mun's avatar Jeongsik Mun Committed by Todd Kennedy
Browse files

Fix an app data removal issue during OTA update

There is an edge case where an OTA updates a system app to
a higher version than a version of an upgrade on /data and
reset happens for unknown reason right after removing the apk of
the upgrade on /data. PackageManager cleans up orphaned packages ahead
of scanning when it happens. However, it gets 'duplicated appId'
error in enableSystemPackageLPw() and it ends up changing
the appId and removing app's data dir.

This fix removes the code to clean up orphaned packages, which is
a fix for b/32321269.

Test: manual
  1. Command to install an apk(version 1) as system app.
    $ adb remount; adb shell mkdir /system/app/Test \
      adb push Test_v1.apk /system/app/Test/Test.apk \
      adb reboot
  2. Command to update it with an apk(v2)
    $ adb install Test_v2.apk
  3. Command to simulate an OTA, rebooted after removing Test_v2.apk
    $ adb remount; adb push Test_v3.apk /system/app/Test/Test.apk \
      adb shell rm -rf [codepath_of_test_v2]; adb reboot
  4. Check the appId didn't change and app data wasn't removed
Bug: 162757159
Change-Id: I4544316e99247ae1de1228d5fe11416cfb601849
parent 99abec3d
Loading
Loading
Loading
Loading
+3 −14
Original line number Diff line number Diff line
@@ -6444,20 +6444,6 @@ public class PackageManagerService extends IPackageManager.Stub
            mPermissionManager.readLegacyPermissionsTEMP(mSettings.mPermissions);
            // Clean up orphaned packages for which the code path doesn't exist
            // and they are an update to a system app - caused by bug/32321269
            final WatchedArrayMap<String, PackageSetting> packageSettings =
                mSettings.getPackagesLocked();
            final int packageSettingCount = packageSettings.size();
            for (int i = packageSettingCount - 1; i >= 0; i--) {
                PackageSetting ps = packageSettings.valueAt(i);
                if (!isExternal(ps) && (ps.getPath() == null || !ps.getPath().exists())
                        && mSettings.getDisabledSystemPkgLPr(ps.name) != null) {
                    packageSettings.removeAt(i);
                    mSettings.enableSystemPackageLPw(ps.name);
                }
            }
            if (!mOnlyCore && mFirstBoot) {
                requestCopyPreoptedFiles(mInjector);
            }
@@ -6506,6 +6492,9 @@ public class PackageManagerService extends IPackageManager.Stub
            mIsPreNMR1Upgrade = mIsUpgrade && ver.sdkVersion < Build.VERSION_CODES.N_MR1;
            mIsPreQUpgrade = mIsUpgrade && ver.sdkVersion < Build.VERSION_CODES.Q;
            final WatchedArrayMap<String, PackageSetting> packageSettings =
                mSettings.getPackagesLocked();
            // Save the names of pre-existing packages prior to scanning, so we can determine
            // which system packages are completely new due to an upgrade.
            if (isDeviceUpgrading()) {