Merge "Apps can go from isolated to non-isolated storage" into qt-dev

am: 3891c698cb

Change-Id: I4e7c9e53b4bc8f948e0bc7de28487cb19a38f186
This commit is contained in:
Philip P. Moltmann
2019-05-22 18:58:04 -07:00
committed by android-build-merger
2 changed files with 47 additions and 6 deletions

View File

@@ -1347,6 +1347,7 @@ public class PermissionManagerService {
updatedUserIds); updatedUserIds);
updatedUserIds = setInitialGrantForNewImplicitPermissionsLocked(origPermissions, updatedUserIds = setInitialGrantForNewImplicitPermissionsLocked(origPermissions,
permissionsState, pkg, newImplicitPermissions, updatedUserIds); permissionsState, pkg, newImplicitPermissions, updatedUserIds);
updatedUserIds = checkIfLegacyStorageOpsNeedToBeUpdated(pkg, replace, updatedUserIds);
} }
// Persist the runtime permissions state for users with changes. If permissions // Persist the runtime permissions state for users with changes. If permissions
@@ -1472,6 +1473,28 @@ public class PermissionManagerService {
ps.updatePermissionFlags(mSettings.getPermission(newPerm), userId, flags, flags); ps.updatePermissionFlags(mSettings.getPermission(newPerm), userId, flags, flags);
} }
/**
* When the app has requested legacy storage we might need to update
* {@link android.app.AppOpsManager#OP_LEGACY_STORAGE}. Hence force an update in
* {@link com.android.server.policy.PermissionPolicyService#synchronizePackagePermissionsAndAppOpsForUser(Context, String, int)}
*
* @param pkg The package for which the permissions are updated
* @param replace If the app is being replaced
* @param updatedUserIds The ids of the users that already changed.
*
* @return The ids of the users that are changed
*/
private @NonNull int[] checkIfLegacyStorageOpsNeedToBeUpdated(
@NonNull PackageParser.Package pkg, boolean replace, @NonNull int[] updatedUserIds) {
if (replace && pkg.applicationInfo.hasRequestedLegacyExternalStorage() && (
pkg.requestedPermissions.contains(READ_EXTERNAL_STORAGE)
|| pkg.requestedPermissions.contains(WRITE_EXTERNAL_STORAGE))) {
return UserManagerService.getInstance().getUserIds();
}
return updatedUserIds;
}
/** /**
* Set the state of a implicit permission that is seen for the first time. * Set the state of a implicit permission that is seen for the first time.
* *

View File

@@ -229,6 +229,15 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncRestrictedOps * @see #syncRestrictedOps
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToAllowIfDefault = new ArrayList<>();
/**
* All ops that need to be flipped to allow.
*
* Currently, only used by the restricted permissions logic.
*
* @see #syncRestrictedOps
*/
private final @NonNull ArrayList<OpToUnrestrict> mOpsToAllow = new ArrayList<>(); private final @NonNull ArrayList<OpToUnrestrict> mOpsToAllow = new ArrayList<>();
/** /**
@@ -238,7 +247,7 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncRestrictedOps * @see #syncRestrictedOps
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToIgnore = new ArrayList<>(); private final @NonNull ArrayList<OpToUnrestrict> mOpsToIgnoreIfDefault = new ArrayList<>();
/** /**
* All foreground permissions * All foreground permissions
@@ -262,11 +271,16 @@ public final class PermissionPolicyService extends SystemService {
final int allowCount = mOpsToAllow.size(); final int allowCount = mOpsToAllow.size();
for (int i = 0; i < allowCount; i++) { for (int i = 0; i < allowCount; i++) {
final OpToUnrestrict op = mOpsToAllow.get(i); final OpToUnrestrict op = mOpsToAllow.get(i);
setUidModeAllowed(op.code, op.uid);
}
final int allowIfDefaultCount = mOpsToAllowIfDefault.size();
for (int i = 0; i < allowIfDefaultCount; i++) {
final OpToUnrestrict op = mOpsToAllowIfDefault.get(i);
setUidModeAllowedIfDefault(op.code, op.uid, op.packageName); setUidModeAllowedIfDefault(op.code, op.uid, op.packageName);
} }
final int ignoreCount = mOpsToIgnore.size(); final int ignoreIfDefaultCount = mOpsToIgnoreIfDefault.size();
for (int i = 0; i < ignoreCount; i++) { for (int i = 0; i < ignoreIfDefaultCount; i++) {
final OpToUnrestrict op = mOpsToIgnore.get(i); final OpToUnrestrict op = mOpsToIgnoreIfDefault.get(i);
setUidModeIgnoredIfDefault(op.code, op.uid, op.packageName); setUidModeIgnoredIfDefault(op.code, op.uid, op.packageName);
} }
final int defaultCount = mOpsToDefault.size(); final int defaultCount = mOpsToDefault.size();
@@ -341,7 +355,7 @@ public final class PermissionPolicyService extends SystemService {
if (applyRestriction) { if (applyRestriction) {
mOpsToDefault.add(new OpToRestrict(uid, opCode)); mOpsToDefault.add(new OpToRestrict(uid, opCode));
} else { } else {
mOpsToAllow.add(new OpToUnrestrict(uid, pkg.packageName, opCode)); mOpsToAllowIfDefault.add(new OpToUnrestrict(uid, pkg.packageName, opCode));
} }
} else if (permissionInfo.isSoftRestricted()) { } else if (permissionInfo.isSoftRestricted()) {
// Storage uses a special app op to decide the mount state and // Storage uses a special app op to decide the mount state and
@@ -356,7 +370,7 @@ public final class PermissionPolicyService extends SystemService {
mOpsToAllow.add(new OpToUnrestrict(uid, pkg.packageName, mOpsToAllow.add(new OpToUnrestrict(uid, pkg.packageName,
AppOpsManager.OP_LEGACY_STORAGE)); AppOpsManager.OP_LEGACY_STORAGE));
} else { } else {
mOpsToIgnore.add(new OpToUnrestrict(uid, pkg.packageName, mOpsToIgnoreIfDefault.add(new OpToUnrestrict(uid, pkg.packageName,
AppOpsManager.OP_LEGACY_STORAGE)); AppOpsManager.OP_LEGACY_STORAGE));
} }
} }
@@ -421,6 +435,10 @@ public final class PermissionPolicyService extends SystemService {
setUidModeIfDefault(opCode, uid, AppOpsManager.MODE_ALLOWED, packageName); setUidModeIfDefault(opCode, uid, AppOpsManager.MODE_ALLOWED, packageName);
} }
private void setUidModeAllowed(int opCode, int uid) {
mAppOpsManager.setUidMode(opCode, uid, AppOpsManager.MODE_ALLOWED);
}
private void setUidModeIgnoredIfDefault(int opCode, int uid, @NonNull String packageName) { private void setUidModeIgnoredIfDefault(int opCode, int uid, @NonNull String packageName) {
setUidModeIfDefault(opCode, uid, AppOpsManager.MODE_IGNORED, packageName); setUidModeIfDefault(opCode, uid, AppOpsManager.MODE_IGNORED, packageName);
} }