Loading src/java/com/android/internal/telephony/PhoneSubInfoController.java +61 −22 Original line number Diff line number Diff line Loading @@ -53,7 +53,9 @@ import com.android.internal.telephony.uicc.UiccPort; import com.android.telephony.Rlog; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class PhoneSubInfoController extends IPhoneSubInfo.Stub { private static final String TAG = "PhoneSubInfoController"; Loading Loading @@ -477,19 +479,20 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { * * @param subId subscriptionId * @param callingPackage package name of the caller * @param callingFeatureId feature Id of the caller * @return List of public user identities of type android.net.Uri or empty list if * EF_IMPU is not available. * @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 List<Uri> getImsPublicUserIdentities(int subId, String callingPackage, String callingFeatureId) { if (TelephonyPermissions. checkCallingOrSelfReadPrivilegedPhoneStatePermissionOrReadPhoneNumber( mContext, subId, callingPackage, callingFeatureId, "getImsPublicUserIdentities")) { public List<Uri> getImsPublicUserIdentities(int subId, String callingPackage) { if (!SubscriptionManager.isValidSubscriptionId(subId)) { throw new IllegalArgumentException("Invalid subscription: " + subId); } TelephonyPermissions .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( mContext, subId, "getImsPublicUserIdentities"); enforceTelephonyFeatureWithException(callingPackage, PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getImsPublicUserIdentities"); Loading @@ -507,9 +510,6 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { return impuList; } throw new IllegalStateException("ISIM is not loaded"); } else { throw new IllegalArgumentException("Invalid SubscriptionID = " + subId); } } /** Loading Loading @@ -545,6 +545,45 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { }); } /** * Fetches the IMS Proxy Call Session Control Function(P-CSCF) based on the subscription. * * @param subId subscriptionId * @param callingPackage package name of the caller * @return List of IMS Proxy Call Session Control Function strings. * @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 List<String> getImsPcscfAddresses(int subId, String callingPackage) { if (!mFeatureFlags.supportIsimRecord()) { return new ArrayList<>(); } if (!SubscriptionManager.isValidSubscriptionId(subId)) { throw new IllegalArgumentException("Invalid subscription: " + subId); } TelephonyPermissions .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( mContext, subId, "getImsPcscfAddresses"); enforceTelephonyFeatureWithException(callingPackage, PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getImsPcscfAddresses"); Phone phone = getPhone(subId); assert phone != null; IsimRecords isimRecords = phone.getIsimRecords(); if (isimRecords != null) { String[] pcscfs = isimRecords.getIsimPcscf(); List<String> pcscfList = Arrays.stream(pcscfs) .filter(u -> u != null) .map(u -> u.trim()) .filter(u -> u.length() > 0) .collect(Collectors.toList()); return pcscfList; } throw new IllegalStateException("ISIM is not loaded"); } /** * Returns the USIM service table that fetched from EFUST elementary field that are loaded * based on the appType. Loading tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +106 −19 Original line number Diff line number Diff line Loading @@ -1270,8 +1270,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); assertNotNull(impuList); assertEquals(refImpuArray.length, impuList.size()); Loading @@ -1288,8 +1287,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { refImpuArray[2] = "tel:+91987754324"; doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); assertNotNull(impuList); // Null or Empty string cannot be converted to URI assertEquals(refImpuArray.length - 2, impuList.size()); Loading @@ -1300,7 +1298,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(null).when(mPhone).getIsimRecords(); try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalStateException); Loading @@ -1311,32 +1309,121 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { @Test public void getImsPublicUserIdentities_InValidSubIdCheck() { try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(-1, TAG, FEATURE_ID); mPhoneSubInfoControllerUT.getImsPublicUserIdentities(-1, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); assertTrue(ex.getMessage().contains("Invalid SubscriptionID")); assertTrue(ex.getMessage().contains("Invalid subscription")); } } @Test public void getImsPublicUserIdentities_NoReadPrivilegedPermission() { mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL); String[] refImpuArray = new String[3]; refImpuArray[0] = "012345678"; refImpuArray[1] = "sip:test@verify.com"; refImpuArray[2] = "tel:+91987754324"; try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof SecurityException); assertTrue(ex.getMessage().contains("getImsPublicUserIdentities")); } mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE); } @Test public void getImsPcscfAddresses() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = "127.0.0.1"; preDefinedPcscfs[1] = "192.168.0.1"; preDefinedPcscfs[2] = "::1"; doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); assertEquals(preDefinedPcscfs.length, pcscfAddresses.size()); assertEquals(preDefinedPcscfs[0], pcscfAddresses.get(0).toString()); assertEquals(preDefinedPcscfs[1], pcscfAddresses.get(1).toString()); assertEquals(preDefinedPcscfs[2], pcscfAddresses.get(2).toString()); } @Test public void getImsPcscfAddresses_InvalidPcscf() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = null; preDefinedPcscfs[2] = ""; preDefinedPcscfs[2] = "::1"; doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); // Null or Empty string is not added to pcscf list assertEquals(preDefinedPcscfs.length - 2, pcscfAddresses.size()); } @Test public void getImsPcscfAddresses_IsimNotLoadedError() { doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(null).when(mPhone).getIsimRecords(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalStateException); assertTrue(ex.getMessage().contains("ISIM is not loaded")); } } @Test public void getImsPcscfAddresses_InValidSubIdCheck() { doReturn(true).when(mFeatureFlags).supportIsimRecord(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(-1, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); assertTrue(ex.getMessage().contains("Invalid subscription")); } } @Test public void getImsPcscfAddresses_NoReadPrivilegedPermission() { mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL); doReturn(true).when(mFeatureFlags).supportIsimRecord(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof SecurityException); assertTrue(ex.getMessage().contains("getImsPcscfAddresses")); } assertNotNull(impuList); assertEquals(refImpuArray.length, impuList.size()); assertEquals(impuList.get(0).toString(), refImpuArray[0]); assertEquals(impuList.get(1).toString(), refImpuArray[1]); assertEquals(impuList.get(2).toString(), refImpuArray[2]); mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE); } @Test public void getImsPcscfAddresses_FlagDisabled() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = "127.0.0.1"; preDefinedPcscfs[1] = "192.168.0.1"; preDefinedPcscfs[2] = "::1"; doReturn(false).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); assertEquals(0, pcscfAddresses.size()); } } No newline at end of file Loading
src/java/com/android/internal/telephony/PhoneSubInfoController.java +61 −22 Original line number Diff line number Diff line Loading @@ -53,7 +53,9 @@ import com.android.internal.telephony.uicc.UiccPort; import com.android.telephony.Rlog; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class PhoneSubInfoController extends IPhoneSubInfo.Stub { private static final String TAG = "PhoneSubInfoController"; Loading Loading @@ -477,19 +479,20 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { * * @param subId subscriptionId * @param callingPackage package name of the caller * @param callingFeatureId feature Id of the caller * @return List of public user identities of type android.net.Uri or empty list if * EF_IMPU is not available. * @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 List<Uri> getImsPublicUserIdentities(int subId, String callingPackage, String callingFeatureId) { if (TelephonyPermissions. checkCallingOrSelfReadPrivilegedPhoneStatePermissionOrReadPhoneNumber( mContext, subId, callingPackage, callingFeatureId, "getImsPublicUserIdentities")) { public List<Uri> getImsPublicUserIdentities(int subId, String callingPackage) { if (!SubscriptionManager.isValidSubscriptionId(subId)) { throw new IllegalArgumentException("Invalid subscription: " + subId); } TelephonyPermissions .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( mContext, subId, "getImsPublicUserIdentities"); enforceTelephonyFeatureWithException(callingPackage, PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getImsPublicUserIdentities"); Loading @@ -507,9 +510,6 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { return impuList; } throw new IllegalStateException("ISIM is not loaded"); } else { throw new IllegalArgumentException("Invalid SubscriptionID = " + subId); } } /** Loading Loading @@ -545,6 +545,45 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { }); } /** * Fetches the IMS Proxy Call Session Control Function(P-CSCF) based on the subscription. * * @param subId subscriptionId * @param callingPackage package name of the caller * @return List of IMS Proxy Call Session Control Function strings. * @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 List<String> getImsPcscfAddresses(int subId, String callingPackage) { if (!mFeatureFlags.supportIsimRecord()) { return new ArrayList<>(); } if (!SubscriptionManager.isValidSubscriptionId(subId)) { throw new IllegalArgumentException("Invalid subscription: " + subId); } TelephonyPermissions .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( mContext, subId, "getImsPcscfAddresses"); enforceTelephonyFeatureWithException(callingPackage, PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getImsPcscfAddresses"); Phone phone = getPhone(subId); assert phone != null; IsimRecords isimRecords = phone.getIsimRecords(); if (isimRecords != null) { String[] pcscfs = isimRecords.getIsimPcscf(); List<String> pcscfList = Arrays.stream(pcscfs) .filter(u -> u != null) .map(u -> u.trim()) .filter(u -> u.length() > 0) .collect(Collectors.toList()); return pcscfList; } throw new IllegalStateException("ISIM is not loaded"); } /** * Returns the USIM service table that fetched from EFUST elementary field that are loaded * based on the appType. Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +106 −19 Original line number Diff line number Diff line Loading @@ -1270,8 +1270,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); assertNotNull(impuList); assertEquals(refImpuArray.length, impuList.size()); Loading @@ -1288,8 +1287,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { refImpuArray[2] = "tel:+91987754324"; doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); assertNotNull(impuList); // Null or Empty string cannot be converted to URI assertEquals(refImpuArray.length - 2, impuList.size()); Loading @@ -1300,7 +1298,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(null).when(mPhone).getIsimRecords(); try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalStateException); Loading @@ -1311,32 +1309,121 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { @Test public void getImsPublicUserIdentities_InValidSubIdCheck() { try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(-1, TAG, FEATURE_ID); mPhoneSubInfoControllerUT.getImsPublicUserIdentities(-1, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); assertTrue(ex.getMessage().contains("Invalid SubscriptionID")); assertTrue(ex.getMessage().contains("Invalid subscription")); } } @Test public void getImsPublicUserIdentities_NoReadPrivilegedPermission() { mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL); String[] refImpuArray = new String[3]; refImpuArray[0] = "012345678"; refImpuArray[1] = "sip:test@verify.com"; refImpuArray[2] = "tel:+91987754324"; try { mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof SecurityException); assertTrue(ex.getMessage().contains("getImsPublicUserIdentities")); } mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE); } @Test public void getImsPcscfAddresses() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = "127.0.0.1"; preDefinedPcscfs[1] = "192.168.0.1"; preDefinedPcscfs[2] = "::1"; doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(refImpuArray).when(mIsimUiccRecords).getIsimImpu(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<Uri> impuList = mPhoneSubInfoControllerUT.getImsPublicUserIdentities(0, TAG, FEATURE_ID); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); assertEquals(preDefinedPcscfs.length, pcscfAddresses.size()); assertEquals(preDefinedPcscfs[0], pcscfAddresses.get(0).toString()); assertEquals(preDefinedPcscfs[1], pcscfAddresses.get(1).toString()); assertEquals(preDefinedPcscfs[2], pcscfAddresses.get(2).toString()); } @Test public void getImsPcscfAddresses_InvalidPcscf() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = null; preDefinedPcscfs[2] = ""; preDefinedPcscfs[2] = "::1"; doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); // Null or Empty string is not added to pcscf list assertEquals(preDefinedPcscfs.length - 2, pcscfAddresses.size()); } @Test public void getImsPcscfAddresses_IsimNotLoadedError() { doReturn(true).when(mFeatureFlags).supportIsimRecord(); doReturn(null).when(mPhone).getIsimRecords(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalStateException); assertTrue(ex.getMessage().contains("ISIM is not loaded")); } } @Test public void getImsPcscfAddresses_InValidSubIdCheck() { doReturn(true).when(mFeatureFlags).supportIsimRecord(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(-1, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); assertTrue(ex.getMessage().contains("Invalid subscription")); } } @Test public void getImsPcscfAddresses_NoReadPrivilegedPermission() { mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL); doReturn(true).when(mFeatureFlags).supportIsimRecord(); try { mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); fail(); } catch (Exception ex) { assertTrue(ex instanceof SecurityException); assertTrue(ex.getMessage().contains("getImsPcscfAddresses")); } assertNotNull(impuList); assertEquals(refImpuArray.length, impuList.size()); assertEquals(impuList.get(0).toString(), refImpuArray[0]); assertEquals(impuList.get(1).toString(), refImpuArray[1]); assertEquals(impuList.get(2).toString(), refImpuArray[2]); mContextFixture.addCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE); } @Test public void getImsPcscfAddresses_FlagDisabled() { String[] preDefinedPcscfs = new String[3]; preDefinedPcscfs[0] = "127.0.0.1"; preDefinedPcscfs[1] = "192.168.0.1"; preDefinedPcscfs[2] = "::1"; doReturn(false).when(mFeatureFlags).supportIsimRecord(); doReturn(mIsimUiccRecords).when(mPhone).getIsimRecords(); doReturn(preDefinedPcscfs).when(mIsimUiccRecords).getIsimPcscf(); List<String> pcscfAddresses = mPhoneSubInfoControllerUT.getImsPcscfAddresses(0, TAG); assertNotNull(pcscfAddresses); assertEquals(0, pcscfAddresses.size()); } } No newline at end of file