[Settings] 1. Show default subId SIM page if get an intent with invalid
subId 2. Fix the hotswap UI issue Bug: 271635200 Bug: 271347499 Test: local test Change-Id: Iac61a211fce7bcd85da48cb291f46584cf43f5c5
This commit is contained in:
@@ -179,7 +179,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
}
|
||||
|
||||
private void addRegisterBySubId(int subId) {
|
||||
if (!mTelephonyCallbackMap.containsKey(subId)) {
|
||||
if (!mTelephonyCallbackMap.containsKey(subId) || !mTelephonyManagerMap.containsKey(subId)) {
|
||||
PhoneCallStateTelephonyCallback
|
||||
telephonyCallback = new PhoneCallStateTelephonyCallback();
|
||||
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
|
||||
@@ -435,8 +435,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
getUiccInfoBySubscriptionInfo(uiccSlotInfos, subInfo);
|
||||
SubscriptionInfo firstRemovableSubInfo = SubscriptionUtil.getFirstRemovableSubscription(
|
||||
context);
|
||||
SubscriptionInfo subscriptionOrDefault = SubscriptionUtil.getSubscriptionOrDefault(
|
||||
context, mSubId);
|
||||
if(DEBUG){
|
||||
Log.d(TAG, "convert subscriptionInfo to entity for subId = " + mSubId);
|
||||
}
|
||||
@@ -455,8 +453,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
firstRemovableSubInfo == null ? false
|
||||
: firstRemovableSubInfo.getSubscriptionId() == mSubId,
|
||||
String.valueOf(SubscriptionUtil.getDefaultSimConfig(context, mSubId)),
|
||||
subscriptionOrDefault == null ? false
|
||||
: subscriptionOrDefault.getSubscriptionId() == mSubId,
|
||||
SubscriptionUtil.isDefaultSubscription(context, mSubId),
|
||||
mSubscriptionManager.isValidSubscriptionId(mSubId),
|
||||
mSubscriptionManager.isUsableSubscriptionId(mSubId),
|
||||
mSubscriptionManager.isActiveSubscriptionId(mSubId),
|
||||
@@ -540,11 +537,11 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
SubscriptionUtil.getSelectableSubscriptionInfoList(mContext));
|
||||
}
|
||||
|
||||
private void insertAvailableSubInfoToEntity(List<SubscriptionInfo> availableInfoList) {
|
||||
private void insertAvailableSubInfoToEntity(List<SubscriptionInfo> inputAvailableInfoList) {
|
||||
sExecutor.execute(() -> {
|
||||
SubscriptionInfoEntity[] availableInfoArray = mAvailableSubInfoEntityList.toArray(
|
||||
new SubscriptionInfoEntity[0]);
|
||||
if ((availableInfoList == null || availableInfoList.size() == 0)
|
||||
if ((inputAvailableInfoList == null || inputAvailableInfoList.size() == 0)
|
||||
&& mAvailableSubInfoEntityList.size() != 0) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "availableSudInfoList from framework is empty, remove all subs");
|
||||
@@ -554,11 +551,12 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
deleteAllInfoBySubId(info.subId);
|
||||
}
|
||||
|
||||
} else if (availableInfoList != null) {
|
||||
SubscriptionInfo[] infoArray = availableInfoList.toArray(new SubscriptionInfo[0]);
|
||||
} else if (inputAvailableInfoList != null) {
|
||||
SubscriptionInfo[] inputAvailableInfoArray = inputAvailableInfoList.toArray(
|
||||
new SubscriptionInfo[0]);
|
||||
// Remove the redundant subInfo
|
||||
if (availableInfoList.size() <= mAvailableSubInfoEntityList.size()) {
|
||||
for (SubscriptionInfo subInfo : infoArray) {
|
||||
if (inputAvailableInfoList.size() <= mAvailableSubInfoEntityList.size()) {
|
||||
for (SubscriptionInfo subInfo : inputAvailableInfoArray) {
|
||||
int subId = subInfo.getSubscriptionId();
|
||||
if (mSubscriptionInfoMap.containsKey(subId)) {
|
||||
mSubscriptionInfoMap.remove(subId);
|
||||
@@ -571,11 +569,20 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
deleteAllInfoBySubId(String.valueOf(key));
|
||||
}
|
||||
}
|
||||
} else if (inputAvailableInfoList.size() < mAvailableSubInfoEntityList.size()) {
|
||||
// Check the subInfo between the new list from framework and old list in
|
||||
// the database, if the subInfo is not existed in the new list, delete it
|
||||
// from the database.
|
||||
for (SubscriptionInfoEntity info : availableInfoArray) {
|
||||
if (sCacheSubscriptionInfoEntityMap.containsKey(info.subId)) {
|
||||
deleteAllInfoBySubId(info.subId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert all new available subInfo to database.
|
||||
for (SubscriptionInfo subInfo : infoArray) {
|
||||
for (SubscriptionInfo subInfo : inputAvailableInfoArray) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "insert subInfo to subInfoEntity, subInfo = " + subInfo);
|
||||
}
|
||||
|
@@ -101,7 +101,9 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
return setSummaryResId(R.string.calls_sms_no_sim);
|
||||
} else {
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
for (SubscriptionInfoEntity subInfo : list) {
|
||||
SubscriptionInfoEntity[] entityArray = list.toArray(
|
||||
new SubscriptionInfoEntity[0]);
|
||||
for (SubscriptionInfoEntity subInfo : entityArray) {
|
||||
int subsSize = list.size();
|
||||
int subId = Integer.parseInt(subInfo.subId);
|
||||
final CharSequence displayName = subInfo.uniqueName;
|
||||
@@ -125,7 +127,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
.append(")");
|
||||
}
|
||||
// Do not add ", " for the last subscription.
|
||||
if (!subInfo.equals(list.get(list.size() - 1))) {
|
||||
if (list.size() > 0 && !subInfo.equals(list.get(list.size() - 1))) {
|
||||
summary.append(", ");
|
||||
}
|
||||
|
||||
|
@@ -688,6 +688,12 @@ public class SubscriptionUtil {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static boolean isDefaultSubscription(Context context, int subId) {
|
||||
SubscriptionAnnotation subInfo = getDefaultSubscriptionSelection(
|
||||
new SelectableSubscriptions(context, true).call());
|
||||
return subInfo != null && subInfo.getSubscriptionId() == subId;
|
||||
}
|
||||
|
||||
public static SubscriptionInfo getSubscriptionOrDefault(Context context, int subscriptionId) {
|
||||
return getSubscription(context, subscriptionId,
|
||||
(subscriptionId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) ? null : (
|
||||
|
@@ -114,15 +114,12 @@ public class ConvertToEsimPreferenceController extends TelephonyBasePreferenceCo
|
||||
@Override
|
||||
public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
// TODO(b/262195754): Need the intent to enabled the feature.
|
||||
// if (DataServiceUtils.shouldUpdateEntityList(mSubscriptionInfoEntityList,
|
||||
// subInfoEntityList)) {
|
||||
// mSubscriptionInfoEntityList = subInfoEntityList;
|
||||
// mSubscriptionInfoEntityList.forEach(entity -> {
|
||||
// if (Integer.parseInt(entity.subId) == mSubId) {
|
||||
// mSubscriptionInfoEntity = entity;
|
||||
// update();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// mSubscriptionInfoEntityList = subInfoEntityList;
|
||||
// mSubscriptionInfoEntityList.forEach(entity -> {
|
||||
// if (Integer.parseInt(entity.subId) == mSubId) {
|
||||
// mSubscriptionInfoEntity = entity;
|
||||
// update();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -150,7 +151,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
MobileNetworkUtils.getSearchableSubscriptionId(context));
|
||||
Log.d(LOG_TAG, "display subId from intent: " + mSubId);
|
||||
} else {
|
||||
Log.d(LOG_TAG, "intent is null, can not get the subId from intent.");
|
||||
Log.d(LOG_TAG, "intent is null, can not get subId " + mSubId + " from intent.");
|
||||
}
|
||||
} else {
|
||||
mSubId = getArguments().getInt(Settings.EXTRA_SUB_ID,
|
||||
@@ -165,9 +166,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
mMobileNetworkRepository.queryMobileNetworkInfoBySubId(
|
||||
String.valueOf(mSubId));
|
||||
});
|
||||
if (mSubId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
return Arrays.asList();
|
||||
}
|
||||
|
||||
return Arrays.asList(
|
||||
new DataUsageSummaryPreferenceController(getActivity(), getSettingsLifecycle(),
|
||||
this, mSubId),
|
||||
@@ -178,8 +177,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
new SmsDefaultSubscriptionController(context, KEY_SMS_PREF, getSettingsLifecycle(),
|
||||
this),
|
||||
new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF,
|
||||
getSettingsLifecycle(), this, mSubId),
|
||||
new ConvertToEsimPreferenceController(context, KEY_CONVERT_TO_ESIM_PREF,
|
||||
getSettingsLifecycle(), this, mSubId));
|
||||
}
|
||||
|
||||
@@ -188,8 +185,14 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
super.onAttach(context);
|
||||
|
||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
Log.d(LOG_TAG, "Invalid subId request " + mSubId);
|
||||
return;
|
||||
Log.d(LOG_TAG, "Invalid subId, get the default subscription to show.");
|
||||
SubscriptionInfo info = SubscriptionUtil.getSubscriptionOrDefault(context, mSubId);
|
||||
if (info == null) {
|
||||
Log.d(LOG_TAG, "Invalid subId request " + mSubId);
|
||||
return;
|
||||
}
|
||||
mSubId = info.getSubscriptionId();
|
||||
Log.d(LOG_TAG, "Show NetworkSettings fragment for subId" + mSubId);
|
||||
}
|
||||
|
||||
Intent intent = getIntent();
|
||||
@@ -291,7 +294,11 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
use(ContactDiscoveryPreferenceController.class).init(getParentFragmentManager(), mSubId);
|
||||
use(NrAdvancedCallingPreferenceController.class).init(mSubId);
|
||||
use(TransferEsimPreferenceController.class).init(mSubId, mSubscriptionInfoEntity);
|
||||
use(ConvertToEsimPreferenceController.class).init(mSubId, mSubscriptionInfoEntity);
|
||||
final ConvertToEsimPreferenceController convertToEsimPreferenceController =
|
||||
use(ConvertToEsimPreferenceController.class);
|
||||
if (convertToEsimPreferenceController != null) {
|
||||
convertToEsimPreferenceController.init(mSubId, mSubscriptionInfoEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -321,7 +328,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
}
|
||||
|
||||
private void onSubscriptionDetailChanged() {
|
||||
|
||||
if (mSubscriptionInfoEntity != null) {
|
||||
/**
|
||||
* Update the title when SIM stats got changed
|
||||
@@ -451,7 +457,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
ContactDiscoveryDialogFragment fragment = getContactDiscoveryFragment(mSubId);
|
||||
|
||||
if (mSubscriptionInfoEntity == null) {
|
||||
Log.d(LOG_TAG, "Zoey, showContactDiscoveryDialog, Invalid subId request " + mSubId);
|
||||
Log.d(LOG_TAG, "showContactDiscoveryDialog, Invalid subId request " + mSubId);
|
||||
onDestroy();
|
||||
return;
|
||||
}
|
||||
@@ -488,13 +494,20 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
}
|
||||
|
||||
mSubInfoEntityList = subInfoEntityList;
|
||||
mSubInfoEntityList.forEach(entity -> {
|
||||
SubscriptionInfoEntity[] entityArray = mSubInfoEntityList.toArray(
|
||||
new SubscriptionInfoEntity[0]);
|
||||
for (SubscriptionInfoEntity entity : entityArray) {
|
||||
int subId = Integer.parseInt(entity.subId);
|
||||
mSubscriptionInfoMap.put(subId, entity);
|
||||
if (subId == mSubId) {
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && subId == mSubId) {
|
||||
mSubscriptionInfoEntity = entity;
|
||||
onSubscriptionDetailChanged();
|
||||
Log.d(LOG_TAG, "Set subInfo for subId " + mSubId);
|
||||
break;
|
||||
} else if (entity.isDefaultSubscriptionSelection) {
|
||||
mSubscriptionInfoEntity = entity;
|
||||
Log.d(LOG_TAG, "Set subInfo to the default subInfo.");
|
||||
}
|
||||
});
|
||||
}
|
||||
onSubscriptionDetailChanged();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user