Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70309285 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Finish mobile settings if sub id not exists" into main

parents 855681fa 3ad52764
Loading
Loading
Loading
Loading
+10 −24
Original line number Diff line number Diff line
@@ -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();
    }
}