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

Commit d89bc9d4 authored by Rambo Wang's avatar Rambo Wang
Browse files

Update SubscriptionInfoUpdater to use TM#getCarrierServicePackageName

The implementation for TelephonyManager#getCarrierServicePackageName
has been highly optimized. Internally, the cached values are directly
returned instead of performing a heavy query from package manager.

Besides the performance improvement, the switch may also largely reduce
the deadlock and IPC thread blocking due to the removal of IPC
call in most time.

Bug: 217442920
Test: atest SubscriptionInfoUpdaterTest
Change-Id: I3545bd3b807c9efe5ea525b0bf6ebde42386486a
parent bcf5d849
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.os.PersistableBundle;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.service.carrier.CarrierIdentifier;
import android.service.carrier.CarrierService;
import android.service.euicc.EuiccProfileInfo;
import android.service.euicc.EuiccService;
import android.service.euicc.GetEuiccProfileInfoListResult;
@@ -1141,11 +1140,10 @@ public class SubscriptionInfoUpdater extends Handler {
    private boolean isCarrierServicePackage(int phoneId, String pkgName) {
        if (pkgName.equals(getDefaultCarrierServicePackageName())) return false;

        List<String> carrierPackageNames = TelephonyManager.from(sContext)
                .getCarrierPackageNamesForIntentAndPhone(
                        new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
        if (DBG) logd("Carrier Packages For Subscription = " + carrierPackageNames);
        return carrierPackageNames != null && carrierPackageNames.contains(pkgName);
        String carrierPackageName = TelephonyManager.from(sContext)
                .getCarrierServicePackageNameForLogicalSlot(phoneId);
        if (DBG) logd("Carrier service package for subscription = " + carrierPackageName);
        return pkgName.equals(carrierPackageName);
    }

    /**
+12 −13
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ import org.mockito.stubbing.Answer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@@ -746,8 +745,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

        doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getSubIdUsingPhoneId(phoneId);
        doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());
@@ -772,8 +771,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getSubIdUsingPhoneId(phoneId);
        doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
        doReturn(false).when(mSubInfo).isOpportunistic();
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());
@@ -805,8 +804,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
                ParcelUuid.fromString("11111111-2222-3333-4444-555555555555"), carrierPackageName);
        doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getSubIdUsingPhoneId(phoneId);
        doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());
@@ -842,8 +841,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
        doReturn(ParcelUuid.fromString("11111111-2222-3333-4444-555555555555"))
            .when(mSubInfo).getGroupUuid();
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());
@@ -922,8 +921,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        final int phoneId = mPhone.getPhoneId();

        // Install fixtures, ensure the test will hit the right code path
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());
@@ -982,8 +981,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getSubIdUsingPhoneId(phoneId);
        doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
        doReturn(false).when(mSubInfo).isOpportunistic();
        doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager)
                .getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
        doReturn(carrierPackageName).when(mTelephonyManager)
                .getCarrierServicePackageNameForLogicalSlot(eq(phoneId));
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(),
                new FakeSubscriptionContentProvider());