summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2018-12-20 12:58:45 -0500
committer Fabian Kozynski <kozynski@google.com> 2018-12-20 12:58:45 -0500
commit0b4592cecb9374e5ff7802e1606707bde61abd1a (patch)
tree6019933f9a32390994b63551bc2bdeb6c0a42bef
parentb34e8528ca7e6aee84ba5eef9739155f658690c5 (diff)
Use raw op codes for the watch noted APIs.
Test: atest com.android.server.AppOpsServiceTests Test: atest com.android.systemui.appops.AppOpsControllerTest bug:121246606 Change-Id: Id99923c566fbf132914b15c676cb766d8793e875
-rw-r--r--core/java/android/app/AppOpsManager.java14
-rw-r--r--packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java31
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java16
4 files changed, 28 insertions, 41 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index a2784237247c..c3839f95a8a5 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -2496,7 +2496,7 @@ public class AppOpsManager {
* @param packageName The package performing the operation.
* @param result The result of the note.
*/
- void onOpNoted(String code, int uid, String packageName, int result);
+ void onOpNoted(int code, int uid, String packageName, int result);
}
/**
@@ -2953,7 +2953,7 @@ public class AppOpsManager {
* @hide
*/
@RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
- public void startWatchingNoted(@NonNull String[] ops, @NonNull OnOpNotedListener callback) {
+ public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) {
IAppOpsNotedCallback cb;
synchronized (mNotedWatchers) {
cb = mNotedWatchers.get(callback);
@@ -2963,17 +2963,13 @@ public class AppOpsManager {
cb = new IAppOpsNotedCallback.Stub() {
@Override
public void opNoted(int op, int uid, String packageName, int mode) {
- callback.onOpNoted(sOpToString[op], uid, packageName, mode);
+ callback.onOpNoted(op, uid, packageName, mode);
}
};
mNotedWatchers.put(callback, cb);
}
try {
- final int[] opCodes = new int[ops.length];
- for (int i = 0; i < opCodes.length; i++) {
- opCodes[i] = strOpToOp(ops[i]);
- }
- mService.startWatchingNoted(opCodes, cb);
+ mService.startWatchingNoted(ops, cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2983,7 +2979,7 @@ public class AppOpsManager {
* Stop watching for noted app ops. An app op may be immediate or long running.
* Unregistering a non-registered callback has no effect.
*
- * @see #startWatchingNoted(String[], OnOpNotedListener)
+ * @see #startWatchingNoted(int[], OnOpNotedListener)
* @see #noteOp(String, int, String)
*
* @hide
diff --git a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
index 52d1260b4221..af6ee1f4179a 100644
--- a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
@@ -57,21 +57,13 @@ public class AppOpsControllerImpl implements AppOpsController,
@GuardedBy("mNotedItems")
private final List<AppOpItem> mNotedItems = new ArrayList<>();
- protected static final int[] OPS;
- protected static final String[] OPS_STRING = new String[] {
- AppOpsManager.OPSTR_CAMERA,
- AppOpsManager.OPSTR_SYSTEM_ALERT_WINDOW,
- AppOpsManager.OPSTR_RECORD_AUDIO,
- AppOpsManager.OPSTR_COARSE_LOCATION,
- AppOpsManager.OPSTR_FINE_LOCATION};
-
- static {
- int numOps = OPS_STRING.length;
- OPS = new int[numOps];
- for (int i = 0; i < numOps; i++) {
- OPS[i] = AppOpsManager.strOpToOp(OPS_STRING[i]);
- }
- }
+ protected static final int[] OPS = new int[] {
+ AppOpsManager.OP_CAMERA,
+ AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
+ AppOpsManager.OP_RECORD_AUDIO,
+ AppOpsManager.OP_COARSE_LOCATION,
+ AppOpsManager.OP_FINE_LOCATION
+ };
public AppOpsControllerImpl(Context context, Looper bgLooper) {
mContext = context;
@@ -92,7 +84,7 @@ public class AppOpsControllerImpl implements AppOpsController,
protected void setListening(boolean listening) {
if (listening) {
mAppOps.startWatchingActive(OPS, this);
- mAppOps.startWatchingNoted(OPS_STRING, this);
+ mAppOps.startWatchingNoted(OPS, this);
} else {
mAppOps.stopWatchingActive(this);
mAppOps.stopWatchingNoted(this);
@@ -254,14 +246,13 @@ public class AppOpsControllerImpl implements AppOpsController,
}
@Override
- public void onOpNoted(String code, int uid, String packageName, int result) {
+ public void onOpNoted(int code, int uid, String packageName, int result) {
if (DEBUG) {
Log.w(TAG, "Op: " + code + " with result " + AppOpsManager.MODE_NAMES[result]);
}
if (result != AppOpsManager.MODE_ALLOWED) return;
- int op_code = AppOpsManager.strOpToOp(code);
- addNoted(op_code, uid, packageName);
- notifySuscribers(op_code, uid, packageName, true);
+ addNoted(code, uid, packageName);
+ notifySuscribers(code, uid, packageName, true);
}
private void notifySuscribers(int code, int uid, String packageName, boolean active) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java
index bb445483c966..2582946333c0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java
@@ -86,7 +86,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
mCallback);
mController.onOpActiveChanged(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
- mController.onOpNoted(AppOpsManager.OPSTR_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
AppOpsManager.MODE_ALLOWED);
verify(mCallback).onActiveStateChanged(AppOpsManager.OP_RECORD_AUDIO,
TEST_UID, TEST_PACKAGE_NAME, true);
@@ -136,7 +136,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
TEST_UID, TEST_PACKAGE_NAME, true);
mController.onOpActiveChanged(AppOpsManager.OP_CAMERA,
TEST_UID, TEST_PACKAGE_NAME, true);
- mController.onOpNoted(AppOpsManager.OPSTR_FINE_LOCATION,
+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION,
TEST_UID, TEST_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
assertEquals(3, mController.getActiveAppOps().size());
}
@@ -147,7 +147,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
TEST_UID, TEST_PACKAGE_NAME, true);
mController.onOpActiveChanged(AppOpsManager.OP_CAMERA,
TEST_UID_OTHER, TEST_PACKAGE_NAME, true);
- mController.onOpNoted(AppOpsManager.OPSTR_FINE_LOCATION,
+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION,
TEST_UID, TEST_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
assertEquals(2,
mController.getActiveAppOpsForUser(UserHandle.getUserId(TEST_UID)).size());
@@ -158,7 +158,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
@Test
public void opNotedScheduledForRemoval() {
mController.setBGHandler(mMockHandler);
- mController.onOpNoted(AppOpsManager.OPSTR_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
AppOpsManager.MODE_ALLOWED);
verify(mMockHandler).scheduleRemoval(any(AppOpItem.class), anyLong());
}
diff --git a/services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java b/services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java
index 52f434db3be3..edd89f9e61d1 100644
--- a/services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java
+++ b/services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java
@@ -52,8 +52,8 @@ public class AppOpsNotedWatcherTest {
// Try to start watching noted ops
final AppOpsManager appOpsManager = getContext().getSystemService(AppOpsManager.class);
try {
- appOpsManager.startWatchingNoted(new String[]{AppOpsManager.OPSTR_FINE_LOCATION,
- AppOpsManager.OPSTR_RECORD_AUDIO}, listener);
+ appOpsManager.startWatchingNoted(new int[]{AppOpsManager.OP_FINE_LOCATION,
+ AppOpsManager.OP_RECORD_AUDIO}, listener);
fail("Watching noted ops shoudl require " + Manifest.permission.WATCH_APPOPS);
} catch (SecurityException expected) {
/*ignored*/
@@ -67,23 +67,23 @@ public class AppOpsNotedWatcherTest {
// Start watching noted ops
final AppOpsManager appOpsManager = getContext().getSystemService(AppOpsManager.class);
- appOpsManager.startWatchingNoted(new String[]{AppOpsManager.OPSTR_FINE_LOCATION,
- AppOpsManager.OPSTR_CAMERA}, listener);
+ appOpsManager.startWatchingNoted(new int[]{AppOpsManager.OP_FINE_LOCATION,
+ AppOpsManager.OP_CAMERA}, listener);
// Note some ops
- appOpsManager.noteOp(AppOpsManager.OPSTR_FINE_LOCATION, Process.myUid(),
+ appOpsManager.noteOp(AppOpsManager.OP_FINE_LOCATION, Process.myUid(),
getContext().getPackageName());
- appOpsManager.noteOp(AppOpsManager.OPSTR_CAMERA, Process.myUid(),
+ appOpsManager.noteOp(AppOpsManager.OP_CAMERA, Process.myUid(),
getContext().getPackageName());
// Verify that we got called for the ops being noted
final InOrder inOrder = inOrder(listener);
inOrder.verify(listener, timeout(NOTIFICATION_TIMEOUT_MILLIS)
- .times(1)).onOpNoted(eq(AppOpsManager.OPSTR_FINE_LOCATION),
+ .times(1)).onOpNoted(eq(AppOpsManager.OP_FINE_LOCATION),
eq(Process.myUid()), eq(getContext().getPackageName()),
eq(AppOpsManager.MODE_ALLOWED));
inOrder.verify(listener, timeout(NOTIFICATION_TIMEOUT_MILLIS)
- .times(1)).onOpNoted(eq(AppOpsManager.OPSTR_CAMERA),
+ .times(1)).onOpNoted(eq(AppOpsManager.OP_CAMERA),
eq(Process.myUid()), eq(getContext().getPackageName()),
eq(AppOpsManager.MODE_ALLOWED));