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

Commit 8d594afd authored by Nazanin Bakhshi's avatar Nazanin Bakhshi Committed by android-build-merger
Browse files

Fix getImsi to return for inactive and active subs

am: d6bdf0be

Change-Id: I60891994c5b98c2f979ffb074a8b6585623660ae
parents 469c2bbe d6bdf0be
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -125,9 +125,8 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
    }

    public String getSubscriberIdForSubscriber(int subId, String callingPackage) {
        Phone thePhone = getPhone(subId);
        String message = "getSubscriberId";
        if (thePhone != null) {
        if (SubscriptionController.getInstance().isActiveSubId(subId, callingPackage)) {
            return callPhoneMethodForSubIdWithReadSubscriberIdentifiersCheck(subId, callingPackage,
                    message, (phone) -> phone.getSubscriberId());
        } else {
@@ -137,7 +136,7 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
            }
            final long identity = Binder.clearCallingIdentity();
            try {
                return SubscriptionController.getInstance().getImsi(subId);
                return SubscriptionController.getInstance().getImsiPrivileged(subId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
+15 −12
Original line number Diff line number Diff line
@@ -1893,29 +1893,32 @@ public class SubscriptionController extends ISub.Stub {

    /**
     * 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 getImsi(int subId) {
        Cursor cursor = mContext.getContentResolver().query(
                SubscriptionManager.getUriForSubscriptionId(subId), null,
    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);

                new String[] {String.valueOf(subId)}, null)) {
            String imsi = null;
        try {
            if (cursor != null) {
                if (cursor.moveToNext()) {
                    imsi = getOptionalStringFromCursor(cursor, SubscriptionManager.IMSI,
                            /*defaultVal*/ null);
                }
            } else {
                logd("getImsiPrivileged: failed to retrieve imsi.");
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }

            return imsi;
        }
    }

    /**
     * Set ISO country code by subscription ID
+2 −0
Original line number Diff line number Diff line
@@ -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)