Merge "Add shouldForceCollectOp to appOpInfo"

This commit is contained in:
TreeHugger Robot
2022-09-15 05:22:31 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 11 deletions

View File

@@ -26,6 +26,7 @@ import java.util.Objects;
* Information about a particular app op.
*/
class AppOpInfo {
/**
* A unique constant identifying this app op.
*/
@@ -91,6 +92,11 @@ class AppOpInfo {
*/
public final boolean restrictRead;
/**
* Whether to collect noteOp instances, and send them to callbacks.
*/
public final boolean forceCollectNotes;
AppOpInfo(int code,
int switchCode,
@NonNull String name,
@@ -100,7 +106,8 @@ class AppOpInfo {
AppOpsManager.RestrictionBypass allowSystemRestrictionBypass,
int defaultMode,
boolean disableReset,
boolean restrictRead) {
boolean restrictRead,
boolean forceCollectNotes) {
if (code < OP_NONE) throw new IllegalArgumentException();
if (switchCode < OP_NONE) throw new IllegalArgumentException();
Objects.requireNonNull(name);
@@ -115,6 +122,7 @@ class AppOpInfo {
this.defaultMode = defaultMode;
this.disableReset = disableReset;
this.restrictRead = restrictRead;
this.forceCollectNotes = forceCollectNotes;
}
static class Builder {
@@ -128,6 +136,7 @@ class AppOpInfo {
private int mDefaultMode = AppOpsManager.MODE_DEFAULT;
private boolean mDisableReset = false;
private boolean mRestrictRead = false;
private boolean mForceCollectNotes = false;
Builder(int code, @NonNull String name, @NonNull String simpleName) {
if (code < OP_NONE) throw new IllegalArgumentException();
@@ -190,9 +199,15 @@ class AppOpInfo {
return this;
}
public Builder setForceCollectNotes(boolean value) {
this.mForceCollectNotes = value;
return this;
}
public AppOpInfo build() {
return new AppOpInfo(mCode, mSwitchCode, mName, mSimpleName, mPermission, mRestriction,
mAllowSystemRestrictionBypass, mDefaultMode, mDisableReset, mRestrictRead);
mAllowSystemRestrictionBypass, mDefaultMode, mDisableReset, mRestrictRead,
mForceCollectNotes);
}
}
}

View File

@@ -1831,6 +1831,9 @@ public class AppOpsManager {
})
private @interface ShouldCollectNoteOp {}
/** Whether noting for an appop should be collected */
private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];
private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
// RUNTIME PERMISSIONS
// Contacts
@@ -2281,9 +2284,18 @@ public class AppOpsManager {
"ACCESS_RESTRICTED_SETTINGS").setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setDisableReset(true).setRestrictRead(true).build(),
new AppOpInfo.Builder(OP_RECEIVE_AMBIENT_TRIGGER_AUDIO, OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO,
"RECEIVE_SOUNDTRIGGER_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED).build()
"RECEIVE_SOUNDTRIGGER_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setForceCollectNotes(true).build()
};
/**
* @hide
*/
public static boolean shouldForceCollectNoteForOp(int op) {
Preconditions.checkArgumentInRange(op, 0, _NUM_OP - 1, "opCode");
return sAppOpInfos[op].forceCollectNotes;
}
/**
* Mapping from an app op name to the app op code.
*/
@@ -2313,9 +2325,6 @@ public class AppOpsManager {
private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction =
new ThreadLocal<>();
/** Whether noting for an appop should be collected */
private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];
static {
if (sAppOpInfos.length != _NUM_OP) {
throw new IllegalStateException("mAppOpInfos length " + sAppOpInfos.length

View File

@@ -267,10 +267,6 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch
OP_CAMERA,
};
private static final int[] WATCHABLE_NON_PERMISSION_OPS = {
OP_RECEIVE_AMBIENT_TRIGGER_AUDIO,
};
private static final int MAX_UNFORWARDED_OPS = 10;
private static final int MAX_UNUSED_POOLED_OBJECTS = 3;
private static final int RARELY_USED_PACKAGES_INITIALIZATION_DELAY_MILLIS = 300000;
@@ -4252,7 +4248,7 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch
public boolean shouldCollectNotes(int opCode) {
Preconditions.checkArgumentInRange(opCode, 0, _NUM_OP - 1, "opCode");
if (ArrayUtils.contains(WATCHABLE_NON_PERMISSION_OPS, opCode)) {
if (AppOpsManager.shouldForceCollectNoteForOp(opCode)) {
return true;
}