Refactor signal strength in SIM status
- Move data logic into repository for better testing - Check carrier config first, if not shows some items, we don't need to load data - Tests in SimStatusDialogControllerTest will be fixed in later cls Bug: 337417520 Test: manual - on SIM status Test: unit test Change-Id: Iccd209fd455d66d4f6438652ee7481d2a0e72a99
This commit is contained in:
@@ -28,25 +28,18 @@ import static com.android.settings.deviceinfo.simstatus.SimStatusDialogControlle
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.OPERATOR_INFO_VALUE_ID;
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ROAMING_INFO_VALUE_ID;
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SERVICE_STATE_VALUE_ID;
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_LABEL_ID;
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_VALUE_ID;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.CellSignalStrength;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -70,7 +63,6 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -86,14 +78,6 @@ public class SimStatusDialogControllerTest {
|
||||
@Mock
|
||||
private ServiceState mServiceState;
|
||||
@Mock
|
||||
private SignalStrength mSignalStrength;
|
||||
@Mock
|
||||
private CellSignalStrength mCellSignalStrengthCdma;
|
||||
@Mock
|
||||
private CellSignalStrength mCellSignalStrengthLte;
|
||||
@Mock
|
||||
private CellSignalStrength mCellSignalStrengthWcdma;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private PersistableBundle mPersistableBundle;
|
||||
@Mock
|
||||
@@ -148,15 +132,6 @@ public class SimStatusDialogControllerTest {
|
||||
mUpdatePhoneNumberCount.incrementAndGet();
|
||||
}
|
||||
};
|
||||
// CellSignalStrength setup
|
||||
doReturn(0).when(mCellSignalStrengthCdma).getDbm();
|
||||
doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
|
||||
doReturn(0).when(mCellSignalStrengthLte).getDbm();
|
||||
doReturn(0).when(mCellSignalStrengthLte).getAsuLevel();
|
||||
doReturn(0).when(mCellSignalStrengthWcdma).getDbm();
|
||||
doReturn(0).when(mCellSignalStrengthWcdma).getAsuLevel();
|
||||
|
||||
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
|
||||
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
||||
|
||||
when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
|
||||
@@ -171,10 +146,7 @@ public class SimStatusDialogControllerTest {
|
||||
mPersistableBundle = new PersistableBundle();
|
||||
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mPersistableBundle);
|
||||
|
||||
mPersistableBundle.putBoolean(
|
||||
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL, true);
|
||||
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
||||
doReturn(mSignalStrength).when(mTelephonyManager).getSignalStrength();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,7 +189,7 @@ public class SimStatusDialogControllerTest {
|
||||
|
||||
@Test
|
||||
@Ignore("b/337417520")
|
||||
public void initialize_updateServiceStateWithPowerOff_shouldUpdateTextAndResetSignalStrength() {
|
||||
public void initialize_updateServiceStateWithPowerOff_shouldUpdateText() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
|
||||
|
||||
mController.initialize();
|
||||
@@ -225,12 +197,11 @@ public class SimStatusDialogControllerTest {
|
||||
final String offServiceText = ResourcesUtils.getResourcesString(
|
||||
mContext, "radioInfo_service_off");
|
||||
verify(mDialog).setText(SERVICE_STATE_VALUE_ID, offServiceText);
|
||||
verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/337417520")
|
||||
public void initialize_updateVoiceDataOutOfService_shouldUpdateSettingAndResetSignalStrength() {
|
||||
public void initialize_updateVoiceDataOutOfService_shouldUpdateSetting() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||
when(mServiceState.getDataRegistrationState()).thenReturn(
|
||||
ServiceState.STATE_OUT_OF_SERVICE);
|
||||
@@ -240,7 +211,6 @@ public class SimStatusDialogControllerTest {
|
||||
final String offServiceText = ResourcesUtils.getResourcesString(
|
||||
mContext, "radioInfo_service_out");
|
||||
verify(mDialog).setText(SERVICE_STATE_VALUE_ID, offServiceText);
|
||||
verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,52 +225,6 @@ public class SimStatusDialogControllerTest {
|
||||
verify(mDialog).setText(SERVICE_STATE_VALUE_ID, inServiceText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_updateSignalStrengthWithLte50Wcdma40_shouldUpdateSignalStrengthTo50() {
|
||||
final int lteDbm = 50;
|
||||
final int lteAsu = 50;
|
||||
final int wcdmaDbm = 40;
|
||||
final int wcdmaAsu = 40;
|
||||
setupCellSignalStrength_lteWcdma(lteDbm, lteAsu, wcdmaDbm, wcdmaAsu);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
final String signalStrengthString = ResourcesUtils.getResourcesString(
|
||||
mContext, "sim_signal_strength", lteDbm, lteAsu);
|
||||
verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_updateSignalStrengthWithLte50Cdma30_shouldUpdateSignalStrengthTo50() {
|
||||
final int lteDbm = 50;
|
||||
final int lteAsu = 50;
|
||||
final int cdmaDbm = 30;
|
||||
final int cdmaAsu = 30;
|
||||
setupCellSignalStrength_lteCdma(lteDbm, lteAsu, cdmaDbm, cdmaAsu);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
final String signalStrengthString = ResourcesUtils.getResourcesString(
|
||||
mContext, "sim_signal_strength", lteDbm, lteAsu);
|
||||
verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_updateVoiceOutOfServiceDataInService_shouldUpdateSignalStrengthTo50() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||
when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||
|
||||
final int lteDbm = 50;
|
||||
final int lteAsu = 50;
|
||||
setupCellSignalStrength_lteOnly(lteDbm, lteAsu);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
final String signalStrengthString = ResourcesUtils.getResourcesString(
|
||||
mContext, "sim_signal_strength", lteDbm, lteAsu);
|
||||
verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_updateVoiceNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
|
||||
when(mTelephonyManager.getVoiceNetworkType()).thenReturn(
|
||||
@@ -356,17 +280,6 @@ public class SimStatusDialogControllerTest {
|
||||
verify(mDialog).removeSettingFromScreen(ICCID_INFO_VALUE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_doNotShowSignalStrength_shouldRemoveSignalStrengthSetting() {
|
||||
mPersistableBundle.putBoolean(
|
||||
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL, false);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_LABEL_ID);
|
||||
verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_VALUE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_showSignalStrengthAndIccId_shouldShowSignalStrengthAndIccIdSetting() {
|
||||
// getConfigForSubId is nullable, so make sure the default behavior is correct
|
||||
@@ -374,7 +287,6 @@ public class SimStatusDialogControllerTest {
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog, times(2)).setText(eq(SIGNAL_STRENGTH_VALUE_ID), any());
|
||||
verify(mDialog).removeSettingFromScreen(ICCID_INFO_LABEL_ID);
|
||||
verify(mDialog).removeSettingFromScreen(ICCID_INFO_VALUE_ID);
|
||||
}
|
||||
@@ -428,48 +340,4 @@ public class SimStatusDialogControllerTest {
|
||||
verify(mDialog).setSettingVisibility(IMS_REGISTRATION_STATE_LABEL_ID, false);
|
||||
verify(mDialog).setSettingVisibility(IMS_REGISTRATION_STATE_VALUE_ID, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_nullSignalStrength_noCrash() {
|
||||
doReturn(null).when(mTelephonyManager).getSignalStrength();
|
||||
// we should not crash when running the following line
|
||||
mController.initialize();
|
||||
}
|
||||
|
||||
private void setupCellSignalStrength_lteWcdma(int lteDbm, int lteAsu, int wcdmaDbm,
|
||||
int wcdmaAsu) {
|
||||
doReturn(lteDbm).when(mCellSignalStrengthLte).getDbm();
|
||||
doReturn(lteAsu).when(mCellSignalStrengthLte).getAsuLevel();
|
||||
doReturn(wcdmaDbm).when(mCellSignalStrengthWcdma).getDbm();
|
||||
doReturn(wcdmaAsu).when(mCellSignalStrengthWcdma).getAsuLevel();
|
||||
|
||||
List<CellSignalStrength> cellSignalStrengthList = new ArrayList<>(2);
|
||||
cellSignalStrengthList.add(mCellSignalStrengthLte);
|
||||
cellSignalStrengthList.add(mCellSignalStrengthWcdma);
|
||||
|
||||
doReturn(cellSignalStrengthList).when(mSignalStrength).getCellSignalStrengths();
|
||||
}
|
||||
|
||||
private void setupCellSignalStrength_lteCdma(int lteDbm, int lteAsu, int cdmaDbm, int cdmaAsu) {
|
||||
doReturn(lteDbm).when(mCellSignalStrengthLte).getDbm();
|
||||
doReturn(lteAsu).when(mCellSignalStrengthLte).getAsuLevel();
|
||||
doReturn(cdmaDbm).when(mCellSignalStrengthCdma).getDbm();
|
||||
doReturn(cdmaAsu).when(mCellSignalStrengthCdma).getAsuLevel();
|
||||
|
||||
List<CellSignalStrength> cellSignalStrengthList = new ArrayList<>(2);
|
||||
cellSignalStrengthList.add(mCellSignalStrengthLte);
|
||||
cellSignalStrengthList.add(mCellSignalStrengthCdma);
|
||||
|
||||
doReturn(cellSignalStrengthList).when(mSignalStrength).getCellSignalStrengths();
|
||||
}
|
||||
|
||||
private void setupCellSignalStrength_lteOnly(int lteDbm, int lteAsu) {
|
||||
doReturn(lteDbm).when(mCellSignalStrengthLte).getDbm();
|
||||
doReturn(lteAsu).when(mCellSignalStrengthLte).getAsuLevel();
|
||||
|
||||
List<CellSignalStrength> cellSignalStrengthList = new ArrayList<>(2);
|
||||
cellSignalStrengthList.add(mCellSignalStrengthLte);
|
||||
|
||||
doReturn(cellSignalStrengthList).when(mSignalStrength).getCellSignalStrengths();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user