Loading src/java/com/android/internal/telephony/SignalStrengthController.java +41 −6 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.PatternSyntaxException; /** Loading Loading @@ -101,6 +102,7 @@ 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_SERVICE_STATE_CHANGED = 10; @NonNull private final Phone mPhone; Loading Loading @@ -146,6 +148,8 @@ public class SignalStrengthController extends Handler { @NonNull private final LocalLog mLocalLog = new LocalLog(64); private final AtomicBoolean mNTNConnected = new AtomicBoolean(false); public SignalStrengthController(@NonNull Phone phone) { mPhone = phone; mCi = mPhone.mCi; Loading @@ -161,6 +165,8 @@ public class SignalStrengthController extends Handler { ccm.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> onCarrierConfigurationChanged(slotIndex)); mPhone.registerForServiceStateChanged(this, EVENT_SERVICE_STATE_CHANGED, null); } @Override Loading Loading @@ -273,6 +279,11 @@ public class SignalStrengthController extends Handler { break; } case EVENT_SERVICE_STATE_CHANGED: { onServiceStateChanged((ServiceState) ((AsyncResult) msg.obj).result); break; } default: log("Unhandled message with number: " + msg.what); break; Loading Loading @@ -406,10 +417,13 @@ public class SignalStrengthController extends Handler { true)); } int lteMeasurementEnabled = mCarrierConfig.getInt(CarrierConfigManager .KEY_PARAMETERS_USED_FOR_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); int[] lteRsrpThresholds = mCarrierConfig.getIntArray( CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY); int lteMeasurementEnabled = mCarrierConfig.getInt(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_PARAMETERS_USED_FOR_NTN_LTE_SIGNAL_BAR_INT : CarrierConfigManager.KEY_PARAMETERS_USED_FOR_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); int[] lteRsrpThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY); if (lteRsrpThresholds != null) { signalThresholdInfos.add( validateAndCreateSignalThresholdInfo( Loading @@ -421,7 +435,8 @@ public class SignalStrengthController extends Handler { } if (mPhone.getHalVersion(HAL_SERVICE_NETWORK).greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { int[] lteRsrqThresholds = mCarrierConfig.getIntArray( int[] lteRsrqThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSRQ_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSRQ_THRESHOLDS_INT_ARRAY); if (lteRsrqThresholds != null) { signalThresholdInfos.add( Loading @@ -433,7 +448,8 @@ public class SignalStrengthController extends Handler { (lteMeasurementEnabled & CellSignalStrengthLte.USE_RSRQ) != 0)); } int[] lteRssnrThresholds = mCarrierConfig.getIntArray( int[] lteRssnrThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSSNR_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSSNR_THRESHOLDS_INT_ARRAY); if (lteRssnrThresholds != null) { signalThresholdInfos.add( Loading Loading @@ -1322,6 +1338,25 @@ public class SignalStrengthController extends Handler { }; } private void onServiceStateChanged(ServiceState state) { if (state.getState() != ServiceState.STATE_IN_SERVICE) { return; } if (mNTNConnected.get() != state.isUsingNonTerrestrialNetwork()) { log("onServiceStateChanged: update it to " + state.isUsingNonTerrestrialNetwork()); updateReportingCriteria(); mNTNConnected.set(state.isUsingNonTerrestrialNetwork()); } } private boolean isUsingNonTerrestrialNetwork() { if (mPhone.getServiceState() == null) { return false; } return mPhone.getServiceState().isUsingNonTerrestrialNetwork(); } private static void log(String msg) { if (DBG) Rlog.d(TAG, msg); } Loading tests/telephonytests/src/com/android/internal/telephony/SignalStrengthControllerTest.java +240 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.internal.telephony; import static android.telephony.ServiceState.STATE_IN_SERVICE; import static android.telephony.ServiceState.STATE_OUT_OF_SERVICE; import static android.telephony.ServiceState.STATE_POWER_OFF; 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; Loading @@ -27,14 +30,19 @@ 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.anyList; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.os.AsyncResult; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; Loading Loading @@ -1269,6 +1277,238 @@ public class SignalStrengthControllerTest extends TelephonyTest { sendCarrierConfigUpdate(); } @Test public void testInvalidCarrierConfig_NTN_LTE_RSRP_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-140, -44] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSRP_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-140, -44] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRQ_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_NTN_LTE_RSRQ_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-34, 3] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSRQ_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-34, 3] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSSNR_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-20, 30] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSSNR_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-20, 30] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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 testLteSignalStrengthReportingCriteriaWhenServiceStateChanged() { SignalStrength ss = new SignalStrength( new CellSignalStrengthCdma(), new CellSignalStrengthGsm(), new CellSignalStrengthWcdma(), new CellSignalStrengthTdscdma(), new CellSignalStrengthLte( -110, /* rssi */ -114, /* rsrp */ -5, /* rsrq */ 0, /* rssnr */ SignalStrength.INVALID, /* cqi */ SignalStrength.INVALID /* ta */), new CellSignalStrengthNr()); // RSRP NTN_LTE threshold set to Good and LTE threshold set to poor. mBundle.putInt(CarrierConfigManager.KEY_PARAMETERS_USED_FOR_NTN_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-125 /* SIGNAL_STRENGTH_POOR */, -120 /* SIGNAL_STRENGTH_MODERATE */, -115 /* SIGNAL_STRENGTH_GOOD */, -110/* SIGNAL_STRENGTH_GREAT */}); mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-114, /* SIGNAL_STRENGTH_POOR */ -110, /* SIGNAL_STRENGTH_MODERATE */ -105, /* SIGNAL_STRENGTH_GOOD */ -100, /* SIGNAL_STRENGTH_GREAT */}); CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class); when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) .thenReturn(mockConfigManager); when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); // When NTN is connected, check the signal strength is GOOD AsyncResult asyncResult = mock(AsyncResult.class); asyncResult.result = mServiceState; doReturn(true).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_GOOD, mSsc.getSignalStrength().getLevel()); // When TN connected, check the signal strength is POOR doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); // RSRP NTN_LTE threshold set to Moderate and LTE threshold set to poor. // When TN connected, check the signal strength is POOR. mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-130 /* SIGNAL_STRENGTH_POOR */, -120 /* SIGNAL_STRENGTH_MODERATE */, -110 /* SIGNAL_STRENGTH_GOOD */, -100/* SIGNAL_STRENGTH_GREAT */}); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); // Service State Changed with OUT_OF_SERVICE, then no update // SignalStrengthReportingCriteria. reset(mSimulatedCommandsVerifier); doReturn(STATE_OUT_OF_SERVICE).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with POWER_OFF, then no update SignalStrengthReportingCriteria. reset(mSimulatedCommandsVerifier); doReturn(STATE_POWER_OFF).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE, then update SignalStrengthReportingCriteria. // When NTN is connected, check the signal strength is MODERATE reset(mSimulatedCommandsVerifier); doReturn(true).when(mServiceState).isUsingNonTerrestrialNetwork(); doReturn(STATE_IN_SERVICE).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_MODERATE, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE and still NTN is connected, // verify not update SignalStrengthReportingCriteria and the signal strength is MODERATE. reset(mSimulatedCommandsVerifier); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_MODERATE, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE, then update SignalStrengthReportingCriteria. // When TN is connected, check the signal strength is POOR. reset(mSimulatedCommandsVerifier); doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE and still TN is connected, // verify not update SignalStrengthReportingCriteria and the signal strength is POOR. reset(mSimulatedCommandsVerifier); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); reset(mSimulatedCommandsVerifier); } private void verifyAllEmptyThresholdAreDisabledWhenSetSignalStrengthReportingCriteria( int expectedNonEmptyThreshold) { ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor = Loading tests/telephonytests/src/com/android/internal/telephony/SignalStrengthTest.java +532 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/java/com/android/internal/telephony/SignalStrengthController.java +41 −6 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.PatternSyntaxException; /** Loading Loading @@ -101,6 +102,7 @@ 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_SERVICE_STATE_CHANGED = 10; @NonNull private final Phone mPhone; Loading Loading @@ -146,6 +148,8 @@ public class SignalStrengthController extends Handler { @NonNull private final LocalLog mLocalLog = new LocalLog(64); private final AtomicBoolean mNTNConnected = new AtomicBoolean(false); public SignalStrengthController(@NonNull Phone phone) { mPhone = phone; mCi = mPhone.mCi; Loading @@ -161,6 +165,8 @@ public class SignalStrengthController extends Handler { ccm.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> onCarrierConfigurationChanged(slotIndex)); mPhone.registerForServiceStateChanged(this, EVENT_SERVICE_STATE_CHANGED, null); } @Override Loading Loading @@ -273,6 +279,11 @@ public class SignalStrengthController extends Handler { break; } case EVENT_SERVICE_STATE_CHANGED: { onServiceStateChanged((ServiceState) ((AsyncResult) msg.obj).result); break; } default: log("Unhandled message with number: " + msg.what); break; Loading Loading @@ -406,10 +417,13 @@ public class SignalStrengthController extends Handler { true)); } int lteMeasurementEnabled = mCarrierConfig.getInt(CarrierConfigManager .KEY_PARAMETERS_USED_FOR_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); int[] lteRsrpThresholds = mCarrierConfig.getIntArray( CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY); int lteMeasurementEnabled = mCarrierConfig.getInt(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_PARAMETERS_USED_FOR_NTN_LTE_SIGNAL_BAR_INT : CarrierConfigManager.KEY_PARAMETERS_USED_FOR_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); int[] lteRsrpThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY); if (lteRsrpThresholds != null) { signalThresholdInfos.add( validateAndCreateSignalThresholdInfo( Loading @@ -421,7 +435,8 @@ public class SignalStrengthController extends Handler { } if (mPhone.getHalVersion(HAL_SERVICE_NETWORK).greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { int[] lteRsrqThresholds = mCarrierConfig.getIntArray( int[] lteRsrqThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSRQ_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSRQ_THRESHOLDS_INT_ARRAY); if (lteRsrqThresholds != null) { signalThresholdInfos.add( Loading @@ -433,7 +448,8 @@ public class SignalStrengthController extends Handler { (lteMeasurementEnabled & CellSignalStrengthLte.USE_RSRQ) != 0)); } int[] lteRssnrThresholds = mCarrierConfig.getIntArray( int[] lteRssnrThresholds = mCarrierConfig.getIntArray(isUsingNonTerrestrialNetwork() ? CarrierConfigManager.KEY_NTN_LTE_RSSNR_THRESHOLDS_INT_ARRAY : CarrierConfigManager.KEY_LTE_RSSNR_THRESHOLDS_INT_ARRAY); if (lteRssnrThresholds != null) { signalThresholdInfos.add( Loading Loading @@ -1322,6 +1338,25 @@ public class SignalStrengthController extends Handler { }; } private void onServiceStateChanged(ServiceState state) { if (state.getState() != ServiceState.STATE_IN_SERVICE) { return; } if (mNTNConnected.get() != state.isUsingNonTerrestrialNetwork()) { log("onServiceStateChanged: update it to " + state.isUsingNonTerrestrialNetwork()); updateReportingCriteria(); mNTNConnected.set(state.isUsingNonTerrestrialNetwork()); } } private boolean isUsingNonTerrestrialNetwork() { if (mPhone.getServiceState() == null) { return false; } return mPhone.getServiceState().isUsingNonTerrestrialNetwork(); } private static void log(String msg) { if (DBG) Rlog.d(TAG, msg); } Loading
tests/telephonytests/src/com/android/internal/telephony/SignalStrengthControllerTest.java +240 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.internal.telephony; import static android.telephony.ServiceState.STATE_IN_SERVICE; import static android.telephony.ServiceState.STATE_OUT_OF_SERVICE; import static android.telephony.ServiceState.STATE_POWER_OFF; 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; Loading @@ -27,14 +30,19 @@ 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.anyList; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.os.AsyncResult; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; Loading Loading @@ -1269,6 +1277,238 @@ public class SignalStrengthControllerTest extends TelephonyTest { sendCarrierConfigUpdate(); } @Test public void testInvalidCarrierConfig_NTN_LTE_RSRP_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-140, -44] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSRP_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-140, -44] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRQ_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_NTN_LTE_RSRQ_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-34, 3] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSRQ_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-34, 3] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSSNR_thresholdIsTooSmall() { // 4 threshold integers must be within the boundaries [-20, 30] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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_NTN_LTE_RSSNR_thresholdIsTooLarge() { // 4 threshold integers must be within the boundaries [-20, 30] mBundle.putIntArray(CarrierConfigManager.KEY_NTN_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 testLteSignalStrengthReportingCriteriaWhenServiceStateChanged() { SignalStrength ss = new SignalStrength( new CellSignalStrengthCdma(), new CellSignalStrengthGsm(), new CellSignalStrengthWcdma(), new CellSignalStrengthTdscdma(), new CellSignalStrengthLte( -110, /* rssi */ -114, /* rsrp */ -5, /* rsrq */ 0, /* rssnr */ SignalStrength.INVALID, /* cqi */ SignalStrength.INVALID /* ta */), new CellSignalStrengthNr()); // RSRP NTN_LTE threshold set to Good and LTE threshold set to poor. mBundle.putInt(CarrierConfigManager.KEY_PARAMETERS_USED_FOR_NTN_LTE_SIGNAL_BAR_INT, CellSignalStrengthLte.USE_RSRP); mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-125 /* SIGNAL_STRENGTH_POOR */, -120 /* SIGNAL_STRENGTH_MODERATE */, -115 /* SIGNAL_STRENGTH_GOOD */, -110/* SIGNAL_STRENGTH_GREAT */}); mBundle.putIntArray(CarrierConfigManager.KEY_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-114, /* SIGNAL_STRENGTH_POOR */ -110, /* SIGNAL_STRENGTH_MODERATE */ -105, /* SIGNAL_STRENGTH_GOOD */ -100, /* SIGNAL_STRENGTH_GREAT */}); CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class); when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) .thenReturn(mockConfigManager); when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); // When NTN is connected, check the signal strength is GOOD AsyncResult asyncResult = mock(AsyncResult.class); asyncResult.result = mServiceState; doReturn(true).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_GOOD, mSsc.getSignalStrength().getLevel()); // When TN connected, check the signal strength is POOR doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); // RSRP NTN_LTE threshold set to Moderate and LTE threshold set to poor. // When TN connected, check the signal strength is POOR. mBundle.putIntArray(CarrierConfigManager.KEY_NTN_LTE_RSRP_THRESHOLDS_INT_ARRAY, new int[]{-130 /* SIGNAL_STRENGTH_POOR */, -120 /* SIGNAL_STRENGTH_MODERATE */, -110 /* SIGNAL_STRENGTH_GOOD */, -100/* SIGNAL_STRENGTH_GREAT */}); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); // Service State Changed with OUT_OF_SERVICE, then no update // SignalStrengthReportingCriteria. reset(mSimulatedCommandsVerifier); doReturn(STATE_OUT_OF_SERVICE).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with POWER_OFF, then no update SignalStrengthReportingCriteria. reset(mSimulatedCommandsVerifier); doReturn(STATE_POWER_OFF).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE, then update SignalStrengthReportingCriteria. // When NTN is connected, check the signal strength is MODERATE reset(mSimulatedCommandsVerifier); doReturn(true).when(mServiceState).isUsingNonTerrestrialNetwork(); doReturn(STATE_IN_SERVICE).when(mServiceState).getState(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_MODERATE, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE and still NTN is connected, // verify not update SignalStrengthReportingCriteria and the signal strength is MODERATE. reset(mSimulatedCommandsVerifier); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_MODERATE, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE, then update SignalStrengthReportingCriteria. // When TN is connected, check the signal strength is POOR. reset(mSimulatedCommandsVerifier); doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier).setSignalStrengthReportingCriteria(anyList(), isNull()); // Service State Changed with IN_SERVICE and still TN is connected, // verify not update SignalStrengthReportingCriteria and the signal strength is POOR. reset(mSimulatedCommandsVerifier); mSsc.handleMessage(mSsc.obtainMessage(10/*EVENT_SERVICE_STATE_CHANGED*/, asyncResult)); processAllMessages(); mSimulatedCommands.setSignalStrength(ss); mSimulatedCommands.notifySignalStrength(); processAllMessages(); assertEquals(CellSignalStrength.SIGNAL_STRENGTH_POOR, mSsc.getSignalStrength().getLevel()); verify(mSimulatedCommandsVerifier, never()).setSignalStrengthReportingCriteria(anyList(), isNull()); reset(mSimulatedCommandsVerifier); } private void verifyAllEmptyThresholdAreDisabledWhenSetSignalStrengthReportingCriteria( int expectedNonEmptyThreshold) { ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor = Loading
tests/telephonytests/src/com/android/internal/telephony/SignalStrengthTest.java +532 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes