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

Commit 2555ad00 authored by rambowang's avatar rambowang
Browse files

Update RatRatcheter with new CarrierConfigManager APIs

- Replace carrier config change broadcast receiver with listener
  which has better performance
- Retrieve subset of carrier configs as needed to save memory

Bug: 244087782
Test: atest RatRatcheterTest ServiceStateTrackerTest
Change-Id: I1c07e553692ae94a32199cdd052aac24cfa05d75
Merged-In: I1c07e553692ae94a32199cdd052aac24cfa05d75
(cherry picked from commit 9eb55811)
parent 7c0e97dd
Loading
Loading
Loading
Loading
+11 −31
Original line number Original line Diff line number Diff line
@@ -16,13 +16,7 @@
package com.android.internal.telephony;
package com.android.internal.telephony;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.NetworkType;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
@@ -80,16 +74,11 @@ public class RatRatcheter {
    /** Constructor */
    /** Constructor */
    public RatRatcheter(Phone phone) {
    public RatRatcheter(Phone phone) {
        mPhone = phone;
        mPhone = phone;

        CarrierConfigManager ccm = mPhone.getContext().getSystemService(CarrierConfigManager.class);
        IntentFilter intentFilter = new IntentFilter();
        if (ccm != null) {
        intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
            ccm.registerCarrierConfigChangeListener(
        try {
                    mPhone.getContext().getMainExecutor(),
            Context contextAsUser = phone.getContext().createPackageContextAsUser(
                    (slotIndex, subId, carrierId, specificCarrierId) -> resetRatFamilyMap());
                phone.getContext().getPackageName(), 0, UserHandle.ALL);
            contextAsUser.registerReceiver(mConfigChangedReceiver,
                intentFilter, null /* broadcastPermission */, null);
        } catch (PackageManager.NameNotFoundException e) {
            Rlog.e(LOG_TAG, "Package name not found: " + e.getMessage());
        }
        }
        resetRatFamilyMap();
        resetRatFamilyMap();
    }
    }
@@ -183,25 +172,16 @@ public class RatRatcheter {
        }
        }
    }
    }


    private BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action)) {
                resetRatFamilyMap();
            }
        }
    };

    private void resetRatFamilyMap() {
    private void resetRatFamilyMap() {
        synchronized(mRatFamilyMap) {
        synchronized(mRatFamilyMap) {
            mRatFamilyMap.clear();
            mRatFamilyMap.clear();


            final CarrierConfigManager configManager = (CarrierConfigManager)
            PersistableBundle b =
                    mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
                    CarrierConfigManager.getCarrierConfigSubset(
            if (configManager == null) return;
                            mPhone.getContext(),
            PersistableBundle b = configManager.getConfigForSubId(mPhone.getSubId());
                            mPhone.getSubId(),
            if (b == null) return;
                            CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES);
            if (b == null || b.isEmpty()) return;


            // Reads an array of strings, eg:
            // Reads an array of strings, eg:
            // ["GPRS, EDGE", "EVDO, EVDO_A, EVDO_B", "HSPA, HSDPA, HSUPA, HSPAP"]
            // ["GPRS, EDGE", "EVDO, EVDO_A, EVDO_B", "HSPA, HSDPA, HSUPA, HSPAP"]
+2 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Mockito;


import java.util.Collections;
import java.util.Collections;
import java.util.concurrent.Executor;


@RunWith(AndroidTestingRunner.class)
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper
@@ -90,6 +91,7 @@ public class DisplayInfoControllerTest extends TelephonyTest {
        logd("DisplayInfoControllerTest setup!");
        logd("DisplayInfoControllerTest setup!");
        super.setUp(getClass().getSimpleName());
        super.setUp(getClass().getSimpleName());


        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName());
        mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName());
        mSstHandler.start();
        mSstHandler.start();
        waitUntilReady();
        waitUntilReady();
+9 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,11 @@ package com.android.internal.telephony;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertTrue;


import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
@@ -31,6 +36,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.Test;


import java.util.Arrays;
import java.util.Arrays;
import java.util.concurrent.Executor;


/** Tests for RatRatcheter. */
/** Tests for RatRatcheter. */
public class RatRatcheterTest extends TelephonyTest {
public class RatRatcheterTest extends TelephonyTest {
@@ -41,6 +47,7 @@ public class RatRatcheterTest extends TelephonyTest {
    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        super.setUp(getClass().getSimpleName());
        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mServiceState = new ServiceState();
        mServiceState = new ServiceState();
    }
    }


@@ -135,6 +142,7 @@ public class RatRatcheterTest extends TelephonyTest {
        ServiceState newSS = new ServiceState();
        ServiceState newSS = new ServiceState();


        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle);
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES,
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES,
                new String[]{"14,19"});
                new String[]{"14,19"});


@@ -153,6 +161,7 @@ public class RatRatcheterTest extends TelephonyTest {
        ServiceState newSS = new ServiceState();
        ServiceState newSS = new ServiceState();


        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle);
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES, new String[]{});
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES, new String[]{});


        setNetworkRegistrationInfo(oldSS, TelephonyManager.NETWORK_TYPE_LTE_CA);
        setNetworkRegistrationInfo(oldSS, TelephonyManager.NETWORK_TYPE_LTE_CA);
+3 −0
Original line number Original line Diff line number Diff line
@@ -112,6 +112,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.concurrent.Executor;


public class ServiceStateTrackerTest extends TelephonyTest {
public class ServiceStateTrackerTest extends TelephonyTest {
    // Mocked classes
    // Mocked classes
@@ -236,6 +237,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {


        doReturn(mSubInfoInternal).when(mSubscriptionManagerService)
        doReturn(mSubInfoInternal).when(mSubscriptionManagerService)
                .getSubscriptionInfoInternal(anyInt());
                .getSubscriptionInfoInternal(anyInt());
        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mContextFixture.putResource(R.string.config_wwan_network_service_package,
        mContextFixture.putResource(R.string.config_wwan_network_service_package,
                "com.android.phone");
                "com.android.phone");
        mContextFixture.putResource(R.string.config_wlan_network_service_package,
        mContextFixture.putResource(R.string.config_wlan_network_service_package,
@@ -249,6 +251,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {


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