Merge "Call Compatibility.isChangeEnabled in calling app"

This commit is contained in:
Philip P. Moltmann
2020-03-12 21:48:20 +00:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.usage.UsageStatsManager;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
@@ -385,6 +386,13 @@ public class AppOpsManager {
*/
public static final int WATCH_FOREGROUND_CHANGES = 1 << 0;
/**
* Flag for {@link #startWatchingMode} that causes the callback to happen on the switch-op
* instead the op the callback was registered. (This simulates pre-R behavior).
*
* @hide
*/
public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1;
/**
* Flag to determine whether we should log noteOp/startOp calls to make sure they
@@ -6717,6 +6725,13 @@ public class AppOpsManager {
};
mModeWatchers.put(callback, cb);
}
// See CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE
if (!Compatibility.isChangeEnabled(
CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) {
flags |= CALL_BACK_ON_SWITCHED_OP;
}
try {
mService.startWatchingModeWithFlags(op, packageName, flags, cb);
} catch (RemoteException e) {

View File

@@ -19,7 +19,7 @@ package com.android.server.appop;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_CAMERA;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
import static android.app.AppOpsManager.CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE;
import static android.app.AppOpsManager.CALL_BACK_ON_SWITCHED_OP;
import static android.app.AppOpsManager.FILTER_BY_ATTRIBUTION_TAG;
import static android.app.AppOpsManager.FILTER_BY_OP_NAMES;
import static android.app.AppOpsManager.FILTER_BY_PACKAGE_NAME;
@@ -87,7 +87,6 @@ import android.app.AppOpsManagerInternal.CheckOpsDelegate;
import android.app.AsyncNotedAppOp;
import android.app.RuntimeAppOpAccessMessage;
import android.app.SyncNotedAppOp;
import android.compat.Compatibility;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -2689,10 +2688,8 @@ public class AppOpsService extends IAppOpsService.Stub {
synchronized (this) {
int switchOp = (op != AppOpsManager.OP_NONE) ? AppOpsManager.opToSwitch(op) : op;
// See CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE
int notifiedOps;
if (Compatibility.isChangeEnabled(
CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) {
if ((flags & CALL_BACK_ON_SWITCHED_OP) == 0) {
if (op == OP_NONE) {
notifiedOps = ALL_OPS;
} else {