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

Commit 17dd0d65 authored by Malcolm Chen's avatar Malcolm Chen Committed by Automerger Merge Worker
Browse files

Remove unecessary locking to avoid dead lock. am: 69eb0eb6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/12220612

Change-Id: Id5f89c08cd18e9fc0eb73eff5fa67409a0656947
parents 4756708f 69eb0eb6
Loading
Loading
Loading
Loading
+48 −47
Original line number Diff line number Diff line
@@ -901,11 +901,17 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    private List<SubscriptionInfo> makeCacheListCopyWithLock(List<SubscriptionInfo> cacheSubList) {
        synchronized (mSubInfoListLock) {
            return new ArrayList<>(cacheSubList);
        }
    }

    @Deprecated
    @UnsupportedAppUsage
    public List<SubscriptionInfo> getActiveSubscriptionInfoList(String callingPackage) {
        return getSubscriptionInfoListFromCacheHelper(callingPackage, null,
                mCacheActiveSubInfoList);
                makeCacheListCopyWithLock(mCacheActiveSubInfoList));
    }

    /**
@@ -919,7 +925,7 @@ public class SubscriptionController extends ISub.Stub {
    public List<SubscriptionInfo> getActiveSubscriptionInfoList(String callingPackage,
            String callingFeatureId) {
        return getSubscriptionInfoListFromCacheHelper(callingPackage, callingFeatureId,
                mCacheActiveSubInfoList);
                makeCacheListCopyWithLock(mCacheActiveSubInfoList));
    }

    /**
@@ -930,13 +936,13 @@ public class SubscriptionController extends ISub.Stub {
    public void refreshCachedActiveSubscriptionInfoList() {
        boolean opptSubListChanged;

        synchronized (mSubInfoListLock) {
        List<SubscriptionInfo> activeSubscriptionInfoList = getSubInfo(
                SubscriptionManager.SIM_SLOT_INDEX + ">=0 OR "
                + SubscriptionManager.SUBSCRIPTION_TYPE + "="
                + SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM,
                null);

        synchronized (mSubInfoListLock) {
            if (activeSubscriptionInfoList != null) {
                // Log when active sub info changes.
                if (mCacheActiveSubInfoList.size() != activeSubscriptionInfoList.size()
@@ -951,10 +957,6 @@ public class SubscriptionController extends ISub.Stub {
                logd("activeSubscriptionInfoList is null.");
                mCacheActiveSubInfoList.clear();
            }

            // Refresh cached opportunistic sub list and detect whether it's changed.
            refreshCachedOpportunisticSubscriptionInfoList();

            if (DBG_CACHE) {
                if (!mCacheActiveSubInfoList.isEmpty()) {
                    for (SubscriptionInfo si : mCacheActiveSubInfoList) {
@@ -966,6 +968,9 @@ public class SubscriptionController extends ISub.Stub {
                }
            }
        }

        // Refresh cached opportunistic sub list and detect whether it's changed.
        refreshCachedOpportunisticSubscriptionInfoList();
    }

    @Deprecated
@@ -3241,8 +3246,8 @@ public class SubscriptionController extends ISub.Stub {
    @Override
    public List<SubscriptionInfo> getOpportunisticSubscriptions(String callingPackage,
            String callingFeatureId) {
        return getSubscriptionInfoListFromCacheHelper(
                callingPackage, callingFeatureId, mCacheOpportunisticSubInfoList);
        return getSubscriptionInfoListFromCacheHelper(callingPackage, callingFeatureId,
                makeCacheListCopyWithLock(mCacheOpportunisticSubInfoList));
    }

    /**
@@ -3935,10 +3940,8 @@ public class SubscriptionController extends ISub.Stub {
            // the identifier and phone number access checks are not required.
        }

        synchronized (mSubInfoListLock) {
            // If the caller can read all phone state, just return the full list.
        if (canReadIdentifiers && canReadPhoneNumber) {
                return new ArrayList<>(cacheSubList);
            return cacheSubList;
        }
        // Filter the list to only include subscriptions which the caller can manage.
        List<SubscriptionInfo> subscriptions = new ArrayList<>(cacheSubList.size());
@@ -3966,7 +3969,6 @@ public class SubscriptionController extends ISub.Stub {
        }
        return subscriptions;
    }
    }

    /**
     * Conditionally removes identifiers from the provided {@code subInfo} if the {@code
@@ -4080,13 +4082,12 @@ public class SubscriptionController extends ISub.Stub {
    }

    private void refreshCachedOpportunisticSubscriptionInfoList() {
        synchronized (mSubInfoListLock) {
            List<SubscriptionInfo> oldOpptCachedList = mCacheOpportunisticSubInfoList;

        List<SubscriptionInfo> subList = getSubInfo(
                SubscriptionManager.IS_OPPORTUNISTIC + "=1 AND ("
                        + SubscriptionManager.SIM_SLOT_INDEX + ">=0 OR "
                        + SubscriptionManager.IS_EMBEDDED + "=1)", null);
        synchronized (mSubInfoListLock) {
            List<SubscriptionInfo> oldOpptCachedList = mCacheOpportunisticSubInfoList;

            if (subList != null) {
                subList.sort(SUBSCRIPTION_INFO_COMPARATOR);