Loading src/java/com/android/internal/telephony/PhoneSubInfoController.java +1 −1 Original line number Diff line number Diff line Loading @@ -270,7 +270,7 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { return; } if (VDBG) log("No read privileged phone permission, check carrier privilege next."); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, message); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mContext, subId, message); } /** Loading src/java/com/android/internal/telephony/SmsPermissions.java +2 −1 Original line number Diff line number Diff line Loading @@ -96,7 +96,8 @@ public class SmsPermissions { } } TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mPhone.getSubId(), message); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( mContext, mPhone.getSubId(), message); } /** Loading tests/telephonytests/src/com/android/internal/telephony/SmsPermissionsTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import org.mockito.MockitoAnnotations; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class SmsPermissionsTest { public class SmsPermissionsTest extends TelephonyTest { private static final String PACKAGE = "com.example.package"; private static final String MESSAGE = "msg"; Loading @@ -59,6 +59,8 @@ public class SmsPermissionsTest { @Before public void setUp() throws Exception { super.setUp("SmsPermissionsTest"); MockitoAnnotations.initMocks(this); mHandlerThread = new HandlerThread("IccSmsInterfaceManagerTest"); mHandlerThread.start(); Loading Loading @@ -89,6 +91,8 @@ public class SmsPermissionsTest { @After public void tearDown() throws Exception { mHandlerThread.quit(); mHandlerThread.join(); super.tearDown(); } @Test Loading Loading @@ -196,6 +200,8 @@ public class SmsPermissionsTest { @Test public void testCheckCallingOrSelfCanGetSmscAddressPermissions_noPermissions() { Mockito.when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManager); Mockito.when(mMockContext.checkCallingOrSelfPermission( Manifest.permission.READ_PRIVILEGED_PHONE_STATE)) .thenReturn(PERMISSION_DENIED); Loading @@ -221,9 +227,10 @@ public class SmsPermissionsTest { @Test public void testCheckCallingOrSelfCanSetSmscAddressPermissions_noPermissions() { Mockito.when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManager); Mockito.when(mMockContext.checkCallingOrSelfPermission( Manifest.permission.MODIFY_PHONE_STATE)) .thenReturn(PERMISSION_DENIED); Manifest.permission.MODIFY_PHONE_STATE)).thenReturn(PERMISSION_DENIED); assertFalse(mSmsPermissionsTest.checkCallingOrSelfCanSetSmscAddress(PACKAGE, MESSAGE)); } } tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java +53 −27 Original line number Diff line number Diff line Loading @@ -83,6 +83,12 @@ public class TelephonyPermissionsTest { private ApplicationInfo mMockApplicationInfo; @Mock private DevicePolicyManager mMockDevicePolicyManager; @Mock private TelephonyManager mTelephonyManagerMock; @Mock private TelephonyManager mTelephonyManagerMockForSub1; @Mock private TelephonyManager mTelephonyManagerMockForSub2; private MockContentResolver mMockContentResolver; private FakeSettingsConfigProvider mFakeSettingsConfigProvider; Loading @@ -90,6 +96,11 @@ public class TelephonyPermissionsTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManagerMock); when(mTelephonyManagerMock.createForSubscriptionId(anyInt())).thenReturn( mTelephonyManagerMock); when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mMockAppOps); when(mMockContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)).thenReturn( mMockSubscriptionManager); Loading Loading @@ -122,7 +133,7 @@ public class TelephonyPermissionsTest { public void testCheckReadPhoneState_noPermissions() { try { TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); fail("Should have thrown SecurityException"); } catch (SecurityException e) { // expected Loading @@ -134,7 +145,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -144,7 +155,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_STATE, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -152,21 +163,23 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG); assertFalse(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneState_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneStateOnAnyActiveSub_noPermissions() { assertFalse(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -174,7 +187,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -184,7 +197,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_STATE, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -192,22 +205,25 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG); assertFalse(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneStateOnAnyActiveSub_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneNumber_noPermissions() { try { TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); fail("Should have thrown SecurityException"); } catch (SecurityException e) { // expected Loading @@ -219,7 +235,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_WRITE_SMS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -227,7 +243,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -237,7 +253,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_SMS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -247,7 +263,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_NUMBERS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -273,8 +289,10 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading Loading @@ -334,7 +352,9 @@ public class TelephonyPermissionsTest { throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))).thenReturn( when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, Loading @@ -348,8 +368,10 @@ public class TelephonyPermissionsTest { new int[]{SUB_ID}); when(mMockSubscriptionManager.getActiveSubscriptionIdList(false)).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading Loading @@ -411,8 +433,10 @@ public class TelephonyPermissionsTest { when(mMockContext.checkPermission( eq(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), anyInt())) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadSubscriberIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading @@ -428,7 +452,9 @@ public class TelephonyPermissionsTest { anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), anyInt())).thenReturn( when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); // Carrier privilege on the other active sub shouldn't allow access to this sub. try { Loading Loading
src/java/com/android/internal/telephony/PhoneSubInfoController.java +1 −1 Original line number Diff line number Diff line Loading @@ -270,7 +270,7 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { return; } if (VDBG) log("No read privileged phone permission, check carrier privilege next."); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, message); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mContext, subId, message); } /** Loading
src/java/com/android/internal/telephony/SmsPermissions.java +2 −1 Original line number Diff line number Diff line Loading @@ -96,7 +96,8 @@ public class SmsPermissions { } } TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mPhone.getSubId(), message); TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( mContext, mPhone.getSubId(), message); } /** Loading
tests/telephonytests/src/com/android/internal/telephony/SmsPermissionsTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import org.mockito.MockitoAnnotations; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class SmsPermissionsTest { public class SmsPermissionsTest extends TelephonyTest { private static final String PACKAGE = "com.example.package"; private static final String MESSAGE = "msg"; Loading @@ -59,6 +59,8 @@ public class SmsPermissionsTest { @Before public void setUp() throws Exception { super.setUp("SmsPermissionsTest"); MockitoAnnotations.initMocks(this); mHandlerThread = new HandlerThread("IccSmsInterfaceManagerTest"); mHandlerThread.start(); Loading Loading @@ -89,6 +91,8 @@ public class SmsPermissionsTest { @After public void tearDown() throws Exception { mHandlerThread.quit(); mHandlerThread.join(); super.tearDown(); } @Test Loading Loading @@ -196,6 +200,8 @@ public class SmsPermissionsTest { @Test public void testCheckCallingOrSelfCanGetSmscAddressPermissions_noPermissions() { Mockito.when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManager); Mockito.when(mMockContext.checkCallingOrSelfPermission( Manifest.permission.READ_PRIVILEGED_PHONE_STATE)) .thenReturn(PERMISSION_DENIED); Loading @@ -221,9 +227,10 @@ public class SmsPermissionsTest { @Test public void testCheckCallingOrSelfCanSetSmscAddressPermissions_noPermissions() { Mockito.when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManager); Mockito.when(mMockContext.checkCallingOrSelfPermission( Manifest.permission.MODIFY_PHONE_STATE)) .thenReturn(PERMISSION_DENIED); Manifest.permission.MODIFY_PHONE_STATE)).thenReturn(PERMISSION_DENIED); assertFalse(mSmsPermissionsTest.checkCallingOrSelfCanSetSmscAddress(PACKAGE, MESSAGE)); } }
tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java +53 −27 Original line number Diff line number Diff line Loading @@ -83,6 +83,12 @@ public class TelephonyPermissionsTest { private ApplicationInfo mMockApplicationInfo; @Mock private DevicePolicyManager mMockDevicePolicyManager; @Mock private TelephonyManager mTelephonyManagerMock; @Mock private TelephonyManager mTelephonyManagerMockForSub1; @Mock private TelephonyManager mTelephonyManagerMockForSub2; private MockContentResolver mMockContentResolver; private FakeSettingsConfigProvider mFakeSettingsConfigProvider; Loading @@ -90,6 +96,11 @@ public class TelephonyPermissionsTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(mMockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn( mTelephonyManagerMock); when(mTelephonyManagerMock.createForSubscriptionId(anyInt())).thenReturn( mTelephonyManagerMock); when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mMockAppOps); when(mMockContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)).thenReturn( mMockSubscriptionManager); Loading Loading @@ -122,7 +133,7 @@ public class TelephonyPermissionsTest { public void testCheckReadPhoneState_noPermissions() { try { TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); fail("Should have thrown SecurityException"); } catch (SecurityException e) { // expected Loading @@ -134,7 +145,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -144,7 +155,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_STATE, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -152,21 +163,23 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG); assertFalse(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneState_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue(TelephonyPermissions.checkReadPhoneState( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneStateOnAnyActiveSub_noPermissions() { assertFalse(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -174,7 +187,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -184,7 +197,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_STATE, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -192,22 +205,25 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PHONE_STATE, PID, UID, MSG); assertFalse(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneStateOnAnyActiveSub_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue(TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( mMockContext, () -> mMockTelephony, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, PID, UID, PACKAGE, FEATURE, MSG)); } @Test public void testCheckReadPhoneNumber_noPermissions() { try { TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG); fail("Should have thrown SecurityException"); } catch (SecurityException e) { // expected Loading @@ -219,7 +235,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_WRITE_SMS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -227,7 +243,7 @@ public class TelephonyPermissionsTest { doNothing().when(mMockContext).enforcePermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, PID, UID, MSG); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -237,7 +253,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_SMS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -247,7 +263,7 @@ public class TelephonyPermissionsTest { when(mMockAppOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_NUMBERS, UID, PACKAGE)) .thenReturn(AppOpsManager.MODE_ALLOWED); assertTrue(TelephonyPermissions.checkReadPhoneNumber( mMockContext, () -> mMockTelephony, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG)); } @Test Loading @@ -273,8 +289,10 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivileges() throws Exception { when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading Loading @@ -334,7 +352,9 @@ public class TelephonyPermissionsTest { throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))).thenReturn( when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, Loading @@ -348,8 +368,10 @@ public class TelephonyPermissionsTest { new int[]{SUB_ID}); when(mMockSubscriptionManager.getActiveSubscriptionIdList(false)).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading Loading @@ -411,8 +433,10 @@ public class TelephonyPermissionsTest { when(mMockContext.checkPermission( eq(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID), anyInt())) .thenReturn(TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID))).thenReturn( mTelephonyManagerMockForSub1); when(mTelephonyManagerMockForSub1.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); assertTrue( TelephonyPermissions.checkCallingOrSelfReadSubscriberIdentifiers(mMockContext, SUB_ID, PACKAGE, FEATURE, MSG)); Loading @@ -428,7 +452,9 @@ public class TelephonyPermissionsTest { anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), anyInt())).thenReturn( when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); when(mTelephonyManagerMockForSub2.getCarrierPrivilegeStatus(anyInt())).thenReturn( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS); // Carrier privilege on the other active sub shouldn't allow access to this sub. try { Loading