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

Commit caaddc87 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Clean up unused params from SubscriptionAnnotation

Bug: 338904413
Test: m Settings
Change-Id: Ic714066e45bb0050361c8096394929828a871589
parent 1acb8162
Loading
Loading
Loading
Loading
+0 −57
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.network.helper;

import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * This is a Callable class which queries valid card ID for eSIM
 */
public class QueryEsimCardId implements Callable<AtomicIntegerArray> {
    private static final String TAG = "QueryEsimCardId";

    private TelephonyManager mTelephonyManager;

    /**
     * Constructor of class
     * @param TelephonyManager
     */
    public QueryEsimCardId(TelephonyManager telephonyManager) {
        mTelephonyManager = telephonyManager;
    }

    /**
     * Implementation of Callable
     * @return card ID(s) in AtomicIntegerArray
     */
    public AtomicIntegerArray call() {
        List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
        if (cardInfos == null) {
            return new AtomicIntegerArray(0);
        }
        return new AtomicIntegerArray(cardInfos.stream()
                .filter(Objects::nonNull)
                .filter(cardInfo -> (!cardInfo.isRemovable() && (cardInfo.getCardId() >= 0)))
                .mapToInt(UiccCardInfo::getCardId)
                .toArray());
    }
}
 No newline at end of file
+1 −14
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.util.Log;
import androidx.annotation.Keep;
import androidx.annotation.VisibleForTesting;

import com.android.settings.network.helper.SubscriptionAnnotation;
import com.android.settingslib.utils.ThreadUtils;

import java.util.Collections;
@@ -103,15 +102,6 @@ public class SelectableSubscriptions implements Callable<List<SubscriptionAnnota
        TelephonyManager telMgr = mContext.getSystemService(TelephonyManager.class);

        try {
            // query in background thread
            Future<AtomicIntegerArray> eSimCardId =
                    ThreadUtils.postOnBackgroundThread(new QueryEsimCardId(telMgr));

            // query in background thread
            Future<AtomicIntegerArray> simSlotIndex =
                    ThreadUtils.postOnBackgroundThread(
                    new QuerySimSlotIndex(telMgr, true, true));

            // query in background thread
            Future<AtomicIntegerArray> activeSimSlotIndex =
                    ThreadUtils.postOnBackgroundThread(
@@ -120,16 +110,13 @@ public class SelectableSubscriptions implements Callable<List<SubscriptionAnnota
            List<SubscriptionInfo> subInfoList = mSubscriptions.get();

            // wait for result from background thread
            List<Integer> eSimCardIdList = atomicToList(eSimCardId.get());
            List<Integer> simSlotIndexList = atomicToList(simSlotIndex.get());
            List<Integer> activeSimSlotIndexList = atomicToList(activeSimSlotIndex.get());

            // build a list of SubscriptionAnnotation
            return IntStream.range(0, subInfoList.size())
                    .mapToObj(subInfoIndex ->
                            new SubscriptionAnnotation.Builder(subInfoList, subInfoIndex))
                    .map(annoBdr -> annoBdr.build(mContext,
                            eSimCardIdList, simSlotIndexList, activeSimSlotIndexList))
                    .map(annoBdr -> annoBdr.build(mContext, activeSimSlotIndexList))
                    .filter(mFilter)
                    .collect(Collectors.collectingAndThen(Collectors.toList(), mFinisher));
        } catch (Exception exception) {
+5 −24
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.settings.network.helper;

import android.content.Context;
import android.os.ParcelUuid;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;

@@ -35,14 +34,11 @@ public class SubscriptionAnnotation {
    private static final String TAG = "SubscriptionAnnotation";

    private SubscriptionInfo mSubInfo;
    private int mOrderWithinList;
    private int mType = TYPE_UNKNOWN;
    private boolean mIsExisted;
    private boolean mIsActive;
    private boolean mIsAllowToDisplay;

    public static final ParcelUuid EMPTY_UUID = ParcelUuid.fromString("0-0-0-0-0");

    public static final int TYPE_UNKNOWN = 0x0;
    public static final int TYPE_PSIM = 0x1;
    public static final int TYPE_ESIM = 0x2;
@@ -52,8 +48,8 @@ public class SubscriptionAnnotation {
     */
    public static class Builder {

        private List<SubscriptionInfo> mSubInfoList;
        private int mIndexWithinList;
        private final List<SubscriptionInfo> mSubInfoList;
        private final int mIndexWithinList;

        /**
         * Constructor of builder
@@ -65,10 +61,9 @@ public class SubscriptionAnnotation {
            mIndexWithinList = indexWithinList;
        }

        public SubscriptionAnnotation build(Context context, List<Integer> eSimCardId,
                List<Integer> simSlotIndex, List<Integer> activeSimSlotIndex) {
        public SubscriptionAnnotation build(Context context, List<Integer> activeSimSlotIndex) {
            return new SubscriptionAnnotation(mSubInfoList, mIndexWithinList, context,
                    eSimCardId, simSlotIndex, activeSimSlotIndex);
                    activeSimSlotIndex);
        }
    }

@@ -78,8 +73,7 @@ public class SubscriptionAnnotation {
    @Keep
    @VisibleForTesting
    protected SubscriptionAnnotation(List<SubscriptionInfo> subInfoList, int subInfoIndex,
            Context context, List<Integer> eSimCardId,
            List<Integer> simSlotIndex, List<Integer> activeSimSlotIndexList) {
            Context context, List<Integer> activeSimSlotIndexList) {
        if ((subInfoIndex < 0) || (subInfoIndex >= subInfoList.size())) {
            return;
        }
@@ -88,7 +82,6 @@ public class SubscriptionAnnotation {
            return;
        }

        mOrderWithinList = subInfoIndex;
        mType = mSubInfo.isEmbedded() ? TYPE_ESIM : TYPE_PSIM;
        mIsExisted = true;
        if (mType == TYPE_ESIM) {
@@ -104,12 +97,6 @@ public class SubscriptionAnnotation {
        mIsAllowToDisplay = isDisplayAllowed(context);
    }

    // the index provided during construction of Builder
    @Keep
    public int getOrderingInList() {
        return mOrderWithinList;
    }

    // type of subscription
    @Keep
    public int getType() {
@@ -141,12 +128,6 @@ public class SubscriptionAnnotation {
                mSubInfo.getSubscriptionId();
    }

    // the grouping UUID
    @Keep
    public ParcelUuid getGroupUuid() {
        return (mSubInfo == null) ? null : mSubInfo.getGroupUuid();
    }

    // the SubscriptionInfo
    @Keep
    public SubscriptionInfo getSubInfo() {