From e2437036a653261aadd2b28f524386340f96b66d Mon Sep 17 00:00:00 2001 From: liulvping Date: Mon, 6 Nov 2017 17:36:40 +0800 Subject: fix system app's abi error after uninstall updated version. When uninstall an updated system app, we always did as following steps. First we delete data structure by calling deleteInstalledPackageLIF(), then enable it from disabled system packages and re-adding to PackageSettings map by calling addPackageLPw(). At last re-installing apps in system partition with scanPackageTracedLI(). But if an package with sharedUserId readded failed with exception of 'Adding duplicate shared id: xxx', then we cann't reuse it's derived CPU Abis from settings, others we could get CPU Abis uninitialized errors. Test: Manual; Update an system app with sharedUserId Test: Manual; Uninstall and ensure it run ok Change-Id: Icfda17c5004d291c664ed80d578aca4b7cf4a975 Signed-off-by: liulvping --- .../core/java/com/android/server/pm/PackageManagerService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 2b3bfc82f982..3c7b033cd818 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -10160,6 +10160,7 @@ public class PackageManagerService extends IPackageManager.Stub // them in the case where we're not upgrading or booting for the first time. String primaryCpuAbiFromSettings = null; String secondaryCpuAbiFromSettings = null; + boolean needToDeriveAbi = (scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) != 0; // writer synchronized (mPackages) { @@ -10237,11 +10238,14 @@ public class PackageManagerService extends IPackageManager.Stub } } - if ((scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) == 0) { + if (!needToDeriveAbi) { PackageSetting foundPs = mSettings.getPackageLPr(pkg.packageName); if (foundPs != null) { primaryCpuAbiFromSettings = foundPs.primaryCpuAbiString; secondaryCpuAbiFromSettings = foundPs.secondaryCpuAbiString; + } else { + // when re-adding a system package failed after uninstalling updates. + needToDeriveAbi = true; } } @@ -10446,7 +10450,7 @@ public class PackageManagerService extends IPackageManager.Stub final String cpuAbiOverride = deriveAbiOverride(pkg.cpuAbiOverride, pkgSetting); if ((scanFlags & SCAN_NEW_INSTALL) == 0) { - if ((scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) != 0) { + if (needToDeriveAbi) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "derivePackageAbi"); final boolean extractNativeLibs = !pkg.isLibrary(); derivePackageAbi(pkg, scanFile, cpuAbiOverride, extractNativeLibs, -- cgit v1.2.3-59-g8ed1b