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

Commit f5a48eb0 authored by rambowang's avatar rambowang Committed by Rambo Wang
Browse files

SignalStrengthController: validate config value before applying

This cl validates the signal threshold infos read from carrier
config and falls back to default values when validation failed.

It also reports anomaly instead of throwing exception and crashing
phone process when invalid threshold is provided.

Ut cases are also introduced to cover all supported RANs with
measurement types.

Bug: 296292890
Fix: 295567672
Test: atest SignalStrengthControllerTest
Test: Basic phone functionality tests (Activation/call/msg/data...)

Change-Id: I6eb69c58f0bb111e551f20b97596e9502f91c116
parent afb5ac5c
Loading
Loading
Loading
Loading
+59 −9
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.telephony.AccessNetworkConstants;
import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityLte;
@@ -61,6 +62,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.regex.PatternSyntaxException;

@@ -384,9 +386,10 @@ public class SignalStrengthController extends Handler {
                CarrierConfigManager.KEY_GSM_RSSI_THRESHOLDS_INT_ARRAY);
        if (gsmRssiThresholds != null) {
            signalThresholdInfos.add(
                    createSignalThresholdsInfo(
                    validateAndCreateSignalThresholdInfo(
                            SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI,
                            gsmRssiThresholds,
                            AccessNetworkThresholds.GERAN,
                            AccessNetworkConstants.AccessNetworkType.GERAN,
                            true));
        }
@@ -395,9 +398,10 @@ public class SignalStrengthController extends Handler {
                CarrierConfigManager.KEY_WCDMA_RSCP_THRESHOLDS_INT_ARRAY);
        if (wcdmaRscpThresholds != null) {
            signalThresholdInfos.add(
                    createSignalThresholdsInfo(
                    validateAndCreateSignalThresholdInfo(
                            SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSCP,
                            wcdmaRscpThresholds,
                            AccessNetworkThresholds.UTRAN,
                            AccessNetworkConstants.AccessNetworkType.UTRAN,
                            true));
        }
@@ -408,9 +412,10 @@ public class SignalStrengthController extends Handler {
                CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY);
        if (lteRsrpThresholds != null) {
            signalThresholdInfos.add(
                    createSignalThresholdsInfo(
                    validateAndCreateSignalThresholdInfo(
                            SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
                            lteRsrpThresholds,
                            AccessNetworkThresholds.EUTRAN_RSRP,
                            AccessNetworkConstants.AccessNetworkType.EUTRAN,
                            (lteMeasurementEnabled & CellSignalStrengthLte.USE_RSRP) != 0));
        }
@@ -420,9 +425,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_LTE_RSRQ_THRESHOLDS_INT_ARRAY);
            if (lteRsrqThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRQ,
                                lteRsrqThresholds,
                                AccessNetworkThresholds.EUTRAN_RSRQ,
                                AccessNetworkConstants.AccessNetworkType.EUTRAN,
                                (lteMeasurementEnabled & CellSignalStrengthLte.USE_RSRQ) != 0));
            }
@@ -431,9 +437,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_LTE_RSSNR_THRESHOLDS_INT_ARRAY);
            if (lteRssnrThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR,
                                lteRssnrThresholds,
                                AccessNetworkThresholds.EUTRAN_RSSNR,
                                AccessNetworkConstants.AccessNetworkType.EUTRAN,
                                (lteMeasurementEnabled & CellSignalStrengthLte.USE_RSSNR) != 0));
            }
@@ -444,9 +451,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_5G_NR_SSRSRP_THRESHOLDS_INT_ARRAY);
            if (nrSsrsrpThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSRSRP,
                                nrSsrsrpThresholds,
                                AccessNetworkThresholds.NGRAN_SSRSRP,
                                AccessNetworkConstants.AccessNetworkType.NGRAN,
                                (nrMeasurementEnabled & CellSignalStrengthNr.USE_SSRSRP) != 0));
            }
@@ -455,9 +463,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_5G_NR_SSRSRQ_THRESHOLDS_INT_ARRAY);
            if (nrSsrsrqThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSRSRQ,
                                nrSsrsrqThresholds,
                                AccessNetworkThresholds.NGRAN_SSRSRQ,
                                AccessNetworkConstants.AccessNetworkType.NGRAN,
                                (nrMeasurementEnabled & CellSignalStrengthNr.USE_SSRSRQ) != 0));
            }
@@ -466,9 +475,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_5G_NR_SSSINR_THRESHOLDS_INT_ARRAY);
            if (nrSssinrThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSSINR,
                                nrSssinrThresholds,
                                AccessNetworkThresholds.NGRAN_SSSINR,
                                AccessNetworkConstants.AccessNetworkType.NGRAN,
                                (nrMeasurementEnabled & CellSignalStrengthNr.USE_SSSINR) != 0));
            }
