summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2016-10-25 20:47:15 -0700
committergitbuildkicker <android-build@google.com>2016-10-26 18:33:01 -0700
commit2c30838b8b64bce630e0683bc95c3a573d87dbf1 (patch)
tree7c892ed203857ae0fdcae2da8b585b2bddf8065e
parentbf9464f93296ccc133a0269deeeaaffc1631b753 (diff)
downloadbase-2c30838b8b64bce630e0683bc95c3a573d87dbf1.tar.gz
[DO NOT MERGE] Don't accidentally delete renamed packages
Apps on the system image can change their package by declaring their old one in the manifest. If a package is renamed it is internally referred by its old name. The reconciliation code was using the new package name for renamed packages and was concluding the apk is orphaned thus deleting it. This puts the package in a bad state where the app is gone and the version on the system partition is disabled. Also Play was showing an update for a renamed system app as an install while it is an update because of the same reason, it was using the new package name while the app is internally referred by the old one. The fix for both above is to internally normalize the package name by using the old one if the package was renamed or the package name as is. Test: With the fix put the old calculator on the system image and booted, then put the renamed calculator and booted, updated calculator from play and rebooted - calculator keeps working. Also did the above steps without the patch to put calculator in a bad state and flashed the system with the patch which fixed the broken calculator app. bug:32321269 Change-Id: I98bfc05c399edfc9854ebcce44182fefa55ceeff (cherry picked from commit e2c85890ac3941525288e08962b33d30618de801)
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c360c901d485..5fd9c58964d0 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2161,6 +2161,18 @@ public class PackageManagerService extends IPackageManager.Stub {
mFirstBoot = !mSettings.readLPw(sUserManager.getUsers(false));
+ // 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 int packageSettingCount = mSettings.mPackages.size();
+ for (int i = packageSettingCount - 1; i >= 0; i--) {
+ PackageSetting ps = mSettings.mPackages.valueAt(i);
+ if (!isExternal(ps) && (ps.codePath == null || !ps.codePath.exists())
+ && mSettings.getDisabledSystemPkgLPr(ps.name) != null) {
+ mSettings.mPackages.removeAt(i);
+ mSettings.enableSystemPackageLPw(ps.name);
+ }
+ }
+
if (mFirstBoot) {
requestCopyPreoptedFiles();
}
@@ -3115,8 +3127,12 @@ public class PackageManagerService extends IPackageManager.Stub {
flags = updateFlagsForPackage(flags, userId, packageName);
enforceCrossUserPermission(Binder.getCallingUid(), userId,
false /* requireFullPermission */, false /* checkShell */, "get package info");
+
// reader
synchronized (mPackages) {
+ // Normalize package name to hanlde renamed packages
+ packageName = normalizePackageNameLPr(packageName);
+
final boolean matchFactoryOnly = (flags & MATCH_FACTORY_ONLY) != 0;
PackageParser.Package p = null;
if (matchFactoryOnly) {
@@ -3317,8 +3333,12 @@ public class PackageManagerService extends IPackageManager.Stub {
flags = updateFlagsForApplication(flags, userId, packageName);
enforceCrossUserPermission(Binder.getCallingUid(), userId,
false /* requireFullPermission */, false /* checkShell */, "get application info");
+
// writer
synchronized (mPackages) {
+ // Normalize package name to hanlde renamed packages
+ packageName = normalizePackageNameLPr(packageName);
+
PackageParser.Package p = mPackages.get(packageName);
if (DEBUG_PACKAGE_INFO) Log.v(
TAG, "getApplicationInfo " + packageName
@@ -3340,6 +3360,11 @@ public class PackageManagerService extends IPackageManager.Stub {
return null;
}
+ private String normalizePackageNameLPr(String packageName) {
+ String normalizedPackageName = mSettings.mRenamedPackages.get(packageName);
+ return normalizedPackageName != null ? normalizedPackageName : packageName;
+ }
+
@Override
public void freeStorageAndNotify(final String volumeUuid, final long freeStorageSize,
final IPackageDataObserver observer) {
@@ -19691,6 +19716,9 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
private void assertPackageKnown(String volumeUuid, String packageName)
throws PackageManagerException {
synchronized (mPackages) {
+ // Normalize package name to handle renamed packages
+ packageName = normalizePackageNameLPr(packageName);
+
final PackageSetting ps = mSettings.mPackages.get(packageName);
if (ps == null) {
throw new PackageManagerException("Package " + packageName + " is unknown");
@@ -19705,6 +19733,9 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
private void assertPackageKnownAndInstalled(String volumeUuid, String packageName, int userId)
throws PackageManagerException {
synchronized (mPackages) {
+ // Normalize package name to handle renamed packages
+ packageName = normalizePackageNameLPr(packageName);
+
final PackageSetting ps = mSettings.mPackages.get(packageName);
if (ps == null) {
throw new PackageManagerException("Package " + packageName + " is unknown");