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
This commit is contained in:
Jeongsik Mun
2020-08-13 09:43:22 +09:00
committed by Todd Kennedy
parent 99abec3d81
commit ef96992ba0

View File

@@ -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()) {