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
This commit is contained in:
Philip P. Moltmann
2018-11-01 16:22:50 -07:00
parent e0f00eac2a
commit e1b277a413
2 changed files with 42 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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 &lt;bg permission -> list&lt;fg perm&gt;&gt;
*/
public @Nullable ArrayMap<String, List<String>> getBackgroundPermissions() {
return mBackgroundPermissions;
}
private class PermissionManagerInternalImpl extends PermissionManagerInternal {
@Override
public void systemReady() {