Loading core/java/android/app/AppOpsManager.java +5 −9 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading @@ -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); Loading @@ -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(); } Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java +11 −20 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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) { Loading packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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()); } Loading @@ -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()); Loading @@ -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()); } Loading services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -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*/ Loading @@ -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)); Loading Loading
core/java/android/app/AppOpsManager.java +5 −9 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading @@ -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); Loading @@ -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(); } Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java +11 −20 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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) { Loading
packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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()); } Loading @@ -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()); Loading @@ -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()); } Loading
services/tests/servicestests/src/com/android/server/appops/AppOpsNotedWatcherTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -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*/ Loading @@ -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)); Loading