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

Commit f92af313 authored by Nazanin Bakhshi's avatar Nazanin Bakhshi
Browse files

Store subscriber ID / IMSI into telephony database

Bug: 131916175
Test: manual
Change-Id: I64cd12a6737b7ef7fb31b851c1cbb5b7f46e6ca7
Merged-In: I64cd12a6737b7ef7fb31b851c1cbb5b7f46e6ca7
(cherry picked from commit cdbf6a9b)
parent afa38d35
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -125,8 +125,23 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
    }

    public String getSubscriberIdForSubscriber(int subId, String callingPackage) {
        Phone thePhone = getPhone(subId);
        String message = "getSubscriberId";
        if (thePhone != null) {
            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().getImsi(subId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }

    /**
+47 −1
Original line number Diff line number Diff line
@@ -1822,6 +1822,53 @@ 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
     * @return imsi
     */
    public String getImsi(int subId) {
        Cursor cursor = mContext.getContentResolver().query(
                SubscriptionManager.getUriForSubscriptionId(subId), null,
                SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=?",
                new String[]{String.valueOf(subId)}, null);

        String imsi = null;
        try {
            if (cursor != null) {
                if (cursor.moveToNext()) {
                    imsi = getOptionalStringFromCursor(cursor, SubscriptionManager.IMSI,
                            /*defaultVal*/ null);
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return imsi;
    }

    /**
     * Set ISO country code by subscription ID
     * @param iso iso country code associated with the subscription
@@ -2917,7 +2964,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.
+7 −1
Original line number Diff line number Diff line
@@ -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)) {
@@ -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) {
+1 −0
Original line number Diff line number Diff line
@@ -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"
                    + ");";
        }

+7 −0
Original line number Diff line number Diff line
@@ -346,6 +346,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() {