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

Commit e0c03042 authored by Arun kumar Voddu's avatar Arun kumar Voddu Committed by Android (Google) Code Review
Browse files

Merge "IMPI system API implementation"

parents b4ed7803 1fca39b9
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -352,6 +352,34 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
                });
    }

    /**
     * Fetches the IMS private user identity (EF_IMPI) based on subscriptionId.
     *
     * @param subId subscriptionId
     * @return IMPI (IMS private user identity) of type string.
     * @throws IllegalArgumentException if the subscriptionId is not valid
     * @throws IllegalStateException in case the ISIM hasn’t been loaded.
     * @throws SecurityException if the caller does not have the required permission
     */
    public String getImsPrivateUserIdentity(int subId, String callingPackage,
            String callingFeatureId) {
        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
            throw new IllegalArgumentException("Invalid SubscriptionID  = " + subId);
        }
        if (!TelephonyPermissions.checkCallingOrSelfUseIccAuthWithDeviceIdentifier(mContext,
                callingPackage, callingFeatureId, "getImsPrivateUserIdentity")) {
            throw (new SecurityException("No permissions to the caller"));
        }
        Phone phone = getPhone(subId);
        assert phone != null;
        IsimRecords isim = phone.getIsimRecords();
        if (isim != null) {
            return isim.getIsimImpi();
        } else {
            throw new IllegalStateException("ISIM is not loaded");
        }
    }

    /**
    * get the Isim Domain based on subId
    */
+45 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.telephony.TelephonyManager.APPTYPE_USIM;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.anyString;
@@ -1167,4 +1168,48 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
        mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE);
        assertEquals(refSst, mPhoneSubInfoControllerUT.getSimServiceTable(anyInt(), anyInt()));
    }

    @Test
    public void getPrivateUserIdentity() {
        String refImpi = "1234567890@example.com";
        doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords();
        doReturn(refImpi).when(mIsimUiccRecords).getIsimImpi();

        doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOpNoThrow(
                eq(AppOpsManager.OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER), anyInt(), eq(TAG),
                eq(FEATURE_ID), nullable(String.class));

        String impi = mPhoneSubInfoControllerUT.getImsPrivateUserIdentity(0, TAG, FEATURE_ID);
        assertEquals(refImpi, impi);
    }

    @Test
    public void getPrivateUserIdentity_NoPermission() {
        String refImpi = "1234567890@example.com";
        doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords();
        doReturn(refImpi).when(mIsimUiccRecords).getIsimImpi();

        try {
            mPhoneSubInfoControllerUT.getImsPrivateUserIdentity(0, TAG, FEATURE_ID);
            fail();
        } catch (Exception ex) {
            assertTrue(ex instanceof SecurityException);
            assertTrue(ex.getMessage().contains("No permissions to the caller"));
        }
    }

    @Test
    public void getPrivateUserIdentity_InValidSubIdCheck() {
        String refImpi = "1234567890@example.com";
        doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords();
        doReturn(refImpi).when(mIsimUiccRecords).getIsimImpi();

        try {
            mPhoneSubInfoControllerUT.getImsPrivateUserIdentity(-1, TAG, FEATURE_ID);
            fail();
        } catch (Exception ex) {
            assertTrue(ex instanceof IllegalArgumentException);
            assertTrue(ex.getMessage().contains("Invalid SubscriptionID"));
        }
    }
}
 No newline at end of file