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

Commit 50461264 authored by arunvoddu's avatar arunvoddu Committed by Arun kumar Voddu
Browse files

Interface for PSI-SMSC value from UICC

Bug: 236680361
Test: Done with manual and atest verification
Change-Id: I3359d274322a981bf2353a771fc37626f4309d6b
parent 4327d1bd
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -583,6 +583,30 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
        }
        }
    }
    }


    /**
     * Returns SIP URI or tel URI of the Public Service Identity of the SM-SC that fetched from
     * EFPSISMSC elementary field that are loaded based on the ISIM/USIM appType.
     */
    public String getSmscIdentity(int subId, int appType)
            throws RemoteException {
        return callPhoneMethodForSubIdWithPrivilegedCheck(subId, "getSmscIdentity",
                (phone) -> {
                    UiccPort uiccPort = phone.getUiccPort();
                    if (uiccPort == null || uiccPort.getUiccProfile() == null) {
                        loge("getSmscIdentity(): uiccPort or uiccProfile is null");
                        return null;
                    }
                    UiccCardApplication uiccApp = uiccPort.getUiccProfile().getApplicationByType(
                            appType);
                    if (uiccApp == null) {
                        loge("getSmscIdentity(): no app with specified type = "
                                + appType);
                        return null;
                    }
                    return uiccApp.getIccRecords().getSmscIdentity();
                });
    }

    private void log(String s) {
    private void log(String s) {
        Rlog.d(TAG, s);
        Rlog.d(TAG, s);
    }
    }
+150 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.internal.telephony;
package com.android.internal.telephony;


import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
@@ -33,15 +34,27 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.RemoteException;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import com.android.internal.telephony.uicc.IsimUiccRecords;
import com.android.internal.telephony.uicc.SIMRecords;
import com.android.internal.telephony.uicc.UiccCardApplication;
import com.android.internal.telephony.uicc.UiccPort;
import com.android.internal.telephony.uicc.UiccProfile;

import org.junit.After;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.mockito.Mockito;


public class PhoneSubInfoControllerTest extends TelephonyTest {
public class PhoneSubInfoControllerTest extends TelephonyTest {
    private static final String FEATURE_ID = "myfeatureId";
    private static final String FEATURE_ID = "myfeatureId";
    private static final String PSI_SMSC_TEL1 = "tel:+91123456789";
    private static final String PSI_SMSC_SIP1 = "sip:+1234567890@msg.pc.t-mobile.com;user=phone";
    private static final String PSI_SMSC_TEL2 = "tel:+91987654321";
    private static final String PSI_SMSC_SIP2 = "sip:+19876543210@msg.pc.t-mobile.com;user=phone";