@@ -477,9 +487,10 @@ public class SignalStrengthController extends Handler {
                    CarrierConfigManager.KEY_WCDMA_ECNO_THRESHOLDS_INT_ARRAY);
            if (wcdmaEcnoThresholds != null) {
                signalThresholdInfos.add(
                        createSignalThresholdsInfo(
                        validateAndCreateSignalThresholdInfo(
                                SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_ECNO,
                                wcdmaEcnoThresholds,
                                AccessNetworkThresholds.UTRAN_ECNO,
                                AccessNetworkConstants.AccessNetworkType.UTRAN,
                                false));
            }
@@ -1149,6 +1160,45 @@ public class SignalStrengthController extends Handler {
                .build();
    }

    /**
     * Validate the provided signal {@code thresholds} info and fall back to use the
     * {@code defaultThresholds} and report anomaly if invalid to prevent crashing Phone.
     */
    private static SignalThresholdInfo validateAndCreateSignalThresholdInfo(
            int measurementType, @NonNull int[] thresholds, @NonNull int[] defaultThresholds,
            int ran, boolean isEnabled) {
        SignalThresholdInfo signalThresholdInfo;
        try {
            signalThresholdInfo = new SignalThresholdInfo.Builder()
                    .setSignalMeasurementType(measurementType)
                    .setThresholds(thresholds)
                    .setRadioAccessNetworkType(ran)
                    .setIsEnabled(isEnabled)
                    .build();
        // TODO(b/295236831): only catch IAE when phone global exception handler is introduced.
        // Although SignalThresholdInfo only throws IAE for invalid carrier configs, we catch
        // all exception to prevent crashing phone before global exception handler is available.
        } catch (Exception e) {
            signalThresholdInfo = new SignalThresholdInfo.Builder()
                    .setSignalMeasurementType(measurementType)
                    .setThresholds(defaultThresholds)
                    .setRadioAccessNetworkType(ran)
                    .setIsEnabled(isEnabled)
                    .build();

            AnomalyReporter.reportAnomaly(
                    UUID.fromString("28232bc4-78ff-447e-b597-7c054c802407"),
                    "Invalid parameter to generate SignalThresholdInfo: "
                            + "measurementType=" + measurementType
                            + ", thresholds=" + Arrays.toString(thresholds)
                            + ", RAN=" + ran
                            + ", isEnabled=" + isEnabled
                            + ". Replaced with default thresholds: " + Arrays.toString(
                            defaultThresholds));
        }
        return signalThresholdInfo;
    }

    /**
     * dBm thresholds that correspond to changes in signal strength indications.
     */
+257 −0
Original line number Diff line number Diff line
@@ -1012,6 +1012,263 @@ public class SignalStrengthControllerTest extends TelephonyTest {
        assertThat(msgCaptor.getValue().what).isEqualTo(ssChangedEvent);
    }

    @Test
    public void testInvalidCarrierConfig_GERAN_RSSI_arrayIsTooLong() {
        mBundle.putIntArray(CarrierConfigManager.KEY_GSM_RSSI_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -109, /* SIGNAL_STRENGTH_POOR */
                        -103, /* SIGNAL_STRENGTH_MODERATE */
                        -97, /* SIGNAL_STRENGTH_GOOD */
                        -89,  /* SIGNAL_STRENGTH_GREAT */
                        -80, /* and extra value */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_GERAN_RSSI_arrayIsTooShort() {
        mBundle.putIntArray(CarrierConfigManager.KEY_GSM_RSSI_THRESHOLDS_INT_ARRAY,
                new int[]{});
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_GERAN_RSSI_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-113, -51]
        mBundle.putIntArray(CarrierConfigManager.KEY_GSM_RSSI_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -114, /* SIGNAL_STRENGTH_POOR */
                        -103, /* SIGNAL_STRENGTH_MODERATE */
                        -97, /* SIGNAL_STRENGTH_GOOD */
                        -89,  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_GERAN_RSSI_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-113, -51]
        mBundle.putIntArray(CarrierConfigManager.KEY_GSM_RSSI_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -109, /* SIGNAL_STRENGTH_POOR */
                        -103, /* SIGNAL_STRENGTH_MODERATE */
                        -97, /* SIGNAL_STRENGTH_GOOD */
                        -89,  /* SIGNAL_STRENGTH_GREAT */
                        -50, /* and extra value */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_UTRAN_RSCP_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-120, -24]
        mBundle.putIntArray(CarrierConfigManager.KEY_WCDMA_RSCP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -121, /* SIGNAL_STRENGTH_POOR */
                        -104, /* SIGNAL_STRENGTH_MODERATE */
                        -94,  /* SIGNAL_STRENGTH_GOOD */
                        -84   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_UTRAN_RSCP_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-120, -24]
        mBundle.putIntArray(CarrierConfigManager.KEY_WCDMA_RSCP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -114, /* SIGNAL_STRENGTH_POOR */
                        -104, /* SIGNAL_STRENGTH_MODERATE */
                        -94,  /* SIGNAL_STRENGTH_GOOD */
                        -23   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSRP_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-140, -44]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -141, /* SIGNAL_STRENGTH_POOR */
                        -118, /* SIGNAL_STRENGTH_MODERATE */
                        -108, /* SIGNAL_STRENGTH_GOOD */
                        -98,  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSRP_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-140, -44]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -128, /* SIGNAL_STRENGTH_POOR */
                        -118, /* SIGNAL_STRENGTH_MODERATE */
                        -108, /* SIGNAL_STRENGTH_GOOD */
                        -43,  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSRQ_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-34, 3]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRQ_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -35,  /* SIGNAL_STRENGTH_POOR */
                        -17,  /* SIGNAL_STRENGTH_MODERATE */
                        -14,  /* SIGNAL_STRENGTH_GOOD */
                        -11   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSRQ_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-34, 3]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRQ_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -20,  /* SIGNAL_STRENGTH_POOR */
                        -17,  /* SIGNAL_STRENGTH_MODERATE */
                        -14,  /* SIGNAL_STRENGTH_GOOD */
                        4   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSSNR_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-20, 30]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSSNR_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -21,  /* SIGNAL_STRENGTH_POOR */
                        1,   /* SIGNAL_STRENGTH_MODERATE */
                        5,   /* SIGNAL_STRENGTH_GOOD */
                        13   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_EUTRAN_RSSNR_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-20, 30]
        mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSSNR_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -3,  /* SIGNAL_STRENGTH_POOR */
                        1,   /* SIGNAL_STRENGTH_MODERATE */
                        5,   /* SIGNAL_STRENGTH_GOOD */
                        31   /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSRSRP_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-140, -44]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSRSRP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -141, /* SIGNAL_STRENGTH_POOR */
                        -107, /* SIGNAL_STRENGTH_MODERATE */
                        -100, /* SIGNAL_STRENGTH_GOOD */
                        -95,  /* SIGNAL_STRENGTH_GREAT */
                        -90, /* and extra value */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSRSRP_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-140, -44]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSRSRP_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -113, /* SIGNAL_STRENGTH_POOR */
                        -107, /* SIGNAL_STRENGTH_MODERATE */
                        -100, /* SIGNAL_STRENGTH_GOOD */
                        -95,  /* SIGNAL_STRENGTH_GREAT */
                        -45, /* and extra value */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSRSRQ_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-43, 20]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSRSRQ_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -44, /* SIGNAL_STRENGTH_POOR */
                        -19, /* SIGNAL_STRENGTH_MODERATE */
                        -7, /* SIGNAL_STRENGTH_GOOD */
                        6  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSRSRQ_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-43, 20]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSRSRQ_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -31, /* SIGNAL_STRENGTH_POOR */
                        -19, /* SIGNAL_STRENGTH_MODERATE */
                        -7, /* SIGNAL_STRENGTH_GOOD */
                        21  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSSINR_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-23, 40]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSSINR_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -24, /* SIGNAL_STRENGTH_POOR */
                        5, /* SIGNAL_STRENGTH_MODERATE */
                        15, /* SIGNAL_STRENGTH_GOOD */
                        30  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_NGRAN_SSSINR_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-24, 1]
        mBundle.putIntArray(CarrierConfigManager.KEY_WCDMA_ECNO_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -25, /* SIGNAL_STRENGTH_POOR */
                        -14, /* SIGNAL_STRENGTH_MODERATE */
                        -6, /* SIGNAL_STRENGTH_GOOD */
                        1  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_UTRAN_ECNO_thresholdIsTooSmall() {
        // 4 threshold integers must be within the boundaries [-24, 1]
        mBundle.putIntArray(CarrierConfigManager.KEY_WCDMA_ECNO_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -24, /* SIGNAL_STRENGTH_POOR */
                        -14, /* SIGNAL_STRENGTH_MODERATE */
                        -6, /* SIGNAL_STRENGTH_GOOD */
                        2  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    @Test
    public void testInvalidCarrierConfig_UTRAN_ECNO_thresholdIsTooLarge() {
        // 4 threshold integers must be within the boundaries [-23, 40]
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSSINR_THRESHOLDS_INT_ARRAY,
                new int[]{
                        -5, /* SIGNAL_STRENGTH_POOR */
                        5, /* SIGNAL_STRENGTH_MODERATE */
                        15, /* SIGNAL_STRENGTH_GOOD */
                        41  /* SIGNAL_STRENGTH_GREAT */
                });
        sendCarrierConfigUpdate();
    }

    private void verifyAllEmptyThresholdAreDisabledWhenSetSignalStrengthReportingCriteria(
            int expectedNonEmptyThreshold) {
        ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor =