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

Commit b3832a47 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge changes from topic "sm_cleanup"

* changes:
  Subscription Manager public method clean up
  Refine QNS anomaly report
  Better support for handover from OOS
parents c854536d 28276184
Loading
Loading
Loading
Loading
+40 −96
Original line number Diff line number Diff line
@@ -164,15 +164,10 @@ public class SubscriptionController extends ISub.Stub {

    private AppOpsManager mAppOps;

    // Allows test mocks to avoid SELinux failures on invalidate calls.
    private static boolean sCachingEnabled = true;

    // Each slot can have multiple subs.
    private static class WatchedSlotIndexToSubIds {
        private Map<Integer, ArrayList<Integer>> mSlotIndexToSubIds = new ConcurrentHashMap<>();

        WatchedSlotIndexToSubIds() {
        }
        private final Map<Integer, ArrayList<Integer>> mSlotIndexToSubIds =
                new ConcurrentHashMap<>();

        public void clear() {
            mSlotIndexToSubIds.clear();
@@ -191,7 +186,7 @@ public class SubscriptionController extends ISub.Stub {
                return null;
            }

            return new ArrayList<Integer>(subIdList);
            return new ArrayList<>(subIdList);
        }

        public void put(int slotIndex, ArrayList<Integer> value) {
@@ -273,9 +268,9 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    private static WatchedSlotIndexToSubIds sSlotIndexToSubIds = new WatchedSlotIndexToSubIds();
    private final WatchedSlotIndexToSubIds mSlotIndexToSubIds = new WatchedSlotIndexToSubIds();

    protected static WatchedInt sDefaultFallbackSubId =
    private final WatchedInt mDefaultFallbackSubId =
            new WatchedInt(SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        @Override
        public void set(int newValue) {
@@ -1479,7 +1474,7 @@ public class SubscriptionController extends ISub.Stub {
                            int defaultSubId = getDefaultSubId();
                            if (DBG) {
                                logdl("[addSubInfoRecord]"
                                        + " sSlotIndexToSubIds.size=" + sSlotIndexToSubIds.size()
                                        + " mSlotIndexToSubIds.size=" + mSlotIndexToSubIds.size()
                                        + " slotIndex=" + slotIndex + " subId=" + subId
                                        + " defaultSubId=" + defaultSubId
                                        + " simCount=" + subIdCountMax);
@@ -1559,7 +1554,7 @@ public class SubscriptionController extends ISub.Stub {
                    if (DBG) logdl("[addSubInfoRecord] sim name = " + nameToSet);
                }

                if (DBG) logdl("[addSubInfoRecord]- info size=" + sSlotIndexToSubIds.size());
                if (DBG) logdl("[addSubInfoRecord]- info size=" + mSlotIndexToSubIds.size());
            }

        } finally {
@@ -1663,7 +1658,7 @@ public class SubscriptionController extends ISub.Stub {
                return -1;
            }
            refreshCachedActiveSubscriptionInfoList();
            result = sSlotIndexToSubIds.removeFromSubIdList(slotIndex, subId);
            result = mSlotIndexToSubIds.removeFromSubIdList(slotIndex, subId);
            if (result == NO_ENTRY_FOR_SLOT_INDEX) {
                loge("sSlotIndexToSubIds has no entry for slotIndex = " + slotIndex);
            } else if (result == SUB_ID_NOT_IN_SLOT) {
@@ -1707,7 +1702,7 @@ public class SubscriptionController extends ISub.Stub {
        // Refresh the Cache of Active Subscription Info List
        refreshCachedActiveSubscriptionInfoList();

        sSlotIndexToSubIds.remove(slotIndex);
        mSlotIndexToSubIds.remove(slotIndex);
    }

    /**
@@ -2594,14 +2589,14 @@ public class SubscriptionController extends ISub.Stub {
            return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        }

        int size = sSlotIndexToSubIds.size();
        int size = mSlotIndexToSubIds.size();

        if (size == 0) {
            if (DBG) logd("[getSlotIndex]- size == 0, return SIM_NOT_INSERTED instead");
            return SubscriptionManager.SIM_NOT_INSERTED;
        }

        for (Entry<Integer, ArrayList<Integer>> entry : sSlotIndexToSubIds.entrySet()) {
        for (Entry<Integer, ArrayList<Integer>> entry : mSlotIndexToSubIds.entrySet()) {
            int sim = entry.getKey();
            ArrayList<Integer> subs = entry.getValue();

@@ -2644,7 +2639,7 @@ public class SubscriptionController extends ISub.Stub {
        }

        // Check if we've got any SubscriptionInfo records using slotIndexToSubId as a surrogate.
        int size = sSlotIndexToSubIds.size();
        int size = mSlotIndexToSubIds.size();
        if (size == 0) {
            if (VDBG) {
                logd("[getSubId]- sSlotIndexToSubIds.size == 0, return null slotIndex="
@@ -2654,7 +2649,7 @@ public class SubscriptionController extends ISub.Stub {
        }

        // Convert ArrayList to array
        ArrayList<Integer> subIds = sSlotIndexToSubIds.getCopy(slotIndex);
        ArrayList<Integer> subIds = mSlotIndexToSubIds.getCopy(slotIndex);
        if (subIds != null && subIds.size() > 0) {
            int[] subIdArr = new int[subIds.size()];
            for (int i = 0; i < subIds.size(); i++) {
@@ -2687,7 +2682,7 @@ public class SubscriptionController extends ISub.Stub {
            return SubscriptionManager.INVALID_PHONE_INDEX;
        }

        int size = sSlotIndexToSubIds.size();
        int size = mSlotIndexToSubIds.size();
        if (size == 0) {
            phoneId = mDefaultPhoneId;
            if (VDBG) logdl("[getPhoneId]- no sims, returning default phoneId=" + phoneId);
@@ -2695,7 +2690,7 @@ public class SubscriptionController extends ISub.Stub {
        }

        // FIXME: Assumes phoneId == slotIndex
        for (Entry<Integer, ArrayList<Integer>> entry: sSlotIndexToSubIds.entrySet()) {
        for (Entry<Integer, ArrayList<Integer>> entry: mSlotIndexToSubIds.entrySet()) {
            int sim = entry.getKey();
            ArrayList<Integer> subs = entry.getValue();

@@ -2723,14 +2718,14 @@ public class SubscriptionController extends ISub.Stub {
        // Now that all security checks passes, perform the operation as ourselves.
        final long identity = Binder.clearCallingIdentity();
        try {
            int size = sSlotIndexToSubIds.size();
            int size = mSlotIndexToSubIds.size();

            if (size == 0) {
                if (DBG) logdl("[clearSubInfo]- no simInfo size=" + size);
                return 0;
            }

            sSlotIndexToSubIds.clear();
            mSlotIndexToSubIds.clear();
            if (DBG) logdl("[clearSubInfo]- clear size=" + size);
            return size;
        } finally {
@@ -2781,7 +2776,7 @@ public class SubscriptionController extends ISub.Stub {
            if (VDBG) logdl("[getDefaultSubId] NOT VoiceCapable subId=" + subId);
        }
        if (!isActiveSubId(subId)) {
            subId = sDefaultFallbackSubId.get();
            subId = mDefaultFallbackSubId.get();
            if (VDBG) logdl("[getDefaultSubId] NOT active use fall back subId=" + subId);
        }
        if (VDBG) logv("[getDefaultSubId]- value = " + subId);
@@ -2974,7 +2969,7 @@ public class SubscriptionController extends ISub.Stub {
        }
        int previousDefaultSub = getDefaultSubId();
        if (isSubscriptionForRemoteSim(subscriptionType)) {
            sDefaultFallbackSubId.set(subId);
            mDefaultFallbackSubId.set(subId);
            return;
        }
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
@@ -2982,7 +2977,7 @@ public class SubscriptionController extends ISub.Stub {
            if (phoneId >= 0 && (phoneId < mTelephonyManager.getPhoneCount()
                    || mTelephonyManager.getSimCount() == 1)) {
                if (DBG) logdl("[setDefaultFallbackSubId] set sDefaultFallbackSubId=" + subId);
                sDefaultFallbackSubId.set(subId);
                mDefaultFallbackSubId.set(subId);
                // Update MCC MNC device configuration information
                String defaultMccMnc = mTelephonyManager.getSimOperatorNumericForPhone(phoneId);
                MccTable.updateMccMncConfiguration(mContext, defaultMccMnc);
@@ -3082,7 +3077,7 @@ public class SubscriptionController extends ISub.Stub {
    private synchronized ArrayList<Integer> getActiveSubIdArrayList() {
        // Clone the sub id list so it can't change out from under us while iterating
        List<Entry<Integer, ArrayList<Integer>>> simInfoList =
                new ArrayList<>(sSlotIndexToSubIds.entrySet());
                new ArrayList<>(mSlotIndexToSubIds.entrySet());

        // Put the set of sub ids in slot index order
        Collections.sort(simInfoList, (x, y) -> x.getKey().compareTo(y.getKey()));
@@ -3412,7 +3407,7 @@ public class SubscriptionController extends ISub.Stub {
                    .from(mContext).getDefaultSmsPhoneId());
            pw.flush();

            for (Entry<Integer, ArrayList<Integer>> entry : sSlotIndexToSubIds.entrySet()) {
            for (Entry<Integer, ArrayList<Integer>> entry : mSlotIndexToSubIds.entrySet()) {
                pw.println(" sSlotIndexToSubId[" + entry.getKey() + "]: subIds=" + entry);
            }
            pw.flush();
@@ -4397,10 +4392,10 @@ public class SubscriptionController extends ISub.Stub {
    }

    private synchronized boolean addToSubIdList(int slotIndex, int subId, int subscriptionType) {
        ArrayList<Integer> subIdsList = sSlotIndexToSubIds.getCopy(slotIndex);
        ArrayList<Integer> subIdsList = mSlotIndexToSubIds.getCopy(slotIndex);
        if (subIdsList == null) {
            subIdsList = new ArrayList<>();
            sSlotIndexToSubIds.put(slotIndex, subIdsList);
            mSlotIndexToSubIds.put(slotIndex, subIdsList);
        }

        // add the given subId unless it already exists
@@ -4410,20 +4405,20 @@ public class SubscriptionController extends ISub.Stub {
        }
        if (isSubscriptionForRemoteSim(subscriptionType)) {
            // For Remote SIM subscriptions, a slot can have multiple subscriptions.
            sSlotIndexToSubIds.addToSubIdList(slotIndex, subId);
            mSlotIndexToSubIds.addToSubIdList(slotIndex, subId);
        } else {
            // for all other types of subscriptions, a slot can have only one subscription at a time
            sSlotIndexToSubIds.clearSubIdList(slotIndex);
            sSlotIndexToSubIds.addToSubIdList(slotIndex, subId);
            mSlotIndexToSubIds.clearSubIdList(slotIndex);
            mSlotIndexToSubIds.addToSubIdList(slotIndex, subId);
        }


        // Remove the slot from sSlotIndexToSubIds if it has the same sub id with the added slot
        for (Entry<Integer, ArrayList<Integer>> entry : sSlotIndexToSubIds.entrySet()) {
        for (Entry<Integer, ArrayList<Integer>> entry : mSlotIndexToSubIds.entrySet()) {
            if (entry.getKey() != slotIndex && entry.getValue() != null
                    && entry.getValue().contains(subId)) {
                logdl("addToSubIdList - remove " + entry.getKey());
                sSlotIndexToSubIds.remove(entry.getKey());
                mSlotIndexToSubIds.remove(entry.getKey());
            }
        }

@@ -4441,17 +4436,7 @@ public class SubscriptionController extends ISub.Stub {
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public Map<Integer, ArrayList<Integer>> getSlotIndexToSubIdsMap() {
        return sSlotIndexToSubIds.getMap();
    }

    /**
     * This is only for testing
     * @hide
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public void resetStaticMembers() {
        sDefaultFallbackSubId.set(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        mDefaultPhoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
        return mSlotIndexToSubIds.getMap();
    }

    private void notifyOpportunisticSubscriptionInfoChanged() {
@@ -4743,77 +4728,36 @@ public class SubscriptionController extends ISub.Stub {
     */
    private void setGlobalSetting(String name, int value) {
        Settings.Global.putInt(mContext.getContentResolver(), name, value);
        if (name == Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION) {
        if (TextUtils.equals(name, Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION)) {
            invalidateDefaultDataSubIdCaches();
            invalidateActiveDataSubIdCaches();
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        } else if (name == Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION) {
        } else if (TextUtils.equals(name, Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION)) {
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        } else if (name == Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION) {
        } else if (TextUtils.equals(name, Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION)) {
            invalidateDefaultSmsSubIdCaches();
        }
    }

    /**
     * @hide
     */
    private static void invalidateDefaultSubIdCaches() {
        if (sCachingEnabled) {
        SubscriptionManager.invalidateDefaultSubIdCaches();
    }
    }

    /**
     * @hide
     */
    private static void invalidateDefaultDataSubIdCaches() {
        if (sCachingEnabled) {
        SubscriptionManager.invalidateDefaultDataSubIdCaches();
    }
    }

    /**
     * @hide
     */
    private static void invalidateDefaultSmsSubIdCaches() {
        if (sCachingEnabled) {
        SubscriptionManager.invalidateDefaultSmsSubIdCaches();
    }
    }

    /**
     * @hide
     */
    public static void invalidateActiveDataSubIdCaches() {
        if (sCachingEnabled) {
    private static void invalidateActiveDataSubIdCaches() {
        SubscriptionManager.invalidateActiveDataSubIdCaches();
    }
    }

    /**
     * @hide
     */
    protected static void invalidateSlotIndexCaches() {
        if (sCachingEnabled) {
    private static void invalidateSlotIndexCaches() {
        SubscriptionManager.invalidateSlotIndexCaches();
    }
}

    /**
     * @hide
     */
    @VisibleForTesting
    public static void disableCaching() {
        sCachingEnabled = false;
    }

    /**
     * @hide
     */
    @VisibleForTesting
    public static void enableCaching() {
        sCachingEnabled = true;
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -434,6 +434,9 @@ public class AccessNetworksManager extends Handler {
     * @param apnType The requested apnType.
     */
    private void trackFrequentApnTypeChange(@ApnSetting.ApnType int apnType) {
        DataNetworkController dnc = mPhone.getDataNetworkController();
        // ignore the report when no existing network request
        if (!dnc.isCapabilityRequestExisting(DataUtils.apnTypeToNetworkCapability(apnType))) return;
        SlidingWindowEventCounter counter = mApnTypeToQnsChangeNetworkCounter.get(apnType);
        if (counter == null) {
            counter = new SlidingWindowEventCounter(
@@ -445,7 +448,7 @@ public class AccessNetworksManager extends Handler {
            reportAnomaly("QNS requested network change for "
                            + ApnSetting.getApnTypeString(apnType) + " "
                            + counter.getFrequencyString(),
                    "3e89a3df-3524-45fa-b5f2-b8911abc7d57");
                    "3e89a3df-3524-45fa-b5f2-b8911abc7d56");
        }
    }

+21 −3
Original line number Diff line number Diff line
@@ -643,6 +643,11 @@ public class DataNetwork extends StateMachine {
     */
    private @TransportType int mTransport;

    /**
     * The last known data network type.
     */
    private @NetworkType int mLastKnownDataNetworkType;

    /** The reason that why setting up this data network is allowed. */
    private @NonNull DataAllowedReason mDataAllowedReason;

@@ -887,6 +892,7 @@ public class DataNetwork extends StateMachine {
            mTrafficDescriptors.add(dataProfile.getTrafficDescriptor());
        }
        mTransport = transport;
        mLastKnownDataNetworkType = getDataNetworkType();
        mDataAllowedReason = dataAllowedReason;
        dataProfile.setLastSetupTimestamp(SystemClock.elapsedRealtime());
        mAttachedNetworkRequestList.addAll(networkRequestList);
@@ -1077,7 +1083,11 @@ public class DataNetwork extends StateMachine {
                    onCarrierConfigUpdated();
                    break;
                case EVENT_SERVICE_STATE_CHANGED: {
                    mDataCallSessionStats.onDrsOrRatChanged(getDataNetworkType());
                    int networkType = getDataNetworkType();
                    mDataCallSessionStats.onDrsOrRatChanged(networkType);
                    if (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                        mLastKnownDataNetworkType = networkType;
                    }
                    updateSuspendState();
                    updateNetworkCapabilities();
                    break;
@@ -3275,8 +3285,14 @@ public class DataNetwork extends StateMachine {
    }

    /**
     * @return The PCO data map of the network. The key is the PCO id, the value is the PCO data.
     * An empty map if PCO data is not available.
     * @return The last known data network type of the data network.
     */
    public @NetworkType int getLastKnownDataNetworkType() {
        return mLastKnownDataNetworkType;
    }

    /**
     * @return The PCO data received from the network.
     */
    public @NonNull Map<Integer, PcoData> getPcoData() {
        if (mTransport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN
@@ -3525,6 +3541,8 @@ public class DataNetwork extends StateMachine {
        pw.increaseIndent();
        pw.println("mSubId=" + mSubId);
        pw.println("mTransport=" + AccessNetworkConstants.transportTypeToString(mTransport));
        pw.println("mLastKnownDataNetworkType=" + TelephonyManager
                .getNetworkTypeName(mLastKnownDataNetworkType));
        pw.println("WWAN cid=" + mCid.get(AccessNetworkConstants.TRANSPORT_TYPE_WWAN));
        pw.println("WLAN cid=" + mCid.get(AccessNetworkConstants.TRANSPORT_TYPE_WLAN));
        pw.println("mNetworkScore=" + mNetworkScore);
+23 −1
Original line number Diff line number Diff line
@@ -1885,8 +1885,18 @@ public class DataNetworkController extends Handler {
        if (mDataConfigManager.isIwlanHandoverPolicyEnabled()) {
            List<HandoverRule> handoverRules = mDataConfigManager.getHandoverRules();

            int sourceNetworkType = getDataNetworkType(dataNetwork.getTransport());
            if (sourceNetworkType == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                // Using the data network type stored in the data network. We
                // cache the last known network type in data network controller
                // because data network has much shorter life cycle. It can prevent
                // the obsolete last known network type cached in data network
                // type controller.
                sourceNetworkType = dataNetwork.getLastKnownDataNetworkType();
            }
            int sourceAccessNetwork = DataUtils.networkTypeToAccessNetworkType(
                    getDataNetworkType(dataNetwork.getTransport()));
                    sourceNetworkType);

            int targetAccessNetwork = DataUtils.networkTypeToAccessNetworkType(
                    getDataNetworkType(DataUtils.getTargetTransport(dataNetwork.getTransport())));
            NetworkCapabilities capabilities = dataNetwork.getNetworkCapabilities();
@@ -2091,6 +2101,18 @@ public class DataNetworkController extends Handler {
        return mAllNetworkRequestList.contains(networkRequest);
    }

    /**
     * Check if a request for the capability currently exists. Note this method id not thread safe
     * so can be only called within the modules in {@link com.android.internal.telephony.data}.
     *
     * @param capability Network capability to check
     * @return {@code true} if the request for the capability exists.
     */
    public boolean isCapabilityRequestExisting(@NetCapability int capability) {
        return mAllNetworkRequestList.stream()
                .anyMatch(request -> request.hasCapability(capability));
    }

    /**
     * Check if there are existing networks having the same interface name.
     *
+2 −2
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ public class PhoneSwitcher extends Handler {
        @Override
        public void set(int newValue) {
            super.set(newValue);
            SubscriptionController.invalidateActiveDataSubIdCaches();
            SubscriptionManager.invalidateActiveDataSubIdCaches();
        }
    };

@@ -395,7 +395,7 @@ public class PhoneSwitcher extends Handler {
    public static PhoneSwitcher make(int maxDataAttachModemCount, Context context, Looper looper) {
        if (sPhoneSwitcher == null) {
            sPhoneSwitcher = new PhoneSwitcher(maxDataAttachModemCount, context, looper);
            SubscriptionController.invalidateActiveDataSubIdCaches();
            SubscriptionManager.invalidateActiveDataSubIdCaches();
        }

        return sPhoneSwitcher;
Loading