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

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

Merge "Update ServiceStateTracker with new CarrierConfigManager APIs" into udc-dev am: 360d5f0d

parents 5c0c16fa 360d5f0d
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -279,7 +279,6 @@ public class ServiceStateTracker extends Handler {
    protected static final int EVENT_RADIO_POWER_OFF_DONE              = 54;
    protected static final int EVENT_PHYSICAL_CHANNEL_CONFIG           = 55;
    protected static final int EVENT_CELL_LOCATION_RESPONSE            = 56;
    protected static final int EVENT_CARRIER_CONFIG_CHANGED            = 57;
    private static final int EVENT_POLL_STATE_REQUEST                  = 58;
    // Timeout event used when delaying radio power off to wait for IMS deregistration to happen.
    private static final int EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT   = 62;
@@ -557,13 +556,7 @@ public class ServiceStateTracker extends Handler {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                int phoneId = intent.getExtras().getInt(CarrierConfigManager.EXTRA_SLOT_INDEX);
                // Ignore the carrier config changed if the phoneId is not matched.
                if (phoneId == mPhone.getPhoneId()) {
                    sendEmptyMessage(EVENT_CARRIER_CONFIG_CHANGED);
                }
            } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
            if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
                // Update emergency string or operator name, polling service state.
                pollState();
            } else if (action.equals(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED)) {
@@ -576,6 +569,10 @@ public class ServiceStateTracker extends Handler {
        }
    };

    private final CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener =
            (slotIndex, subId, carrierId, specificCarrierId) ->
                    onCarrierConfigurationChanged(slotIndex);

    //CDMA
    // Min values used to by getOtasp()
    public static final String UNACTIVATED_MIN2_VALUE = "000000";
