diff options
author | Jeff Sharkey <jsharkey@android.com> | 2015-10-29 19:00:44 -0700 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2015-11-02 13:21:06 -0800 |
commit | 9c648bdc359af7600675f85367e22f3d47998694 (patch) | |
tree | f286623279eca4e69d85c2677476541ee8549650 /services | |
parent | 52e3639cb4bf84d637bf3fae88a4197e71829d51 (diff) | |
download | frameworks_base-9c648bdc359af7600675f85367e22f3d47998694.zip frameworks_base-9c648bdc359af7600675f85367e22f3d47998694.tar.gz frameworks_base-9c648bdc359af7600675f85367e22f3d47998694.tar.bz2 |
Handle "uninstalled" apps when pruning app-ops.
During system boot, we prune app-ops belonging to apps that have
been uninstalled. However, apps installed on adopted storage devices
haven't been scanned at this point, so they appear to be uninstalled.
To avoid pruning app-ops for these apps, we need a getPackageUid()
variant that also considers "uninstalled" apps for which we still
have PackageSetting values.
Bug: 25206071
Change-Id: I1820f674d45c5ddc1c5f10ed7d859e7025005e28
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/AppOpsService.java | 9 | ||||
-rw-r--r-- | services/core/java/com/android/server/pm/PackageManagerService.java | 39 |
2 files changed, 31 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/AppOpsService.java b/services/core/java/com/android/server/AppOpsService.java index c373fb8..96c1e2a 100644 --- a/services/core/java/com/android/server/AppOpsService.java +++ b/services/core/java/com/android/server/AppOpsService.java @@ -39,7 +39,6 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; import android.media.AudioAttributes; import android.os.AsyncTask; import android.os.Binder; @@ -263,12 +262,12 @@ public class AppOpsService extends IAppOpsService.Stub { Iterator<Ops> it = pkgs.values().iterator(); while (it.hasNext()) { Ops ops = it.next(); - int curUid; + int curUid = -1; try { - curUid = mContext.getPackageManager().getPackageUid(ops.packageName, + curUid = AppGlobals.getPackageManager().getPackageUidEtc(ops.packageName, + PackageManager.GET_UNINSTALLED_PACKAGES, UserHandle.getUserId(ops.uidState.uid)); - } catch (NameNotFoundException e) { - curUid = -1; + } catch (RemoteException ignored) { } if (curUid != ops.uidState.uid) { Slog.i(TAG, "Pruning old package " + ops.packageName diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 5977a1b..cf15334 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -2733,26 +2733,38 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public int getPackageUid(String packageName, int userId) { + return getPackageUidEtc(packageName, 0, userId); + } + + @Override + public int getPackageUidEtc(String packageName, int flags, int userId) { if (!sUserManager.exists(userId)) return -1; enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get package uid"); // reader synchronized (mPackages) { - PackageParser.Package p = mPackages.get(packageName); - if(p != null) { + final PackageParser.Package p = mPackages.get(packageName); + if (p != null) { return UserHandle.getUid(userId, p.applicationInfo.uid); } - PackageSetting ps = mSettings.mPackages.get(packageName); - if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) { - return -1; + if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { + final PackageSetting ps = mSettings.mPackages.get(packageName); + if (ps != null) { + return UserHandle.getUid(userId, ps.appId); + } } - p = ps.pkg; - return p != null ? UserHandle.getUid(userId, p.applicationInfo.uid) : -1; } + + return -1; + } + + @Override + public int[] getPackageGids(String packageName, int userId) { + return getPackageGidsEtc(packageName, 0, userId); } @Override - public int[] getPackageGids(String packageName, int userId) throws RemoteException { + public int[] getPackageGidsEtc(String packageName, int flags, int userId) { if (!sUserManager.exists(userId)) { return null; } @@ -2762,14 +2774,17 @@ public class PackageManagerService extends IPackageManager.Stub { // reader synchronized (mPackages) { - PackageParser.Package p = mPackages.get(packageName); - if (DEBUG_PACKAGE_INFO) { - Log.v(TAG, "getPackageGids" + packageName + ": " + p); - } + final PackageParser.Package p = mPackages.get(packageName); if (p != null) { PackageSetting ps = (PackageSetting) p.mExtras; return ps.getPermissionsState().computeGids(userId); } + if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { + final PackageSetting ps = mSettings.mPackages.get(packageName); + if (ps != null) { + return ps.getPermissionsState().computeGids(userId); + } + } } return null; |