Loading core/java/android/app/AppOpsManager.java +7 −7 Original line number Diff line number Diff line Loading @@ -577,9 +577,9 @@ public class AppOpsManager { * make them all controlled by the same single operation. */ private static int[] sOpToSwitch = new int[] { OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_COARSE_LOCATION OP_COARSE_LOCATION, // OP_FINE_LOCATION OP_COARSE_LOCATION, // OP_GPS OP_VIBRATE, OP_READ_CONTACTS, OP_WRITE_CONTACTS, Loading @@ -587,9 +587,9 @@ public class AppOpsManager { OP_WRITE_CALL_LOG, OP_READ_CALENDAR, OP_WRITE_CALENDAR, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_WIFI_SCAN (results can be used to locate user) OP_POST_NOTIFICATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_NEIGHBORING_CELLS OP_CALL_PHONE, OP_READ_SMS, OP_WRITE_SMS, Loading Loading @@ -618,8 +618,8 @@ public class AppOpsManager { OP_AUDIO_NOTIFICATION_VOLUME, OP_AUDIO_BLUETOOTH_VOLUME, OP_WAKE_LOCK, OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_MONITOR_LOCATION OP_COARSE_LOCATION, // OP_MONITOR_HIGH_POWER_LOCATION OP_GET_USAGE_STATS, OP_MUTE_MICROPHONE, OP_TOAST_WINDOW, Loading services/tests/servicestests/src/com/android/server/appops/AppOpsServiceTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package com.android.server; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.MODE_ERRORED; import static android.app.AppOpsManager.OP_COARSE_LOCATION; import static android.app.AppOpsManager.OP_READ_SMS; import static android.app.AppOpsManager.OP_WIFI_SCAN; import static android.app.AppOpsManager.OP_WRITE_SMS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -103,6 +105,31 @@ public class AppOpsServiceTest { assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED); } /** * Tests the scenario where an operation's permission is controlled by another operation. * For example the results of a WIFI_SCAN can be used to infer the location of a user, so the * ACCESS_COARSE_LOCATION op is used to check whether WIFI_SCAN is allowed. */ @Test public void testNoteOperationAndGetOpsForPackage_controlledByDifferentOp() { // This op controls WIFI_SCAN mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, mMyPackageName, MODE_ALLOWED); assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, mMyPackageName)) .isEqualTo(MODE_ALLOWED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); // Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well. mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, mMyPackageName, MODE_ERRORED); assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, mMyPackageName)) .isEqualTo(MODE_ERRORED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); } // Tests the dumping and restoring of the in-memory state to/from XML. @Test public void testStatePersistence() { Loading Loading
core/java/android/app/AppOpsManager.java +7 −7 Original line number Diff line number Diff line Loading @@ -577,9 +577,9 @@ public class AppOpsManager { * make them all controlled by the same single operation. */ private static int[] sOpToSwitch = new int[] { OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_COARSE_LOCATION OP_COARSE_LOCATION, // OP_FINE_LOCATION OP_COARSE_LOCATION, // OP_GPS OP_VIBRATE, OP_READ_CONTACTS, OP_WRITE_CONTACTS, Loading @@ -587,9 +587,9 @@ public class AppOpsManager { OP_WRITE_CALL_LOG, OP_READ_CALENDAR, OP_WRITE_CALENDAR, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_WIFI_SCAN (results can be used to locate user) OP_POST_NOTIFICATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_NEIGHBORING_CELLS OP_CALL_PHONE, OP_READ_SMS, OP_WRITE_SMS, Loading Loading @@ -618,8 +618,8 @@ public class AppOpsManager { OP_AUDIO_NOTIFICATION_VOLUME, OP_AUDIO_BLUETOOTH_VOLUME, OP_WAKE_LOCK, OP_COARSE_LOCATION, OP_COARSE_LOCATION, OP_COARSE_LOCATION, // OP_MONITOR_LOCATION OP_COARSE_LOCATION, // OP_MONITOR_HIGH_POWER_LOCATION OP_GET_USAGE_STATS, OP_MUTE_MICROPHONE, OP_TOAST_WINDOW, Loading
services/tests/servicestests/src/com/android/server/appops/AppOpsServiceTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package com.android.server; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.MODE_ERRORED; import static android.app.AppOpsManager.OP_COARSE_LOCATION; import static android.app.AppOpsManager.OP_READ_SMS; import static android.app.AppOpsManager.OP_WIFI_SCAN; import static android.app.AppOpsManager.OP_WRITE_SMS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -103,6 +105,31 @@ public class AppOpsServiceTest { assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED); } /** * Tests the scenario where an operation's permission is controlled by another operation. * For example the results of a WIFI_SCAN can be used to infer the location of a user, so the * ACCESS_COARSE_LOCATION op is used to check whether WIFI_SCAN is allowed. */ @Test public void testNoteOperationAndGetOpsForPackage_controlledByDifferentOp() { // This op controls WIFI_SCAN mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, mMyPackageName, MODE_ALLOWED); assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, mMyPackageName)) .isEqualTo(MODE_ALLOWED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); // Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well. mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, mMyPackageName, MODE_ERRORED); assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, mMyPackageName)) .isEqualTo(MODE_ERRORED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); } // Tests the dumping and restoring of the in-memory state to/from XML. @Test public void testStatePersistence() { Loading