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

Commit e73b5c7e authored by Rambo Wang's avatar Rambo Wang Committed by Automerger Merge Worker
Browse files

Merge "Update RatRatcheter with new CarrierConfigManager APIs" into main am: 63c7552a

parents 76306d6b 63c7552a
Loading
Loading
Loading
Loading
+11 −31
Original line number Diff line number Diff line
@@ -16,13 +16,7 @@
package com.android.internal.telephony;

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.UserHandle;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation.NetworkType;
import android.telephony.CarrierConfigManager;
@@ -80,16 +74,11 @@ public class RatRatcheter {
    /** Constructor */
    public RatRatcheter(Phone phone) {
        mPhone = phone;

        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(mConfigChangedReceiver,
                intentFilter, null /* broadcastPermission */, null);
        } catch (PackageManager.NameNotFoundException e) {
            Rlog.e(LOG_TAG, "Package name not found: " + e.getMessage());
        CarrierConfigManager ccm = mPhone.getContext().getSystemService(CarrierConfigManager.class);
        if (ccm != null) {
            ccm.registerCarrierConfigChangeListener(
                    mPhone.getContext().getMainExecutor(),
                    (slotIndex, subId, carrierId, specificCarrierId) -> 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() {
        synchronized(mRatFamilyMap) {
            mRatFamilyMap.clear();

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

            // Reads an array of strings, eg:
            // ["GPRS, EDGE", "EVDO, EVDO_A, EVDO_B", "HSPA, HSDPA, HSUPA, HSPAP"]
+9 −0
Original line number 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.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.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
@@ -31,6 +36,7 @@ import org.junit.Before;
import org.junit.Test;

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

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

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

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

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

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

        setNetworkRegistrationInfo(oldSS, TelephonyManager.NETWORK_TYPE_LTE_CA);