Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f258abbd authored by Hunter Knepshield's avatar Hunter Knepshield
Browse files

Fix TelephonyPermissionsTest for carrier privilege changes.

Carrier privileges on "invisible" (grouped + opportunistic)
subscriptions were not previously considered during privilege checking
for device identifiers. Method signatures were updated, so tests need to
reflect this.

Bug: 135684437
Test: atest FrameworksTelephonyTests
Change-Id: If8dbd73e56676afb8eee9dedf60c2e16e5764f05
parent 6ed38737
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.Manifest.permission.READ_SMS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
@@ -54,6 +55,8 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
        doReturn(2).when(mTelephonyManager).getPhoneCount();
        doReturn(2).when(mTelephonyManager).getPhoneCount();
        doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG);
        doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG);
        doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG);
        doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG);
        doReturn(new int[]{0, 1}).when(mSubscriptionManager)
                .getActiveSubscriptionIdList(anyBoolean());


        mServiceManagerMockedServices.put("isub", mSubscriptionController);
        mServiceManagerMockedServices.put("isub", mSubscriptionController);
        doReturn(mSubscriptionController).when(mSubscriptionController)
        doReturn(mSubscriptionController).when(mSubscriptionController)
+18 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
@@ -85,7 +86,8 @@ public class TelephonyPermissionsTest {
                mMockSubscriptionManager);
                mMockSubscriptionManager);
        when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(
        when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(
                mMockDevicePolicyManager);
                mMockDevicePolicyManager);
        when(mMockSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID});
        when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn(
                new int[]{SUB_ID});


        // By default, assume we have no permissions or app-ops bits.
        // By default, assume we have no permissions or app-ops bits.
        doThrow(new SecurityException()).when(mMockContext)
        doThrow(new SecurityException()).when(mMockContext)
@@ -318,7 +320,7 @@ public class TelephonyPermissionsTest {
    @Test
    @Test
    public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnOtherSubscription()
    public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnOtherSubscription()
            throws Exception {
            throws Exception {
        when(mMockSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(
        when(mMockSubscriptionManager.getActiveSubscriptionIdList(anyBoolean())).thenReturn(
                new int[]{SUB_ID, SUB_ID_2});
                new int[]{SUB_ID, SUB_ID_2});
        when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))).thenReturn(
        when(mMockTelephony.getCarrierPrivilegeStatusForUid(eq(SUB_ID_2), eq(UID))).thenReturn(
                TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS);
                TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS);
@@ -327,6 +329,20 @@ public class TelephonyPermissionsTest {
                        SUB_ID, PID, UID, PACKAGE, MSG));
                        SUB_ID, PID, UID, PACKAGE, MSG));
    }
    }


    @Test
    public void testCheckReadDeviceIdentifiers_hasCarrierPrivilegesOnInvisibleSubscription()
            throws Exception {
        when(mMockSubscriptionManager.getActiveSubscriptionIdList(true)).thenReturn(
                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);
        assertTrue(
                TelephonyPermissions.checkReadDeviceIdentifiers(mMockContext, () -> mMockTelephony,
                        SUB_ID_2, PID, UID, PACKAGE, MSG));
    }

    @Test
    @Test
    public void testCheckReadDeviceIdentifiers_hasAppOpNullSubscription() {
    public void testCheckReadDeviceIdentifiers_hasAppOpNullSubscription() {
        // The appop check comes after the carrier privilege check; this test verifies if the
        // The appop check comes after the carrier privilege check; this test verifies if the