@@ -662,7 +659,11 @@ public class ServiceStateTracker extends Handler {
        mSubscriptionManager.addOnSubscriptionsChangedListener(
                new android.os.HandlerExecutor(this), mOnSubscriptionsChangedListener);
        mRestrictedState = new RestrictedState();

        mCarrierConfig = getCarrierConfig();
        CarrierConfigManager ccm = mPhone.getContext().getSystemService(CarrierConfigManager.class);
        // Callback which directly handle config change should be executed in handler thread
        ccm.registerCarrierConfigChangeListener(this::post, mCarrierConfigChangeListener);

        mAccessNetworksManager = mPhone.getAccessNetworksManager();
        mOutOfServiceSS = new ServiceState();
@@ -701,7 +702,6 @@ public class ServiceStateTracker extends Handler {
        Context context = mPhone.getContext();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        filter.addAction(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
        context.registerReceiver(mIntentReceiver, filter);

@@ -862,6 +862,10 @@ public class ServiceStateTracker extends Handler {
        mPhone.getCarrierActionAgent().unregisterForCarrierAction(this,
                CARRIER_ACTION_SET_RADIO_ENABLED);
        mPhone.getContext().unregisterReceiver(mIntentReceiver);
        CarrierConfigManager ccm = mPhone.getContext().getSystemService(CarrierConfigManager.class);
        if (ccm != null && mCarrierConfigChangeListener != null) {
            ccm.unregisterCarrierConfigChangeListener(mCarrierConfigChangeListener);
        }
        if (mCSST != null) {
            mCSST.dispose();
            mCSST = null;
@@ -1730,10 +1734,6 @@ public class ServiceStateTracker extends Handler {
                rspRspMsg.sendToTarget();
                break;

            case EVENT_CARRIER_CONFIG_CHANGED:
                onCarrierConfigChanged();
                break;

            case EVENT_POLL_STATE_REQUEST:
                pollStateInternal(false);
                break;
@@ -5055,7 +5055,9 @@ public class ServiceStateTracker extends Handler {
        }
    }

    private void onCarrierConfigChanged() {
    private void onCarrierConfigurationChanged(int slotIndex) {
        if (slotIndex != mPhone.getPhoneId()) return;

        mCarrierConfig = getCarrierConfig();
        log("CarrierConfigChange " + mCarrierConfig);

+20 −18
Original line number Diff line number Diff line
@@ -18,13 +18,12 @@ package com.android.internal.telephony;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.HandlerThread;
import android.os.PersistableBundle;
@@ -36,6 +35,7 @@ import android.telephony.CellIdentityLte;
import android.telephony.LteVopsSupportInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner;
@@ -46,7 +46,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.ArgumentCaptor;

import java.util.Collections;
import java.util.concurrent.Executor;
@@ -66,6 +66,7 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    private ServiceStateTrackerTestHandler mSstHandler;
    private SignalStrengthController mSsc;
    private PersistableBundle mBundle;
    private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;

    private class ServiceStateTrackerTestHandler extends HandlerThread {
        private ServiceStateTrackerTestHandler(String name) {
@@ -80,7 +81,16 @@ public class DisplayInfoControllerTest extends TelephonyTest {
            doReturn(NUMERIC).when(mTelephonyManager).getSimOperatorNumericForPhone(eq(PHONE_ID));
            doReturn(NETWORK).when(mTelephonyManager).getSimOperatorNameForPhone(eq(PHONE_ID));

            // Capture listener registered for ServiceStateTracker to emulate the carrier config
            // change notification used later. In this test, it's the second one. The first one
            // comes from RatRatcheter.
            ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener>
                    listenerArgumentCaptor = ArgumentCaptor.forClass(
                    CarrierConfigManager.CarrierConfigChangeListener.class);
            mSst = new ServiceStateTracker(mPhone, mSimulatedCommands);
            verify(mCarrierConfigManager, atLeast(2)).registerCarrierConfigChangeListener(any(),
                    listenerArgumentCaptor.capture());
            mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(1);
            doReturn(mSst).when(mPhone).getServiceStateTracker();
            setReady(true);
        }
@@ -92,6 +102,7 @@ public class DisplayInfoControllerTest extends TelephonyTest {
        super.setUp(getClass().getSimpleName());

        doReturn((Executor) Runnable::run).when(mContext).getMainExecutor();
        mBundle = mContextFixture.getCarrierConfigBundle();
        mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName());
        mSstHandler.start();
        waitUntilReady();
@@ -106,18 +117,14 @@ public class DisplayInfoControllerTest extends TelephonyTest {
        mSstHandler.join();
        mSstHandler = null;
        mBundle = null;
        mCarrierConfigChangeListener = null;
        super.tearDown();
    }

    private void sendCarrierConfigUpdate() {
        CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class);
        when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE))
                .thenReturn(mockConfigManager);
        when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);

        Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, PHONE_ID);
        mContext.sendBroadcast(intent);
        mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID,
                TelephonyManager.UNKNOWN_CARRIER_ID);
        waitForLastHandlerAction(mSstHandler.getThreadHandler());
    }

@@ -174,7 +181,6 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    public void testIsRoamingOverride_NonRoamingOperator() {
        doReturn(true).when(mPhone).isPhoneTypeGsm();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(
                CarrierConfigManager.KEY_NON_ROAMING_OPERATOR_STRING_ARRAY, new String[] {NUMERIC});
        sendCarrierConfigUpdate();
@@ -196,7 +202,6 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    public void testIsRoamingOverride_ForceHomeNetwork() {
        doReturn(true).when(mPhone).isPhoneTypeGsm();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, true);
        sendCarrierConfigUpdate();

@@ -217,7 +222,6 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    public void testIsRoamingOverride_RoamingOperator() {
        doReturn(true).when(mPhone).isPhoneTypeGsm();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(
                CarrierConfigManager.KEY_ROAMING_OPERATOR_STRING_ARRAY, new String[] {"60101"});
        sendCarrierConfigUpdate();
@@ -239,7 +243,6 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    public void testIsRoamingOverride_NonRoamingGsmOperator() {
        doReturn(true).when(mPhone).isPhoneTypeGsm();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(
                CarrierConfigManager.KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY,
                new String[] {NUMERIC});
@@ -262,7 +265,6 @@ public class DisplayInfoControllerTest extends TelephonyTest {
    public void testIsRoamingOverride_RoamingGsmOperator() {
        doReturn(true).when(mPhone).isPhoneTypeGsm();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(
                CarrierConfigManager.KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY, new String[] {NUMERIC});
        sendCarrierConfigUpdate();
+20 −14
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    private ServiceStateStats mServiceStateStats;

    private CellularNetworkService mCellularNetworkService;
    private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;

    // SST now delegates all signal strength operations to SSC
    // Add Mock SSC as the dependency to avoid NPE
@@ -184,7 +185,18 @@ public class ServiceStateTrackerTest extends TelephonyTest {
            mSsc = new SignalStrengthController(mPhone);
            doReturn(mSsc).when(mPhone).getSignalStrengthController();

            // Capture listener registered for ServiceStateTracker to emulate the carrier config
            // change notification used later. In this test, it's the third one. The first one
            // comes from RatRatcheter and the second one comes from SignalStrengthController.
            ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener>
                    listenerArgumentCaptor =
                            ArgumentCaptor.forClass(
                                    CarrierConfigManager.CarrierConfigChangeListener.class);
            sst = new ServiceStateTracker(mPhone, mSimulatedCommands);
            verify(mCarrierConfigManager, atLeast(3)).registerCarrierConfigChangeListener(any(),
                    listenerArgumentCaptor.capture());
            mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(2);

            sst.setServiceStateStats(mServiceStateStats);
            doReturn(sst).when(mPhone).getServiceStateTracker();
            setReady(true);
@@ -253,6 +265,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        replaceInstance(ProxyController.class, "sProxyController", null, mProxyController);
        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle);
        when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);
        mBundle.putStringArray(
                CarrierConfigManager.KEY_ROAMING_OPERATOR_STRING_ARRAY, new String[]{"123456"});

@@ -355,9 +368,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
                    30  /* SIGNAL_STRENGTH_GREAT */
                });

        Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, 0);
        mContext.sendBroadcast(intent);
        sendCarrierConfigUpdate(PHONE_ID);
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());

        logd("ServiceStateTrackerTest -Setup!");
@@ -826,15 +837,10 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        verify(mPhone, times(1)).notifyServiceStateChanged(any(ServiceState.class));
    }

    private void sendCarrierConfigUpdate() {
        CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class);
        when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE))
                .thenReturn(mockConfigManager);
        when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);

        Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, PHONE_ID);
        mContext.sendBroadcast(intent);
    private void sendCarrierConfigUpdate(int phoneId) {
        mCarrierConfigChangeListener.onCarrierConfigChanged(phoneId,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID);
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
    }

@@ -2869,7 +2875,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    public void testUpdateSpnDisplay_spnEmptyAndWifiCallingEnabled_showPlmnOnly() {
        // set empty service provider name
        mBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, "");
        sendCarrierConfigUpdate();
        sendCarrierConfigUpdate(PHONE_ID);

        // GSM phone
        doReturn(true).when(mPhone).isPhoneTypeGsm();
@@ -2949,7 +2955,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    public void testUpdateSpnDisplayLegacy_WlanServiceNoWifiCalling_displayOOS() {
        mBundle.putBoolean(
                CarrierConfigManager.KEY_ENABLE_CARRIER_DISPLAY_NAME_RESOLVER_BOOL, false);
        sendCarrierConfigUpdate();
        sendCarrierConfigUpdate(PHONE_ID);

        // GSM phone
        doReturn(true).when(mPhone).isPhoneTypeGsm();