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

Commit 8e4c65ee authored by rambowang's avatar rambowang Committed by Rambo Wang
Browse files

Update NetworkRegistrationManager with new CarrierConfigManager APIs

Improve NetworkRegistrationManager performance by
- Replacing carrier config change broadcast receiver with listener
  which has much smaller lagency
- Retrieving subset of carrier configs to save memory

Bug: 263267340
Test: atest ServiceStateTrackerTest
Change-Id: I39a11d3e08379d1a7fd512b5f5648a9699f862ef
parent 2ebe9f86
Loading
Loading
Loading
Loading
+22 −41
Original line number Diff line number Diff line
@@ -16,13 +16,10 @@

package com.android.internal.telephony;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.IBinder;
@@ -30,7 +27,6 @@ import android.os.Message;
import android.os.PersistableBundle;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.os.UserHandle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.CarrierConfigManager;
@@ -58,9 +54,6 @@ public class NetworkRegistrationManager extends Handler {
    private final int mTransportType;

    private final Phone mPhone;

    private final CarrierConfigManager mCarrierConfigManager;

    // Registrants who listens registration state change callback from this class.
    private final RegistrantList mRegStateChangeRegistrants = new RegistrantList();

@@ -72,22 +65,6 @@ public class NetworkRegistrationManager extends Handler {

    private NetworkServiceConnection mServiceConnection;

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action)
                    && mPhone.getPhoneId() == intent.getIntExtra(
                    CarrierConfigManager.EXTRA_SLOT_INDEX, 0)) {
                // We should wait for carrier config changed event because the target binding
                // package name can come from the carrier config. Note that we still get this event
                // even when SIM is absent.
                logd("Carrier config changed. Try to bind network service.");
                sendEmptyMessage(EVENT_BIND_NETWORK_SERVICE);
            }
        }
    };

    public NetworkRegistrationManager(@TransportType int transportType, Phone phone) {
        mTransportType = transportType;
        mPhone = phone;
@@ -96,19 +73,20 @@ public class NetworkRegistrationManager extends Handler {
                ? "C" : "I") + "-" + mPhone.getPhoneId();
        mTag = "NRM" + tagSuffix;

        mCarrierConfigManager = (CarrierConfigManager) phone.getContext().getSystemService(
                Context.CARRIER_CONFIG_SERVICE);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        try {
            Context contextAsUser = phone.getContext().createPackageContextAsUser(
                phone.getContext().getPackageName(), 0, UserHandle.ALL);
            contextAsUser.registerReceiver(mBroadcastReceiver, intentFilter,
                null /* broadcastPermission */, null);
        } catch (PackageManager.NameNotFoundException e) {
            loge("Package name not found: " + e.getMessage());
        CarrierConfigManager ccm = phone.getContext().getSystemService(CarrierConfigManager.class);
        // Callback directly calls rebindService and should be executed in handler thread
        ccm.registerCarrierConfigChangeListener(
                this::post,
                (slotIndex, subId, carrierId, specificCarrierId) -> {
                    if (slotIndex == phone.getPhoneId()) {
                        // We should wait for carrier config changed event because the target
                        // binding package name can come from the carrier config. Note that
                        // we still get this event even when SIM is absent.
                        logd("Carrier config changed. Try to bind network service.");
                        rebindService();
                    }
                });

        PhoneConfigurationManager.registerForMultiSimConfigChange(
                this, EVENT_BIND_NETWORK_SERVICE, null);

@@ -333,9 +311,10 @@ public class NetworkRegistrationManager extends Handler {
        // Read package name from resource overlay
        packageName = mPhone.getContext().getResources().getString(resourceId);

        PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId());

        if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) {
        PersistableBundle b =
                CarrierConfigManager.getCarrierConfigSubset(
                        mPhone.getContext(), mPhone.getSubId(), carrierConfig);
        if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) {
            // If carrier config overrides it, use the one from carrier config
            packageName = b.getString(carrierConfig, packageName);
        }
@@ -367,15 +346,17 @@ public class NetworkRegistrationManager extends Handler {
        // Read class name from resource overlay
        className = mPhone.getContext().getResources().getString(resourceId);

        PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId());

        if (b != null && !TextUtils.isEmpty(b.getString(carrierConfig))) {
        PersistableBundle b =
                CarrierConfigManager.getCarrierConfigSubset(
                        mPhone.getContext(), mPhone.getSubId(), carrierConfig);
        if (!b.isEmpty() && !TextUtils.isEmpty(b.getString(carrierConfig))) {
            // If carrier config overrides it, use the one from carrier config
            className = b.getString(carrierConfig, className);
        }

        return className;
    }

    private void logd(String msg) {
        Rlog.d(mTag, msg);
    }
+1 −0
Original line number Diff line number Diff line
@@ -242,6 +242,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {

        replaceInstance(ProxyController.class, "sProxyController", null, mProxyController);
        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle);
        mBundle.putStringArray(
                CarrierConfigManager.KEY_ROAMING_OPERATOR_STRING_ARRAY, new String[]{"123456"});