From 0335f0916dd3473737a30904e2dfc86cbd4b7080 Mon Sep 17 00:00:00 2001 From: Shigeki Yokomichi Date: Tue, 15 Oct 2019 17:18:51 +0900 Subject: [PATCH] Fix crash loop due to broken packages.xml around updated-package Symptom: Device cannot boot up due to NPE during package scan. Root Cause: /data/system/packages.xml is broken with an unexpected element even though there's no corresponding element. When a system apk is installed, the system apk is registered as a element in the packages.xml. When updated with a newer apk in /data, the data apk is registered as a and the system apk is moved to . If a user triggers "Uninstall updates" but the device cannot complete uninstallation processing due to any critical problem like system freeze, the package.xml can be broken because the for the data apk is removed once but the for the system apk remains wrongly. Solution: In this case, this change ignores the inconsistent and installs the system apk as non-updated system app. Test: forcibly stop "Uninstall updates" processing with JDB as described in b/143251299 and check system restart behavior Bug: 143251299 Change-Id: I48b6957d19f5d60d08d2e5ba48fa1d7bf42fdcfe --- .../com/android/server/pm/PackageManagerService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 0460a80b1dc04..461743e9ba531 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -9334,6 +9334,16 @@ public class PackageManagerService extends IPackageManager.Stub pkgSetting = originalPkgSetting == null ? installedPkgSetting : originalPkgSetting; pkgAlreadyExists = pkgSetting != null; final String disabledPkgName = pkgAlreadyExists ? pkgSetting.name : pkg.packageName; + if (scanSystemPartition && !pkgAlreadyExists + && mSettings.getDisabledSystemPkgLPr(disabledPkgName) != null) { + // The updated-package data for /system apk remains inconsistently + // after the package data for /data apk is lost accidentally. + // To recover it, enable /system apk and install it as non-updated system app. + Slog.w(TAG, "Inconsistent package setting of updated system app for " + + disabledPkgName + ". To recover it, enable the system app" + + "and install it as non-updated system app."); + mSettings.removeDisabledSystemPackageLPw(disabledPkgName); + } disabledPkgSetting = mSettings.getDisabledSystemPkgLPr(disabledPkgName); isSystemPkgUpdated = disabledPkgSetting != null;