Merge "Prevent loop in PermissionPolicyService" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-06-21 18:34:53 +00:00
committed by Android (Google) Code Review

View File

@@ -365,7 +365,7 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToRestrict> mOpsToDefault = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToDefault = new ArrayList<>();
/** /**
* All ops that need to be flipped to allow if default. * All ops that need to be flipped to allow if default.
@@ -374,14 +374,14 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToAllowIfDefault = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToAllowIfDefault = new ArrayList<>();
/** /**
* All ops that need to be flipped to allow. * All ops that need to be flipped to allow.
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToAllow = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToAllow = new ArrayList<>();
/** /**
* All ops that need to be flipped to ignore if default. * All ops that need to be flipped to ignore if default.
@@ -390,14 +390,14 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToIgnoreIfDefault = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToIgnoreIfDefault = new ArrayList<>();
/** /**
* All ops that need to be flipped to ignore. * All ops that need to be flipped to ignore.
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToIgnore = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToIgnore = new ArrayList<>();
/** /**
* All ops that need to be flipped to foreground. * All ops that need to be flipped to foreground.
@@ -406,7 +406,7 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToForeground = new ArrayList<>(); private final @NonNull ArrayList<OpToChange> mOpsToForeground = new ArrayList<>();
/** /**
* All ops that need to be flipped to foreground if allow. * All ops that need to be flipped to foreground if allow.
@@ -415,7 +415,7 @@ public final class PermissionPolicyService extends SystemService {
* *
* @see #syncPackages * @see #syncPackages
*/ */
private final @NonNull ArrayList<OpToUnrestrict> mOpsToForegroundIfAllow = private final @NonNull ArrayList<OpToChange> mOpsToForegroundIfAllow =
new ArrayList<>(); new ArrayList<>();
PermissionToOpSynchroniser(@NonNull Context context) { PermissionToOpSynchroniser(@NonNull Context context) {
@@ -432,38 +432,38 @@ public final class PermissionPolicyService extends SystemService {
private void syncPackages() { private void syncPackages() {
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 OpToChange op = mOpsToAllow.get(i);
setUidModeAllowed(op.code, op.uid, op.packageName); setUidModeAllowed(op.code, op.uid, op.packageName);
} }
final int allowIfDefaultCount = mOpsToAllowIfDefault.size(); final int allowIfDefaultCount = mOpsToAllowIfDefault.size();
for (int i = 0; i < allowIfDefaultCount; i++) { for (int i = 0; i < allowIfDefaultCount; i++) {
final OpToUnrestrict op = mOpsToAllowIfDefault.get(i); final OpToChange op = mOpsToAllowIfDefault.get(i);
setUidModeAllowedIfDefault(op.code, op.uid, op.packageName); setUidModeAllowedIfDefault(op.code, op.uid, op.packageName);
} }
final int foregroundCount = mOpsToForegroundIfAllow.size(); final int foregroundCount = mOpsToForegroundIfAllow.size();
for (int i = 0; i < foregroundCount; i++) { for (int i = 0; i < foregroundCount; i++) {
final OpToUnrestrict op = mOpsToForegroundIfAllow.get(i); final OpToChange op = mOpsToForegroundIfAllow.get(i);
setUidModeForegroundIfAllow(op.code, op.uid, op.packageName); setUidModeForegroundIfAllow(op.code, op.uid, op.packageName);
} }
final int foregroundIfAllowCount = mOpsToForeground.size(); final int foregroundIfAllowCount = mOpsToForeground.size();
for (int i = 0; i < foregroundIfAllowCount; i++) { for (int i = 0; i < foregroundIfAllowCount; i++) {
final OpToUnrestrict op = mOpsToForeground.get(i); final OpToChange op = mOpsToForeground.get(i);
setUidModeForeground(op.code, op.uid, op.packageName); setUidModeForeground(op.code, op.uid, op.packageName);
} }
final int ignoreCount = mOpsToIgnore.size(); final int ignoreCount = mOpsToIgnore.size();
for (int i = 0; i < ignoreCount; i++) { for (int i = 0; i < ignoreCount; i++) {
final OpToUnrestrict op = mOpsToIgnore.get(i); final OpToChange op = mOpsToIgnore.get(i);
setUidModeIgnored(op.code, op.uid, op.packageName); setUidModeIgnored(op.code, op.uid, op.packageName);
} }
final int ignoreIfDefaultCount = mOpsToIgnoreIfDefault.size(); final int ignoreIfDefaultCount = mOpsToIgnoreIfDefault.size();
for (int i = 0; i < ignoreIfDefaultCount; i++) { for (int i = 0; i < ignoreIfDefaultCount; i++) {
final OpToUnrestrict op = mOpsToIgnoreIfDefault.get(i); final OpToChange 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();
for (int i = 0; i < defaultCount; i++) { for (int i = 0; i < defaultCount; i++) {
final OpToRestrict op = mOpsToDefault.get(i); final OpToChange op = mOpsToDefault.get(i);
setUidModeDefault(op.code, op.uid); setUidModeDefault(op.code, op.uid, op.packageName);
} }
} }
@@ -493,9 +493,9 @@ public final class PermissionPolicyService extends SystemService {
if (permissionInfo.isHardRestricted()) { if (permissionInfo.isHardRestricted()) {
if (opCode != OP_NONE) { if (opCode != OP_NONE) {
if (applyRestriction) { if (applyRestriction) {
mOpsToDefault.add(new OpToRestrict(uid, opCode)); mOpsToDefault.add(new OpToChange(uid, pkg.packageName, opCode));
} else { } else {
mOpsToAllowIfDefault.add(new OpToUnrestrict(uid, pkg.packageName, opCode)); mOpsToAllowIfDefault.add(new OpToChange(uid, pkg.packageName, opCode));
} }
} }
} else if (permissionInfo.isSoftRestricted()) { } else if (permissionInfo.isSoftRestricted()) {
@@ -505,9 +505,9 @@ public final class PermissionPolicyService extends SystemService {
if (opCode != OP_NONE) { if (opCode != OP_NONE) {
if (policy.canBeGranted()) { if (policy.canBeGranted()) {
mOpsToAllowIfDefault.add(new OpToUnrestrict(uid, pkg.packageName, opCode)); mOpsToAllowIfDefault.add(new OpToChange(uid, pkg.packageName, opCode));
} else { } else {
mOpsToDefault.add(new OpToRestrict(uid, opCode)); mOpsToDefault.add(new OpToChange(uid, pkg.packageName, opCode));
} }
} }
@@ -515,15 +515,14 @@ public final class PermissionPolicyService extends SystemService {
if (op != OP_NONE) { if (op != OP_NONE) {
switch (policy.getDesiredOpMode()) { switch (policy.getDesiredOpMode()) {
case MODE_DEFAULT: case MODE_DEFAULT:
mOpsToDefault.add(new OpToRestrict(uid, op)); mOpsToDefault.add(new OpToChange(uid, pkg.packageName, op));
break; break;
case MODE_ALLOWED: case MODE_ALLOWED:
if (policy.shouldSetAppOpIfNotDefault()) { if (policy.shouldSetAppOpIfNotDefault()) {
mOpsToAllow.add(new OpToUnrestrict(uid, pkg.packageName, op)); mOpsToAllow.add(new OpToChange(uid, pkg.packageName, op));
} else { } else {
mOpsToAllowIfDefault.add( mOpsToAllowIfDefault.add(
new OpToUnrestrict(uid, pkg.packageName, new OpToChange(uid, pkg.packageName, op));
op));
} }
break; break;
case MODE_FOREGROUND: case MODE_FOREGROUND:
@@ -532,10 +531,10 @@ public final class PermissionPolicyService extends SystemService {
break; break;
case MODE_IGNORED: case MODE_IGNORED:
if (policy.shouldSetAppOpIfNotDefault()) { if (policy.shouldSetAppOpIfNotDefault()) {
mOpsToIgnore.add(new OpToUnrestrict(uid, pkg.packageName, op)); mOpsToIgnore.add(new OpToChange(uid, pkg.packageName, op));
} else { } else {
mOpsToIgnoreIfDefault.add( mOpsToIgnoreIfDefault.add(
new OpToUnrestrict(uid, pkg.packageName, new OpToChange(uid, pkg.packageName,
op)); op));
} }
break; break;
@@ -597,7 +596,7 @@ public final class PermissionPolicyService extends SystemService {
if ((flags & FLAG_PERMISSION_REVIEW_REQUIRED) == 0 if ((flags & FLAG_PERMISSION_REVIEW_REQUIRED) == 0
&& isBgPermRestricted(pkgName, bgPermissionName, uid)) { && isBgPermRestricted(pkgName, bgPermissionName, uid)) {
mOpsToForegroundIfAllow.add(new OpToUnrestrict(uid, pkgName, opCode)); mOpsToForegroundIfAllow.add(new OpToChange(uid, pkgName, opCode));
} }
return; return;
@@ -611,12 +610,12 @@ public final class PermissionPolicyService extends SystemService {
pkgName) == PackageManager.PERMISSION_GRANTED; pkgName) == PackageManager.PERMISSION_GRANTED;
if (!isBgHardRestricted && isBgPermGranted) { if (!isBgHardRestricted && isBgPermGranted) {
mOpsToAllow.add(new OpToUnrestrict(uid, pkgName, opCode)); mOpsToAllow.add(new OpToChange(uid, pkgName, opCode));
} else { } else {
mOpsToForeground.add(new OpToUnrestrict(uid, pkgName, opCode)); mOpsToForeground.add(new OpToChange(uid, pkgName, opCode));
} }
} else { } else {
mOpsToIgnore.add(new OpToUnrestrict(uid, pkgName, opCode)); mOpsToIgnore.add(new OpToChange(uid, pkgName, opCode));
} }
} }
@@ -703,26 +702,16 @@ public final class PermissionPolicyService extends SystemService {
} }
} }
private void setUidModeDefault(int opCode, int uid) { private void setUidModeDefault(int opCode, int uid, String packageName) {
mAppOpsManager.setUidMode(opCode, uid, MODE_DEFAULT); setUidMode(opCode, uid, MODE_DEFAULT, packageName);
} }
private class OpToRestrict { private class OpToChange {
final int uid;
final int code;
OpToRestrict(int uid, int code) {
this.uid = uid;
this.code = code;
}
}
private class OpToUnrestrict {
final int uid; final int uid;
final @NonNull String packageName; final @NonNull String packageName;
final int code; final int code;
OpToUnrestrict(int uid, @NonNull String packageName, int code) { OpToChange(int uid, @NonNull String packageName, int code) {
this.uid = uid; this.uid = uid;
this.packageName = packageName; this.packageName = packageName;
this.code = code; this.code = code;