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

Commit 8805703c authored by Manish Dungriyal's avatar Manish Dungriyal Committed by Android (Google) Code Review
Browse files

Merge "Overriding of setHysteresisDb value support"

parents a24abe52 4558b805
Loading
Loading
Loading
Loading
+123 −1
Original line number Diff line number Diff line
@@ -602,12 +602,14 @@ public class SignalStrengthController extends Handler {
                            measurementType,
                            mPhone.getSubId(),
                            mPhone.isDeviceIdle());
            int hysteresisDb = getMinimumHysteresisDb(isEnabledForAppRequest, ran, measurementType,
                    consolidatedThresholds);
            consolidatedSignalThresholdInfos.add(
                    new SignalThresholdInfo.Builder()
                            .setRadioAccessNetworkType(ran)
                            .setSignalMeasurementType(measurementType)
                            .setHysteresisMs(REPORTING_HYSTERESIS_MILLIS)
                            .setHysteresisDb(REPORTING_HYSTERESIS_DB)
                            .setHysteresisDb(hysteresisDb)
                            .setThresholds(consolidatedThresholds, true /*isSystem*/)
                            .setIsEnabled(isEnabledForSystem || isEnabledForAppRequest)
                            .build());
@@ -618,6 +620,126 @@ public class SignalStrengthController extends Handler {
                        + consolidatedSignalThresholdInfos);
    }

    /**
     * Return the minimum hysteresis dB from all available sources:
     * - system default
     * - value set by client through API
     * - threshold delta
     */
    @VisibleForTesting
    public int getMinimumHysteresisDb(boolean isEnabledForAppRequest, int ran, int measurementType,
              final int[] consolidatedThresholdList) {

        int currHysteresisDb = getHysteresisDbFromCarrierConfig(ran, measurementType);

        if (isEnabledForAppRequest) {
            // Get minimum hysteresisDb at api
            int apiHysteresisDb =
                    getHysteresisDbFromSignalThresholdInfoRequests(ran, measurementType);

            // Choose minimum of hysteresisDb between api Vs current system/cc value set
            currHysteresisDb = Math.min(currHysteresisDb, apiHysteresisDb);

            // Hal Req: choose hysteresis db value to be smaller of smallest of threshold delta
            currHysteresisDb =  computeHysteresisDbOnSmallestThresholdDelta(
                    currHysteresisDb, consolidatedThresholdList);
        }
        return currHysteresisDb;
    }

    /**
     * Get the hysteresis db value from Signal Requests
     * Note: Based on the current use case, there does not exist multile App signal threshold info
     * requests with hysteresis db value, so this logic picks the latest hysteresis db value set.
     *
     * TODO(b/262655157): Support Multiple App Hysteresis DB value customisation
     */
    private int getHysteresisDbFromSignalThresholdInfoRequests(
            @AccessNetworkConstants.RadioAccessNetworkType int ran,
            @SignalThresholdInfo.SignalMeasurementType int measurement) {
        int apiHysteresisDb = REPORTING_HYSTERESIS_DB;
        for (SignalRequestRecord record : mSignalRequestRecords) {
            for (SignalThresholdInfo info : record.mRequest.getSignalThresholdInfos()) {
                if (isRanAndSignalMeasurementTypeMatch(ran, measurement, info)) {
                    if (info.getHysteresisDb() >= 0) {
                        apiHysteresisDb = info.getHysteresisDb();
                    }
                }
            }
        }
        return apiHysteresisDb;
    }

    private int getHysteresisDbFromCarrierConfig(int ran, int measurement) {
        int configHysteresisDb = REPORTING_HYSTERESIS_DB;
        String configKey = null;

        switch (ran) {
            case AccessNetworkConstants.AccessNetworkType.GERAN:
                if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI) {
                    configKey = CarrierConfigManager.KEY_GERAN_RSSI_HYSTERESIS_DB_INT;
                }
                break;
            case AccessNetworkConstants.AccessNetworkType.UTRAN:
                if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSCP) {
                    configKey = CarrierConfigManager.KEY_UTRAN_RSCP_HYSTERESIS_DB_INT;
                } else if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_ECNO) {
                    configKey = CarrierConfigManager.KEY_UTRAN_ECNO_HYSTERESIS_DB_INT;
                }
                break;
            case AccessNetworkConstants.AccessNetworkType.EUTRAN:
                if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP) {
                    configKey = CarrierConfigManager.KEY_EUTRAN_RSRP_HYSTERESIS_DB_INT;
                } else if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRQ) {
                    configKey = CarrierConfigManager.KEY_EUTRAN_RSRQ_HYSTERESIS_DB_INT;
                } else if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR) {
                    configKey = CarrierConfigManager.KEY_EUTRAN_RSSNR_HYSTERESIS_DB_INT;
                }
                break;
            case AccessNetworkConstants.AccessNetworkType.NGRAN:
                if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSRSRP) {
                    configKey = CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT;
                } else if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSRSRQ) {
                    configKey = CarrierConfigManager.KEY_NGRAN_SSRSRQ_HYSTERESIS_DB_INT;
                } else if (measurement == SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSSINR) {
                    configKey = CarrierConfigManager.KEY_NGRAN_SSSINR_HYSTERESIS_DB_INT;
                }
                break;
            default:
                localLog("No matching configuration");
        }
        if (configKey != null) {
            configHysteresisDb = mCarrierConfig.getInt(configKey, REPORTING_HYSTERESIS_DB);
        }
        return configHysteresisDb >= SignalThresholdInfo.HYSTERESIS_DB_MINIMUM
                ? configHysteresisDb : REPORTING_HYSTERESIS_DB;
    }

    /**
     * This method computes the hysteresis db value between smaller of the smallest Threshold Delta
     * and system / cc / api hysteresis db value determined.
     *
     * @param currMinHysteresisDb  smaller value between system / cc / api hysteresis db value
     * @param signalThresholdInfoArray consolidated threshold info with App request consolidated.
     * @return current minimum hysteresis db value computed between above params.
     *
     */
    private int computeHysteresisDbOnSmallestThresholdDelta(
            int currMinHysteresisDb, final int[] signalThresholdInfoArray) {
        int index = 0;
        if (signalThresholdInfoArray.length > 1) {
            while (index != signalThresholdInfoArray.length - 1) {
                if (signalThresholdInfoArray[index + 1] - signalThresholdInfoArray[index]
                        < currMinHysteresisDb) {
                    currMinHysteresisDb =
                            signalThresholdInfoArray[index + 1] - signalThresholdInfoArray[index];
                }
                index++;
            }
        }
        return currMinHysteresisDb;
    }

    void setSignalStrengthDefaultValues() {
        mSignalStrength = new SignalStrength();
        mSignalStrengthUpdatedTime = System.currentTimeMillis();
+212 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony;

import static android.telephony.SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP;
import static android.telephony.SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI;
import static android.telephony.SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSRSRP;
import static android.telephony.SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_SSSINR;
import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;

@@ -27,6 +28,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -113,6 +115,7 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                        -97, /* SIGNAL_STRENGTH_GOOD */
                        -89,  /* SIGNAL_STRENGTH_GREAT */
                });
        mBundle.putInt(CarrierConfigManager.KEY_GERAN_RSSI_HYSTERESIS_DB_INT, 6);
        // Support EUTRAN with RSRP
        mBundle.putInt(CarrierConfigManager.KEY_PARAMETERS_USED_FOR_LTE_SIGNAL_BAR_INT,
                1 /* USE_RSRP */);
