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

Commit 18d20ba9 authored by Rambo Wang's avatar Rambo Wang Committed by Android (Google) Code Review
Browse files

Merge "Update RatRatcheter with new CarrierConfigManager APIs"

parents 17884e73 9eb55811
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"]
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;

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

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

        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName());
        mSstHandler.start();
        waitUntilReady();
+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);
+2 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Executor;

public class ServiceStateTrackerTest extends TelephonyTest {
    // Mocked classes
@@ -229,6 +230,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        mSubInfo = Mockito.mock(SubscriptionInfo.class);
        mServiceStateStats = Mockito.mock(ServiceStateStats.class);

        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mContextFixture.putResource(R.string.config_wwan_network_service_package,
                "com.android.phone");
        mContextFixture.putResource(R.string.config_wlan_network_service_package,