Merge "Grab lock when accessing mutable state" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6642c963d9
@@ -875,7 +875,7 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return AppOpsManager.MODE_IGNORED;
|
return AppOpsManager.MODE_IGNORED;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (isOpRestricted(uid, code, resolvedPackageName)) {
|
if (isOpRestrictedLocked(uid, code, resolvedPackageName)) {
|
||||||
return AppOpsManager.MODE_IGNORED;
|
return AppOpsManager.MODE_IGNORED;
|
||||||
}
|
}
|
||||||
code = AppOpsManager.opToSwitch(code);
|
code = AppOpsManager.opToSwitch(code);
|
||||||
@@ -1024,7 +1024,7 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return AppOpsManager.MODE_ERRORED;
|
return AppOpsManager.MODE_ERRORED;
|
||||||
}
|
}
|
||||||
Op op = getOpLocked(ops, code, true);
|
Op op = getOpLocked(ops, code, true);
|
||||||
if (isOpRestricted(uid, code, packageName)) {
|
if (isOpRestrictedLocked(uid, code, packageName)) {
|
||||||
return AppOpsManager.MODE_IGNORED;
|
return AppOpsManager.MODE_IGNORED;
|
||||||
}
|
}
|
||||||
if (op.duration == -1) {
|
if (op.duration == -1) {
|
||||||
@@ -1082,7 +1082,7 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return AppOpsManager.MODE_ERRORED;
|
return AppOpsManager.MODE_ERRORED;
|
||||||
}
|
}
|
||||||
Op op = getOpLocked(ops, code, true);
|
Op op = getOpLocked(ops, code, true);
|
||||||
if (isOpRestricted(uid, code, resolvedPackageName)) {
|
if (isOpRestrictedLocked(uid, code, resolvedPackageName)) {
|
||||||
return AppOpsManager.MODE_IGNORED;
|
return AppOpsManager.MODE_IGNORED;
|
||||||
}
|
}
|
||||||
final int switchCode = AppOpsManager.opToSwitch(code);
|
final int switchCode = AppOpsManager.opToSwitch(code);
|
||||||
@@ -1308,7 +1308,7 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOpRestricted(int uid, int code, String packageName) {
|
private boolean isOpRestrictedLocked(int uid, int code, String packageName) {
|
||||||
int userHandle = UserHandle.getUserId(uid);
|
int userHandle = UserHandle.getUserId(uid);
|
||||||
final int restrictionSetCount = mOpUserRestrictions.size();
|
final int restrictionSetCount = mOpUserRestrictions.size();
|
||||||
|
|
||||||
@@ -2210,25 +2210,33 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
|
|
||||||
private void setUserRestrictionNoCheck(int code, boolean restricted, IBinder token,
|
private void setUserRestrictionNoCheck(int code, boolean restricted, IBinder token,
|
||||||
int userHandle, String[] exceptionPackages) {
|
int userHandle, String[] exceptionPackages) {
|
||||||
ClientRestrictionState restrictionState = mOpUserRestrictions.get(token);
|
boolean notifyChange = false;
|
||||||
|
|
||||||
if (restrictionState == null) {
|
synchronized (AppOpsService.this) {
|
||||||
try {
|
ClientRestrictionState restrictionState = mOpUserRestrictions.get(token);
|
||||||
restrictionState = new ClientRestrictionState(token);
|
|
||||||
} catch (RemoteException e) {
|
if (restrictionState == null) {
|
||||||
return;
|
try {
|
||||||
|
restrictionState = new ClientRestrictionState(token);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mOpUserRestrictions.put(token, restrictionState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restrictionState.setRestriction(code, restricted, exceptionPackages, userHandle)) {
|
||||||
|
notifyChange = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restrictionState.isDefault()) {
|
||||||
|
mOpUserRestrictions.remove(token);
|
||||||
|
restrictionState.destroy();
|
||||||
}
|
}
|
||||||
mOpUserRestrictions.put(token, restrictionState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restrictionState.setRestriction(code, restricted, exceptionPackages, userHandle)) {
|
if (notifyChange) {
|
||||||
notifyWatchersOfChange(code);
|
notifyWatchersOfChange(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restrictionState.isDefault()) {
|
|
||||||
mOpUserRestrictions.remove(token);
|
|
||||||
restrictionState.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyWatchersOfChange(int code) {
|
private void notifyWatchersOfChange(int code) {
|
||||||
@@ -2263,10 +2271,12 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void removeUser(int userHandle) throws RemoteException {
|
public void removeUser(int userHandle) throws RemoteException {
|
||||||
checkSystemUid("removeUser");
|
checkSystemUid("removeUser");
|
||||||
final int tokenCount = mOpUserRestrictions.size();
|
synchronized (AppOpsService.this) {
|
||||||
for (int i = tokenCount - 1; i >= 0; i--) {
|
final int tokenCount = mOpUserRestrictions.size();
|
||||||
ClientRestrictionState opRestrictions = mOpUserRestrictions.valueAt(i);
|
for (int i = tokenCount - 1; i >= 0; i--) {
|
||||||
opRestrictions.removeUser(userHandle);
|
ClientRestrictionState opRestrictions = mOpUserRestrictions.valueAt(i);
|
||||||
|
opRestrictions.removeUser(userHandle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user