diff options
| author | 2018-11-01 16:22:50 -0700 | |
|---|---|---|
| committer | 2018-11-08 09:19:51 -0800 | |
| commit | e1b277a413fc791ba62c2df77ade9aeb6542e3b8 (patch) | |
| tree | 4bca558f30b3702f155f3a5119b960738ad3a230 | |
| parent | e0f00eac2a4344485cbbd802d1cb41df2df7d391 (diff) | |
Have a map of background -> foreground permssions
This needs to be available before package manager service is ready,
hence set it as soon as possible.
In the future we should also allow access to this mapping from other
processes than the system server.
Test: Built
Change-Id: If4240e5522e175ea9b341e4951ce261f17bbaadc
| -rw-r--r-- | core/java/android/permission/PermissionManager.java | 5 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/permission/PermissionManagerService.java | 40 |
2 files changed, 42 insertions, 3 deletions
diff --git a/core/java/android/permission/PermissionManager.java b/core/java/android/permission/PermissionManager.java index fc30eed10983..2ea706613ef8 100644 --- a/core/java/android/permission/PermissionManager.java +++ b/core/java/android/permission/PermissionManager.java @@ -67,15 +67,14 @@ public final class PermissionManager { * such an old app asks for a location permission (i.e. the * {@link SplitPermissionInfo#getSplitPermission()}), then the * {@link Manifest.permission#ACCESS_BACKGROUND_LOCATION} permission (inside - * {@{@link SplitPermissionInfo#getNewPermissions}) is added. + * {@link SplitPermissionInfo#getNewPermissions}) is added. * * <p>Note: Regular apps do not have to worry about this. The platform and permission controller * automatically add the new permissions where needed. * * @return All permissions that are split. */ - public @NonNull - List<SplitPermissionInfo> getSplitPermissions() { + public @NonNull List<SplitPermissionInfo> getSplitPermissions() { return SPLIT_PERMISSIONS; } diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java index f0230fcb91df..d52bd640977f 100644 --- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java +++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java @@ -152,6 +152,13 @@ public class PermissionManagerService { @GuardedBy("mLock") private boolean mSystemReady; + /** + * For each foreground/background permission the mapping: + * Background permission -> foreground permissions + */ + @GuardedBy("mLock") + private ArrayMap<String, List<String>> mBackgroundPermissions; + PermissionManagerService(Context context, @Nullable DefaultPermissionGrantedCallback defaultGrantCallback, @NonNull Object externalLock) { @@ -1770,6 +1777,28 @@ public class PermissionManagerService { // and make sure there are no dangling permissions. flags = updatePermissions(changingPkgName, changingPkg, flags); + synchronized (mLock) { + if (mBackgroundPermissions == null) { + // Cache background -> foreground permission mapping. + // Only system declares background permissions, hence mapping does never change. + mBackgroundPermissions = new ArrayMap<>(); + for (BasePermission bp : mSettings.getAllPermissionsLocked()) { + if (bp.perm.info != null && bp.perm.info.backgroundPermission != null) { + String fgPerm = bp.name; + String bgPerm = bp.perm.info.backgroundPermission; + + List<String> fgPerms = mBackgroundPermissions.get(bgPerm); + if (fgPerms == null) { + fgPerms = new ArrayList<>(); + mBackgroundPermissions.put(bgPerm, fgPerms); + } + + fgPerms.add(fgPerm); + } + } + } + } + Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "restorePermissionState"); // Now update the permissions for all packages, in particular // replace the granted permissions of the system packages. @@ -2087,6 +2116,17 @@ public class PermissionManagerService { mMetricsLogger.write(log); } + /** + * Get the mapping of background permissions to their foreground permissions. + * + * <p>Only initialized in the system server. + * + * @return the map <bg permission -> list<fg perm>> + */ + public @Nullable ArrayMap<String, List<String>> getBackgroundPermissions() { + return mBackgroundPermissions; + } + private class PermissionManagerInternalImpl extends PermissionManagerInternal { @Override public void systemReady() { |