Loading src/java/com/android/internal/telephony/PhoneSubInfoController.java +16 −2 Original line number Diff line number Diff line Loading @@ -125,8 +125,22 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { } public String getSubscriberIdForSubscriber(int subId, String callingPackage) { String message = "getSubscriberId"; if (SubscriptionController.getInstance().isActiveSubId(subId, callingPackage)) { return callPhoneMethodForSubIdWithReadSubscriberIdentifiersCheck(subId, callingPackage, "getSubscriberId", (phone) -> phone.getSubscriberId()); message, (phone) -> phone.getSubscriberId()); } else { if (!TelephonyPermissions.checkCallingOrSelfReadSubscriberIdentifiers( mContext, subId, callingPackage, message)) { return null; } final long identity = Binder.clearCallingIdentity(); try { return SubscriptionController.getInstance().getImsiPrivileged(subId); } finally { Binder.restoreCallingIdentity(identity); } } } /** Loading src/java/com/android/internal/telephony/SubscriptionController.java +50 −1 Original line number Diff line number Diff line Loading @@ -1822,6 +1822,56 @@ public class SubscriptionController extends ISub.Stub { return result; } /** * Set IMSI by subscription ID * @param imsi IMSI (International Mobile Subscriber Identity) * @return the number of records updated */ public int setImsi(String imsi, int subId) { if (DBG) logd("[setImsi]+ imsi:" + imsi + " subId:" + subId); ContentValues value = new ContentValues(1); value.put(SubscriptionManager.IMSI, imsi); int result = mContext.getContentResolver().update( SubscriptionManager.getUriForSubscriptionId(subId), value, null, null); // Refresh the Cache of Active Subscription Info List refreshCachedActiveSubscriptionInfoList(); notifySubscriptionInfoChanged(); return result; } /** * Get IMSI by subscription ID * For active subIds, this will always return the corresponding imsi * For inactive subIds, once they are activated once, even if they are deactivated at the time * of calling this function, the corresponding imsi will be returned * When calling this method, the permission check should have already been done to allow * only privileged read * * @return imsi */ public String getImsiPrivileged(int subId) { try (Cursor cursor = mContext.getContentResolver().query( SubscriptionManager.CONTENT_URI, null, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=?", new String[] {String.valueOf(subId)}, null)) { String imsi = null; if (cursor != null) { if (cursor.moveToNext()) { imsi = getOptionalStringFromCursor(cursor, SubscriptionManager.IMSI, /*defaultVal*/ null); } } else { logd("getImsiPrivileged: failed to retrieve imsi."); } return imsi; } } /** * Set ISO country code by subscription ID * @param iso iso country code associated with the subscription Loading Loading @@ -2917,7 +2967,6 @@ public class SubscriptionController extends ISub.Stub { } /** * * @param groupUuid a UUID assigned to the subscription group. * @param callingPackage the package making the IPC. * @return if callingPackage has carrier privilege on sublist. Loading src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +7 −1 Original line number Diff line number Diff line Loading @@ -453,7 +453,8 @@ public class SubscriptionInfoUpdater extends Handler { } else { for (SubscriptionInfo sub : subscriptionInfos) { int subId = sub.getSubscriptionId(); TelephonyManager tm = TelephonyManager.getDefault(); TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); String operator = tm.getSimOperatorNumeric(subId); if (!TextUtils.isEmpty(operator)) { Loading @@ -478,6 +479,11 @@ public class SubscriptionInfoUpdater extends Handler { SubscriptionController.getInstance().setDisplayNumber(msisdn, subId); } String imsi = tm.createForSubscriptionId(subId).getSubscriberId(); if (imsi != null) { SubscriptionController.getInstance().setImsi(imsi, subId); } String[] ehplmns = records.getEhplmns(); String[] hplmns = records.getPlmnsFromHplmnActRecord(); if (ehplmns != null || hplmns != null) { Loading tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java +1 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ public class FakeTelephonyProvider extends MockContentProvider { + SubscriptionManager.WHITE_LISTED_APN_DATA + " INTEGER DEFAULT 0," + SubscriptionManager.GROUP_OWNER + " TEXT," + SubscriptionManager.DATA_ENABLED_OVERRIDE_RULES + " TEXT" + SubscriptionManager.IMSI + " TEXT" + ");"; } Loading tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(0).when(mSubscriptionController).getPhoneId(eq(0)); doReturn(1).when(mSubscriptionController).getPhoneId(eq(1)); doReturn(2).when(mTelephonyManager).getPhoneCount(); doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG); doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) Loading Loading @@ -346,6 +348,13 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { .getSubscriberIdForSubscriber(1, TAG)); } @Test @SmallTest public void testGetSubscriberIdWithInactiveSubId() { //IMSI assertNull(mPhoneSubInfoControllerUT.getSubscriberIdForSubscriber(2, TAG)); } @Test @SmallTest public void testGetSubscriberIdWithOutPermission() { Loading Loading
src/java/com/android/internal/telephony/PhoneSubInfoController.java +16 −2 Original line number Diff line number Diff line Loading @@ -125,8 +125,22 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub { } public String getSubscriberIdForSubscriber(int subId, String callingPackage) { String message = "getSubscriberId"; if (SubscriptionController.getInstance().isActiveSubId(subId, callingPackage)) { return callPhoneMethodForSubIdWithReadSubscriberIdentifiersCheck(subId, callingPackage, "getSubscriberId", (phone) -> phone.getSubscriberId()); message, (phone) -> phone.getSubscriberId()); } else { if (!TelephonyPermissions.checkCallingOrSelfReadSubscriberIdentifiers( mContext, subId, callingPackage, message)) { return null; } final long identity = Binder.clearCallingIdentity(); try { return SubscriptionController.getInstance().getImsiPrivileged(subId); } finally { Binder.restoreCallingIdentity(identity); } } } /** Loading
src/java/com/android/internal/telephony/SubscriptionController.java +50 −1 Original line number Diff line number Diff line Loading @@ -1822,6 +1822,56 @@ public class SubscriptionController extends ISub.Stub { return result; } /** * Set IMSI by subscription ID * @param imsi IMSI (International Mobile Subscriber Identity) * @return the number of records updated */ public int setImsi(String imsi, int subId) { if (DBG) logd("[setImsi]+ imsi:" + imsi + " subId:" + subId); ContentValues value = new ContentValues(1); value.put(SubscriptionManager.IMSI, imsi); int result = mContext.getContentResolver().update( SubscriptionManager.getUriForSubscriptionId(subId), value, null, null); // Refresh the Cache of Active Subscription Info List refreshCachedActiveSubscriptionInfoList(); notifySubscriptionInfoChanged(); return result; } /** * Get IMSI by subscription ID * For active subIds, this will always return the corresponding imsi * For inactive subIds, once they are activated once, even if they are deactivated at the time * of calling this function, the corresponding imsi will be returned * When calling this method, the permission check should have already been done to allow * only privileged read * * @return imsi */ public String getImsiPrivileged(int subId) { try (Cursor cursor = mContext.getContentResolver().query( SubscriptionManager.CONTENT_URI, null, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=?", new String[] {String.valueOf(subId)}, null)) { String imsi = null; if (cursor != null) { if (cursor.moveToNext()) { imsi = getOptionalStringFromCursor(cursor, SubscriptionManager.IMSI, /*defaultVal*/ null); } } else { logd("getImsiPrivileged: failed to retrieve imsi."); } return imsi; } } /** * Set ISO country code by subscription ID * @param iso iso country code associated with the subscription Loading Loading @@ -2917,7 +2967,6 @@ public class SubscriptionController extends ISub.Stub { } /** * * @param groupUuid a UUID assigned to the subscription group. * @param callingPackage the package making the IPC. * @return if callingPackage has carrier privilege on sublist. Loading
src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +7 −1 Original line number Diff line number Diff line Loading @@ -453,7 +453,8 @@ public class SubscriptionInfoUpdater extends Handler { } else { for (SubscriptionInfo sub : subscriptionInfos) { int subId = sub.getSubscriptionId(); TelephonyManager tm = TelephonyManager.getDefault(); TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); String operator = tm.getSimOperatorNumeric(subId); if (!TextUtils.isEmpty(operator)) { Loading @@ -478,6 +479,11 @@ public class SubscriptionInfoUpdater extends Handler { SubscriptionController.getInstance().setDisplayNumber(msisdn, subId); } String imsi = tm.createForSubscriptionId(subId).getSubscriberId(); if (imsi != null) { SubscriptionController.getInstance().setImsi(imsi, subId); } String[] ehplmns = records.getEhplmns(); String[] hplmns = records.getPlmnsFromHplmnActRecord(); if (ehplmns != null || hplmns != null) { Loading
tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java +1 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ public class FakeTelephonyProvider extends MockContentProvider { + SubscriptionManager.WHITE_LISTED_APN_DATA + " INTEGER DEFAULT 0," + SubscriptionManager.GROUP_OWNER + " TEXT," + SubscriptionManager.DATA_ENABLED_OVERRIDE_RULES + " TEXT" + SubscriptionManager.IMSI + " TEXT" + ");"; } Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { doReturn(0).when(mSubscriptionController).getPhoneId(eq(0)); doReturn(1).when(mSubscriptionController).getPhoneId(eq(1)); doReturn(2).when(mTelephonyManager).getPhoneCount(); doReturn(true).when(mSubscriptionController).isActiveSubId(0, TAG); doReturn(true).when(mSubscriptionController).isActiveSubId(1, TAG); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) Loading Loading @@ -346,6 +348,13 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { .getSubscriberIdForSubscriber(1, TAG)); } @Test @SmallTest public void testGetSubscriberIdWithInactiveSubId() { //IMSI assertNull(mPhoneSubInfoControllerUT.getSubscriberIdForSubscriber(2, TAG)); } @Test @SmallTest public void testGetSubscriberIdWithOutPermission() { Loading