Fix IMEI information can't display without pSIM inserted

When no SIM, we can't get active subscription info.
So current code will not create TelephonyManager and cause IMEI not
retrieved.
Create TelephonyManager with default if no subscription info.

Bug: 132215720
Test: test with SIM and without SIM to check SIM status UI and atest ImeiInfoDialogControllerTest pass
Change-Id: Iaeb932ea66a6bee77136251941cca657984e456f
This commit is contained in:
andychou
2019-05-09 00:00:23 +08:00
parent 6e8c403360
commit 9ac6d81177
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();
}
}