Merge "Fix IMEI information can't display without pSIM inserted" into qt-dev

This commit is contained in:
Andy Chou
2019-05-14 03:32:26 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 4 deletions

View File

@@ -78,9 +78,12 @@ public class ImeiInfoDialogController {
final Context context = dialog.getContext();
mSubscriptionInfo = context.getSystemService(SubscriptionManager.class)
.getActiveSubscriptionInfoForSimSlotIndex(slotId);
TelephonyManager tm = context.getSystemService(TelephonyManager.class);
if (mSubscriptionInfo != null) {
mTelephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId());
} else if(isValidSlotIndex(slotId, tm)) {
mTelephonyManager = tm;
} else {
mTelephonyManager = null;
}
@@ -104,6 +107,7 @@ public class ImeiInfoDialogController {
private void updateDialogForCdmaPhone() {
final Resources res = mDialog.getContext().getResources();
mDialog.setText(ID_MEID_NUMBER_VALUE, getMeid());
// MIN needs to read from SIM. So if no SIM, we should not show MIN on UI
mDialog.setText(ID_MIN_NUMBER_VALUE, mSubscriptionInfo != null
? mTelephonyManager.getCdmaMin(mSubscriptionInfo.getSubscriptionId())
: "");
@@ -137,7 +141,8 @@ public class ImeiInfoDialogController {
@VisibleForTesting
String getCdmaPrlVersion() {
return mTelephonyManager.getCdmaPrlVersion();
// PRL needs to read from SIM. So if no SIM, return empty
return mSubscriptionInfo != null ? mTelephonyManager.getCdmaPrlVersion() : "";
}
@VisibleForTesting
@@ -150,4 +155,9 @@ public class ImeiInfoDialogController {
String getMeid() {
return mTelephonyManager.getMeid(mSlotId);
}
@VisibleForTesting
private boolean isValidSlotIndex(int slotIndex, TelephonyManager telephonyManager) {
return slotIndex >= 0 && slotIndex < telephonyManager.getPhoneCount();
}
}

View File

@@ -86,8 +86,8 @@ public class ImeiInfoDialogControllerTest {
mController = spy(new ImeiInfoDialogController(mDialog, SLOT_ID));
doReturn(PRL_VERSION).when(mController).getCdmaPrlVersion();
doReturn(MEID_NUMBER).when(mController).getMeid();
when(mTelephonyManager.getCdmaPrlVersion()).thenReturn(PRL_VERSION);
when(mTelephonyManager.getMeid(anyInt())).thenReturn(MEID_NUMBER);
when(mTelephonyManager.getCdmaMin(anyInt())).thenReturn(MIN_NUMBER);
when(mTelephonyManager.getDeviceSoftwareVersion(anyInt())).thenReturn(IMEI_SV_NUMBER);
when(mTelephonyManager.getImei(anyInt())).thenReturn(IMEI_NUMBER);
@@ -98,6 +98,7 @@ public class ImeiInfoDialogControllerTest {
mController = spy(new ImeiInfoDialogController(mDialog, SLOT_ID + 1));
mController.populateImeiInfo();
verify(mDialog, never()).setText(anyInt(), any());
}
@@ -129,16 +130,30 @@ public class ImeiInfoDialogControllerTest {
}
@Test
public void populateImeiInfo_cdmaSimDisabled_shouldRemoveImeiInfoAndSetMinToEmpty() {
public void populateImeiInfo_cdmaSimDisabled_shouldRemoveImeiInfoAndSetMinPrlToEmpty() {
ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
mController.populateImeiInfo();
verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
verify(mDialog).setText(ID_PRL_VERSION_VALUE, "");
verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
}
@Test
public void populateImeiInfo_gsmSimDisabled_shouldSetImeiAndRemoveCdmaSettings() {
ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);
mController.populateImeiInfo();
verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
verify(mDialog).removeViewFromScreen(ID_CDMA_SETTINGS);
}
@Test
public void populateImeinfo_gsm_shouldSetImeiAndRemoveCdmaSettings() {
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);