Merge "Test telephony permissions for revoked case" into main
diff --git a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
index 215f164..1af4a76 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
@@ -173,7 +173,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -195,7 +195,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
// The READ_PRIVILEGED_PHONE_STATE permission is now required to get device identifiers.
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -282,7 +282,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -303,7 +303,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -365,7 +365,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -386,7 +386,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -442,7 +442,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
@@ -451,7 +451,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
assertEquals("00", mPhoneSubInfoControllerUT.getDeviceSvnUsingSubId(0, TAG, FEATURE_ID));
@@ -508,7 +508,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -530,7 +530,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
// The READ_PRIVILEGED_PHONE_STATE permission is now required to get device identifiers.
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -593,7 +593,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -614,7 +614,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
try {
@@ -760,7 +760,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
@@ -769,7 +769,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
assertEquals("LINE1_SIM_0", mPhoneSubInfoControllerUT
@@ -907,7 +907,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
@@ -916,7 +916,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
assertEquals("+18051234567", mPhoneSubInfoControllerUT
@@ -963,7 +963,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
@@ -972,7 +972,7 @@
//case 3: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
assertEquals("VM_SIM_0", mPhoneSubInfoControllerUT
@@ -1100,7 +1100,7 @@
//case 2: no READ_PRIVILEGED_PHONE_STATE
mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE);
- doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
index e7fee6b..6369825 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
@@ -170,8 +170,10 @@
public void testCheckReadPhoneState_hasPermissionAndAppOp() {
doNothing().when(mMockContext).enforcePermission(
android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG);
- when(mMockAppOps.noteOp(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), eq(UID), eq(PACKAGE),
- eq(FEATURE), nullable(String.class))).thenReturn(AppOpsManager.MODE_ALLOWED);
+ when(mMockAppOps
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), eq(UID), eq(PACKAGE),
+ eq(FEATURE), nullable(String.class)))
+ .thenReturn(AppOpsManager.MODE_ALLOWED);
assertTrue(TelephonyPermissions.checkReadPhoneState(
mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG));
}
@@ -212,8 +214,10 @@
public void testCheckReadPhoneStateOnAnyActiveSub_hasPermissionAndAppOp() {
doNothing().when(mMockContext).enforcePermission(
android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG);
- when(mMockAppOps.noteOp(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), eq(UID), eq(PACKAGE),
- eq(FEATURE), nullable(String.class))).thenReturn(AppOpsManager.MODE_ALLOWED);
+ when(mMockAppOps
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), eq(UID), eq(PACKAGE),
+ eq(FEATURE), nullable(String.class)))
+ .thenReturn(AppOpsManager.MODE_ALLOWED);
assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub(
mMockContext, PID, UID, PACKAGE, FEATURE, MSG));
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java b/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java
index 0723268..4c1eabc 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java
@@ -527,6 +527,10 @@
// Grant READ_PHONE_STATE permission
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
// Grant identifier access
setIdentifierAccess(true);
// Revoke carrier privileges.
@@ -584,6 +588,11 @@
// Grant READ_PHONE_STATE permission
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
+
setIdentifierAccess(false);
setCarrierPrivilegesForSubId(false, 1);
setCarrierPrivilegesForSubId(false, 2);
@@ -816,6 +825,10 @@
// Grant READ_PHONE_STATE permission for insertion.
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
List<SubscriptionInfo> subInfos = mSubscriptionManagerServiceUT
.getActiveSubscriptionInfoList(CALLING_PACKAGE, CALLING_FEATURE, true);
@@ -845,6 +858,11 @@
// Grant READ_PHONE_STATE permission for insertion.
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
+
SubscriptionInfo subInfo = mSubscriptionManagerServiceUT
.getActiveSubscriptionInfoForSimSlotIndex(0, CALLING_PACKAGE,
CALLING_FEATURE);
@@ -939,6 +957,10 @@
public void testUpdateEmbeddedSubscriptionsNullResult() {
// Grant READ_PHONE_STATE permission.
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
doReturn(null).when(mEuiccController).blockingGetEuiccProfileInfoList(anyInt());
@@ -960,6 +982,11 @@
// Grant READ_PHONE_STATE permission for insertion.
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
+
SubscriptionInfo subInfo = mSubscriptionManagerServiceUT
.getActiveSubscriptionInfoForSimSlotIndex(0, CALLING_PACKAGE,
CALLING_FEATURE);
@@ -1571,7 +1598,12 @@
assertThat(mSubscriptionManagerServiceUT.getOpportunisticSubscriptions(
CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();
+ // Grant READ_PHONE_STATE permission
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Allow the application to perform.
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
setIdentifierAccess(true);
setPhoneNumberAccess(PackageManager.PERMISSION_GRANTED);
@@ -2924,4 +2956,31 @@
assertThat(subInfo.isRemovableEmbedded()).isFalse();
assertThat(subInfo.getNativeAccessRules()).isEqualTo(new byte[]{});
}
+
+
+ @Test
+ public void testGetActiveSubscriptionInfoListNoSecurityException() {
+ // Grant MODIFY_PHONE_STATE permission for insertion.
+ mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
+ insertSubscription(FAKE_SUBSCRIPTION_INFO1);
+ insertSubscription(new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO2)
+ .setSimSlotIndex(SubscriptionManager.INVALID_SIM_SLOT_INDEX).build());
+ // Remove MODIFY_PHONE_STATE
+ mContextFixture.removeCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
+
+ // Should get an empty list without READ_PHONE_STATE.
+ assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
+ CALLING_PACKAGE, CALLING_FEATURE, true)).isEmpty();
+
+ // Grant READ_PHONE_STATE permission for insertion.
+ mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ // Disallow the application to perform.
+ doReturn(AppOpsManager.MODE_ERRORED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(),
+ nullable(String.class), nullable(String.class), nullable(String.class));
+
+ // Should get an empty list if the application is not allowed to perform it.
+ assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
+ CALLING_PACKAGE, CALLING_FEATURE, true)).isEmpty();
+ }
}