    private PhoneSubInfoController mPhoneSubInfoControllerUT;
    private PhoneSubInfoController mPhoneSubInfoControllerUT;
    private AppOpsManager mAppOsMgr;
    private AppOpsManager mAppOsMgr;
@@ -922,4 +935,141 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
        assertEquals("VM_SIM_1", mPhoneSubInfoControllerUT
        assertEquals("VM_SIM_1", mPhoneSubInfoControllerUT
                .getVoiceMailAlphaTagForSubscriber(1, TAG, FEATURE_ID));
                .getVoiceMailAlphaTagForSubscriber(1, TAG, FEATURE_ID));
    }
    }

    private void setUpInitials() {
        UiccPort uiccPort1 = Mockito.mock(UiccPort.class);
        UiccProfile uiccProfile1 = Mockito.mock(UiccProfile.class);
        UiccCardApplication uiccCardApplication1 = Mockito.mock(UiccCardApplication.class);
        SIMRecords simRecords1 = Mockito.mock(SIMRecords.class);
        IsimUiccRecords isimUiccRecords1 = Mockito.mock(IsimUiccRecords.class);

        doReturn(uiccPort1).when(mPhone).getUiccPort();
        doReturn(uiccProfile1).when(uiccPort1).getUiccProfile();
        doReturn(uiccCardApplication1).when(uiccProfile1).getApplicationByType(anyInt());
        doReturn(simRecords1).when(uiccCardApplication1).getIccRecords();
        doReturn(isimUiccRecords1).when(uiccCardApplication1).getIccRecords();
        doReturn(PSI_SMSC_TEL1).when(simRecords1).getSmscIdentity();
        doReturn(PSI_SMSC_TEL1).when(isimUiccRecords1).getSmscIdentity();

        doReturn(mUiccPort).when(mSecondPhone).getUiccPort();
        doReturn(mUiccProfile).when(mUiccPort).getUiccProfile();
        doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplicationByType(anyInt());
        doReturn(mSimRecords).when(mUiccCardApplicationIms).getIccRecords();
        doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords();
        doReturn(PSI_SMSC_TEL2).when(mSimRecords).getSmscIdentity();
        doReturn(PSI_SMSC_TEL2).when(mIsimUiccRecords).getSmscIdentity();
    }

    @Test
    public void testGetSmscIdentityForTelUri() {
        try {
            setUpInitials();
            assertEquals(PSI_SMSC_TEL1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 5));
            assertEquals(PSI_SMSC_TEL1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 3));
            assertEquals(PSI_SMSC_TEL2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
            assertEquals(PSI_SMSC_TEL2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testGetSmscIdentityForSipUri() {
        try {
            UiccPort uiccPort1 = Mockito.mock(UiccPort.class);
            UiccProfile uiccProfile1 = Mockito.mock(UiccProfile.class);
            UiccCardApplication uiccCardApplication1 = Mockito.mock(UiccCardApplication.class);
            SIMRecords simRecords1 = Mockito.mock(SIMRecords.class);
            IsimUiccRecords isimUiccRecords1 = Mockito.mock(IsimUiccRecords.class);

            doReturn(uiccPort1).when(mPhone).getUiccPort();
            doReturn(uiccProfile1).when(uiccPort1).getUiccProfile();
            doReturn(uiccCardApplication1).when(uiccProfile1).getApplicationByType(anyInt());
            doReturn(simRecords1).when(uiccCardApplication1).getIccRecords();
            doReturn(isimUiccRecords1).when(uiccCardApplication1).getIccRecords();
            doReturn(PSI_SMSC_SIP1).when(simRecords1).getSmscIdentity();
            doReturn(PSI_SMSC_SIP1).when(isimUiccRecords1).getSmscIdentity();

            doReturn(mUiccPort).when(mSecondPhone).getUiccPort();
            doReturn(mUiccProfile).when(mUiccPort).getUiccProfile();
            doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplicationByType(anyInt());
            doReturn(mSimRecords).when(mUiccCardApplicationIms).getIccRecords();
            doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords();
            doReturn(PSI_SMSC_SIP2).when(mSimRecords).getSmscIdentity();
            doReturn(PSI_SMSC_SIP2).when(mIsimUiccRecords).getSmscIdentity();

            assertEquals(PSI_SMSC_SIP1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 5));
            assertEquals(PSI_SMSC_SIP1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 3));
            assertEquals(PSI_SMSC_SIP2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
            assertEquals(PSI_SMSC_SIP2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testGetSmscIdentityWithOutPermissions() {
        setUpInitials();

        //case 1: no READ_PRIVILEGED_PHONE_STATE & appOsMgr READ_PHONE_PERMISSION
        mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL);
        try {
            mPhoneSubInfoControllerUT.getSmscIdentity(0, 5);
            Assert.fail("expected Security Exception Thrown");
        } catch (Exception ex) {
            assertTrue(ex instanceof SecurityException);
            assertTrue(ex.getMessage().contains("getSmscIdentity"));
        }

        try {
            mPhoneSubInfoControllerUT.getSmscIdentity(1, 5);
            Assert.fail("expected Security Exception Thrown");
        } catch (Exception ex) {
            assertTrue(ex instanceof SecurityException);
            assertTrue(ex.getMessage().contains("getSmscIdentity"));
        }

        try {
            mPhoneSubInfoControllerUT.getSmscIdentity(0, 3);
            Assert.fail("expected Security Exception Thrown");
        } catch (Exception ex) {
            assertTrue(ex instanceof SecurityException);
            assertTrue(ex.getMessage().contains("getSmscIdentity"));
        }

        try {
            mPhoneSubInfoControllerUT.getSmscIdentity(1, 3);
            Assert.fail("expected Security Exception Thrown");
        } catch (Exception ex) {
            assertTrue(ex instanceof SecurityException);
            assertTrue(ex.getMessage().contains("getSmscIdentity"));
        }

        //case 2: no READ_PRIVILEGED_PHONE_STATE
        mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE);
        doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
                eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
                nullable(String.class));

        try {
            assertEquals(PSI_SMSC_TEL1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 5));
            assertEquals(PSI_SMSC_TEL1, mPhoneSubInfoControllerUT
                    .getSmscIdentity(0, 3));
            assertEquals(PSI_SMSC_TEL2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
            assertEquals(PSI_SMSC_TEL2, mPhoneSubInfoControllerUT
                    .getSmscIdentity(1, 5));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
}