Finish mobile settings if sub id not exists

Could be test with,
adb shell am start \
  -a android.settings.NETWORK_OPERATOR_SETTINGS \
  --ei android.provider.extra.SUB_ID 999

Bug: 336232487
Test: manual - on MobileNetworkSettings
Change-Id: I74d5d5b743c40375ceba1ba6e761da901d0d5e65
This commit is contained in:
Chaohui Wang
2024-06-04 16:07:57 +08:00
parent d6fe83b86e
commit 3ad527640e

View File

@@ -65,10 +65,7 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
@@ -107,7 +104,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
private MobileNetworkRepository mMobileNetworkRepository;
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
private Map<Integer, SubscriptionInfoEntity> mSubscriptionInfoMap = new HashMap<>();
@Nullable
private SubscriptionInfoEntity mSubscriptionInfoEntity;
private MobileNetworkInfoEntity mMobileNetworkInfoEntity;
@@ -512,38 +509,27 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
@Override
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
// Check the current subId is existed or not, if so, finish it.
if (!mSubscriptionInfoMap.isEmpty()) {
// Check each subInfo and remove it in the map based on the new list.
for (SubscriptionInfoEntity entity : subInfoEntityList) {
mSubscriptionInfoMap.remove(Integer.parseInt(entity.subId));
}
Iterator<Integer> iterator = mSubscriptionInfoMap.keySet().iterator();
while (iterator.hasNext()) {
if (iterator.next() == mSubId && getActivity() != null) {
finishFragment();
return;
}
}
}
mSubInfoEntityList = subInfoEntityList;
SubscriptionInfoEntity[] entityArray = mSubInfoEntityList.toArray(
new SubscriptionInfoEntity[0]);
mSubscriptionInfoEntity = null;
for (SubscriptionInfoEntity entity : entityArray) {
int subId = Integer.parseInt(entity.subId);
mSubscriptionInfoMap.put(subId, entity);
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && subId == mSubId) {
if (subId == mSubId) {
mSubscriptionInfoEntity = entity;
Log.d(LOG_TAG, "Set subInfo for subId " + mSubId);
break;
} else if (entity.isDefaultSubscriptionSelection) {
} else if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
&& entity.isDefaultSubscriptionSelection) {
mSubscriptionInfoEntity = entity;
Log.d(LOG_TAG, "Set subInfo to default subInfo.");
}
}
if (mSubscriptionInfoEntity == null && getActivity() != null) {
// If the current subId is not existed, finish it.
finishFragment();
return;
}
onSubscriptionDetailChanged();
}
}