Loading tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; Loading Loading @@ -60,7 +59,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG, FEATURE_ID); doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG, FEATURE_ID); doReturn(new int[]{0, 1}).when(mSubscriptionManager) .getActiveSubscriptionIdList(anyBoolean()); .getActiveAndHiddenSubscriptionIdList(); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java +6 −22 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -106,7 +105,7 @@ public class TelephonyPermissionsTest { mMockSubscriptionManager); when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn( mMockDevicePolicyManager); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID}); // By default, assume we have no permissions or app-ops bits. Loading Loading @@ -351,23 +350,7 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnOtherSubscription() throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); 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)); } @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnInvisibleSubscription() throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(true)).thenReturn( new int[]{SUB_ID}); when(mMockSubscriptionManager.getActiveSubscriptionIdList(false)).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); Loading @@ -381,10 +364,11 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasAppOpNullSubscription() { // The appop check comes after the carrier privilege check; this test verifies if the // SubscriptionManager returns a null array for the active subscription IDs this check can // SubscriptionManager returns an empty array for the active subscription IDs this check can // still proceed to check if the calling package has the appop and any subsequent checks // without a NullPointerException. when(mMockSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(null); when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()) .thenReturn(new int[0]); when(mMockAppOps.noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_DEVICE_IDENTIFIERS), eq(UID), eq(PACKAGE), eq(FEATURE), nullable(String.class))).thenReturn( AppOpsManager.MODE_ALLOWED); Loading Loading @@ -452,7 +436,7 @@ public class TelephonyPermissionsTest { when(mMockContext.checkPermission( eq(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); Loading Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; Loading Loading @@ -60,7 +59,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG, FEATURE_ID); doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG, FEATURE_ID); doReturn(new int[]{0, 1}).when(mSubscriptionManager) .getActiveSubscriptionIdList(anyBoolean()); .getActiveAndHiddenSubscriptionIdList(); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java +6 −22 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -106,7 +105,7 @@ public class TelephonyPermissionsTest { mMockSubscriptionManager); when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn( mMockDevicePolicyManager); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID}); // By default, assume we have no permissions or app-ops bits. Loading Loading @@ -351,23 +350,7 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnOtherSubscription() throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( new int[]{SUB_ID, SUB_ID_2}); 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)); } @Test public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnInvisibleSubscription() throws Exception { when(mMockSubscriptionManager.getActiveSubscriptionIdList(true)).thenReturn( new int[]{SUB_ID}); when(mMockSubscriptionManager.getActiveSubscriptionIdList(false)).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); Loading @@ -381,10 +364,11 @@ public class TelephonyPermissionsTest { @Test public void testCheckReadDeviceIdentifiers_hasAppOpNullSubscription() { // The appop check comes after the carrier privilege check; this test verifies if the // SubscriptionManager returns a null array for the active subscription IDs this check can // SubscriptionManager returns an empty array for the active subscription IDs this check can // still proceed to check if the calling package has the appop and any subsequent checks // without a NullPointerException. when(mMockSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(null); when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()) .thenReturn(new int[0]); when(mMockAppOps.noteOpNoThrow(eq(AppOpsManager.OPSTR_READ_DEVICE_IDENTIFIERS), eq(UID), eq(PACKAGE), eq(FEATURE), nullable(String.class))).thenReturn( AppOpsManager.MODE_ALLOWED); Loading Loading @@ -452,7 +436,7 @@ public class TelephonyPermissionsTest { when(mMockContext.checkPermission( eq(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn( when(mMockSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn( new int[]{SUB_ID, SUB_ID_2}); when(mTelephonyManagerMock.createForSubscriptionId(eq(SUB_ID_2))).thenReturn( mTelephonyManagerMockForSub2); Loading