@@ -123,6 +126,7 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                        -95, /* SIGNAL_STRENGTH_GOOD */
                        -85,  /* SIGNAL_STRENGTH_GREAT */
                });
        mBundle.putInt(CarrierConfigManager.KEY_EUTRAN_RSRP_HYSTERESIS_DB_INT, 3);
        // Support NR with SSRSRP
        mBundle.putInt(CarrierConfigManager.KEY_PARAMETERS_USE_FOR_5G_NR_SIGNAL_BAR_INT,
                1 /* USE_SSRSRP */);
@@ -133,6 +137,7 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                        -80, /* SIGNAL_STRENGTH_GOOD */
                        -64,  /* SIGNAL_STRENGTH_GREAT */
                });
        mBundle.putInt(CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT, 1);
        // By default, NR with SSRSRQ and SSSINR is not supported
        mBundle.putIntArray(CarrierConfigManager.KEY_5G_NR_SSRSRQ_THRESHOLDS_INT_ARRAY,
                new int[] {
@@ -505,6 +510,212 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                CellSignalStrength.SIGNAL_STRENGTH_MODERATE);
    }

    @Test
    public void testSetMinimumHysteresisDb_FromThresholdDelta() {
        final int[] consolidatedThresholdList = new int[] {-120, -116, -113, -112};

        SignalThresholdInfo info =
                new SignalThresholdInfo.Builder()
                        .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.GERAN)
                        .setSignalMeasurementType(SIGNAL_MEASUREMENT_TYPE_RSSI)
                        .setThresholds(new int[] {-113}, true)
                        .setHysteresisDb(2)
                        .build();
        SignalStrengthUpdateRequest request =
                createTestSignalStrengthUpdateRequest(
                        info,
                        false /* shouldReportWhileIdle*/,
                        false /* shouldReportSystemWhileIdle */);
        mSsc.setSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();

        int minHysteresis =
                mSsc.getMinimumHysteresisDb(true,
                        AccessNetworkConstants.AccessNetworkType.GERAN,
                        SIGNAL_MEASUREMENT_TYPE_RSSI,
                        consolidatedThresholdList);
        assertEquals(1, minHysteresis);
        mSsc.clearSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();
    }

    @Test
    public void testSetMinimumHysteresisDb_FromSignalThresholdRequest() {
        final int[] consolidatedThresholdList = new int[] {-120, -116, -112, -108};

        SignalThresholdInfo info =
                new SignalThresholdInfo.Builder()
                        .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.EUTRAN)
                        .setSignalMeasurementType(SIGNAL_MEASUREMENT_TYPE_RSRP)
                        .setThresholds(new int[] {-113}, true)
                        .setHysteresisDb(3)
                        .build();
        SignalStrengthUpdateRequest request =
                createTestSignalStrengthUpdateRequest(
                        info,
                        false /* shouldReportWhileIdle*/,
                        false /* shouldReportSystemWhileIdle */);
        mSsc.setSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();

        int minHysteresis =
                mSsc.getMinimumHysteresisDb(true,
                        AccessNetworkConstants.AccessNetworkType.EUTRAN,
                        SIGNAL_MEASUREMENT_TYPE_RSRP,
                        consolidatedThresholdList);
        assertEquals(3, minHysteresis);

        mSsc.clearSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();
    }

    @Test
    public void testSetMinimumHysteresisDb_FromCarrierConfig() {
        final int[] consolidatedThresholdList = new int[] {-120, -115, -108, -103};

        SignalThresholdInfo info =
                new SignalThresholdInfo.Builder()
                        .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.NGRAN)
                        .setSignalMeasurementType(SIGNAL_MEASUREMENT_TYPE_SSRSRP)
                        .setThresholds(new int[] {-113}, true)
                        .setHysteresisDb(6)
                        .build();
        SignalStrengthUpdateRequest request =
                createTestSignalStrengthUpdateRequest(
                        info,
                        false /* shouldReportWhileIdle*/,
                        false /* shouldReportSystemWhileIdle */);
        mSsc.setSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();

        int minHysteresis =
                mSsc.getMinimumHysteresisDb(true,
                        AccessNetworkConstants.AccessNetworkType.NGRAN,
                        SIGNAL_MEASUREMENT_TYPE_SSRSRP,
                        consolidatedThresholdList);
        assertEquals(1, minHysteresis);
        mSsc.clearSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();
    }

    @Test
    public void testSetHysteresisDb_WithCarrierConfigValue() {
        when(mPhone.isDeviceIdle()).thenReturn(true);
        when(mPhone.getSubId()).thenReturn(ACTIVE_SUB_ID);

        mBundle.putInt(CarrierConfigManager.KEY_GERAN_RSSI_HYSTERESIS_DB_INT, 5);
        mBundle.putInt(CarrierConfigManager.KEY_EUTRAN_RSRP_HYSTERESIS_DB_INT, 3);
        mBundle.putInt(CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT, 2);
        sendCarrierConfigUpdate();

        ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor =
                ArgumentCaptor.forClass(List.class);
        verify(mSimulatedCommandsVerifier, atLeastOnce())
                .setSignalStrengthReportingCriteria(signalThresholdInfoCaptor.capture(), isNull());
        List<SignalThresholdInfo> capturedInfos = signalThresholdInfoCaptor.getAllValues().get(0);
        assertThat(capturedInfos).isNotEmpty();

        for (SignalThresholdInfo signalThresholdInfo : capturedInfos) {
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_RSRP) {
                assertEquals(3, signalThresholdInfo.getHysteresisDb());
            }
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_RSSI) {
                assertEquals(5, signalThresholdInfo.getHysteresisDb());
            }
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_SSRSRP) {
                assertEquals(2, signalThresholdInfo.getHysteresisDb());
            }
        }
        reset(mSimulatedCommandsVerifier);
    }

    @Test
    public void testSetHysteresisDb_BetweenCarrierConfigSignalThresholdInfoThresholdDelta() {
        SignalThresholdInfo info =
                new SignalThresholdInfo.Builder()
                        .setRadioAccessNetworkType(AccessNetworkConstants.AccessNetworkType.NGRAN)
                        .setSignalMeasurementType(SIGNAL_MEASUREMENT_TYPE_SSRSRP)
                        .setThresholds(new int[] {-116}, true)
                        .setHysteresisDb(3)
                        .build();
        SignalStrengthUpdateRequest request =
                createTestSignalStrengthUpdateRequest(
                        info,
                        false /* shouldReportWhileIdle*/,
                        false /* shouldReportSystemWhileIdle */);
        mSsc.setSignalStrengthUpdateRequest(
                ACTIVE_SUB_ID, CALLING_UID, request, Message.obtain(mHandler));
        processAllMessages();

        reset(mSimulatedCommandsVerifier);
        when(mPhone.isDeviceIdle()).thenReturn(false);
        when(mPhone.getSubId()).thenReturn(ACTIVE_SUB_ID);
        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 */
                });

        mBundle.putInt(CarrierConfigManager.KEY_PARAMETERS_USE_FOR_5G_NR_SIGNAL_BAR_INT,
                1 /* USE_SSRSRP */);
        mBundle.putInt(CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT, 4);
        sendCarrierConfigUpdate();

        ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor =
                ArgumentCaptor.forClass(List.class);
        verify(mSimulatedCommandsVerifier, atLeastOnce())
                .setSignalStrengthReportingCriteria(signalThresholdInfoCaptor.capture(), isNull());
        List<SignalThresholdInfo> capturedInfos = signalThresholdInfoCaptor.getAllValues().get(0);
        assertThat(capturedInfos).isNotEmpty();

        for (SignalThresholdInfo signalThresholdInfo : capturedInfos) {
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_SSRSRP) {
                assertEquals(4,
                        mBundle.getInt(CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT));
                assertEquals(3, signalThresholdInfo.getHysteresisDb());
            }
        }
    }

    @Test
    public void testSetHysteresisDb_WithInvalidCarrierConfigValue() {
        when(mPhone.isDeviceIdle()).thenReturn(true);
        when(mPhone.getSubId()).thenReturn(ACTIVE_SUB_ID);

        mBundle.putInt(CarrierConfigManager.KEY_GERAN_RSSI_HYSTERESIS_DB_INT, -4);
        mBundle.putInt(CarrierConfigManager.KEY_EUTRAN_RSRP_HYSTERESIS_DB_INT, -5);
        mBundle.putInt(CarrierConfigManager.KEY_NGRAN_SSRSRP_HYSTERESIS_DB_INT, -2);
        sendCarrierConfigUpdate();

        ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor =
                ArgumentCaptor.forClass(List.class);
        verify(mSimulatedCommandsVerifier, atLeastOnce())
                .setSignalStrengthReportingCriteria(signalThresholdInfoCaptor.capture(), isNull());
        List<SignalThresholdInfo> capturedInfos = signalThresholdInfoCaptor.getAllValues().get(0);
        assertThat(capturedInfos).isNotEmpty();

        for (SignalThresholdInfo signalThresholdInfo : capturedInfos) {
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_RSRP) {
                assertEquals(2, signalThresholdInfo.getHysteresisDb());
            }
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_RSSI) {
                assertEquals(2, signalThresholdInfo.getHysteresisDb());
            }
            if (signalThresholdInfo.getSignalMeasurementType() == SIGNAL_MEASUREMENT_TYPE_SSRSRP) {
                assertEquals(2, signalThresholdInfo.getHysteresisDb());
            }
        }
        reset(mSimulatedCommandsVerifier);
    }

    @Test
    public void testLteSignalStrengthReportingCriteria_convertRssnrUnitFromTenDbToDB() {
        SignalStrength ss = new SignalStrength(
+49 −10

File changed.

Preview size limit exceeded, changes collapsed.