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

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

Merge "Update SignalStrengthController with new CarrierConfigManager APIs" into main am: bce2d934

parents 32d9e29b bce2d934
Loading
Loading
Loading
Loading
+8 −27
Original line number Diff line number Diff line
@@ -18,10 +18,7 @@ package com.android.internal.telephony;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.IBinder;
@@ -100,7 +97,6 @@ public class SignalStrengthController extends Handler {
    private static final int EVENT_POLL_SIGNAL_STRENGTH                     = 7;
    private static final int EVENT_SIGNAL_STRENGTH_UPDATE                   = 8;
    private static final int EVENT_POLL_SIGNAL_STRENGTH_DONE                = 9;
    private static final int EVENT_CARRIER_CONFIG_CHANGED                   = 10;

    @NonNull
    private final Phone mPhone;
@@ -146,20 +142,6 @@ public class SignalStrengthController extends Handler {
    @NonNull
    private final LocalLog mLocalLog = new LocalLog(64);

    private 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)) {
                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);
                }
            }
        }
    };

    public SignalStrengthController(@NonNull Phone phone) {
        mPhone = phone;
        mCi = mPhone.mCi;
@@ -169,10 +151,12 @@ public class SignalStrengthController extends Handler {
        mCi.setOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
        setSignalStrengthDefaultValues();

        CarrierConfigManager ccm = mPhone.getContext().getSystemService(CarrierConfigManager.class);
        mCarrierConfig = getCarrierConfig();
        IntentFilter filter = new IntentFilter();
        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        mPhone.getContext().registerReceiver(mBroadcastReceiver, filter);
        // Callback which directly handle config change should be executed on handler thread
        ccm.registerCarrierConfigChangeListener(this::post,
                (slotIndex, subId, carrierId, specificCarrierId) ->
                        onCarrierConfigurationChanged(slotIndex));
    }

    @Override
@@ -285,11 +269,6 @@ public class SignalStrengthController extends Handler {
                break;
            }

            case EVENT_CARRIER_CONFIG_CHANGED: {
                onCarrierConfigChanged();
                break;
            }

            default:
                log("Unhandled message with number: " + msg.what);
                break;
@@ -1014,7 +993,9 @@ public class SignalStrengthController extends Handler {
        return earfcnPairList;
    }

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

        mCarrierConfig = getCarrierConfig();
        log("Carrier Config changed.");

+17 −8
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.telephony.SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSSI
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
@@ -31,7 +32,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
@@ -47,6 +47,7 @@ import android.telephony.CellSignalStrengthWcdma;
import android.telephony.SignalStrength;
import android.telephony.SignalStrengthUpdateRequest;
import android.telephony.SignalThresholdInfo;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.MediumTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -91,16 +92,13 @@ public class SignalStrengthControllerTest extends TelephonyTest {

    private SignalStrengthController mSsc;
    private PersistableBundle mBundle;
    private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;

    @Before
    public void setUp() throws Exception {
        super.setUp(this.getClass().getSimpleName());
        mHandler = Mockito.mock(Handler.class);

        when(mPhone.getSubId()).thenReturn(ACTIVE_SUB_ID);
        mSsc = new SignalStrengthController(mPhone);
        replaceInstance(Handler.class, "mLooper", mHandler, mSsc.getLooper());
        replaceInstance(Phone.class, "mLooper", mPhone, mSsc.getLooper());

        // Config a fixed supported RAN/MeasurementTypes to make the test more stable
        mBundle = mContextFixture.getCarrierConfigBundle();
@@ -147,6 +145,18 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                        15, /* SIGNAL_STRENGTH_GOOD */
                        30  /* SIGNAL_STRENGTH_GREAT */
                });

        // Capture listener to emulate the carrier config change notification used later
        ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor =
                ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class);
        mSsc = new SignalStrengthController(mPhone);
        verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(),
                listenerArgumentCaptor.capture());
        mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0);

        replaceInstance(Handler.class, "mLooper", mHandler, mSsc.getLooper());
        replaceInstance(Phone.class, "mLooper", mPhone, mSsc.getLooper());

        processAllMessages();
        reset(mSimulatedCommandsVerifier);
    }
@@ -818,9 +828,8 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                .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, ACTIVE_SUB_ID,
                TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID);
        processAllMessages();
    }