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

Commit b407e3c1 authored by Collin Fijalkovich's avatar Collin Fijalkovich
Browse files

Cache getDefaultDataSubscriptionId Binder calls

Use PropertyInvalidatedCache to avoid redundant
calls to SubscriptionController.getDefaultDataSubscriptionId
Bug: 151953109
Test: Verified cache operated correctly when phone process is killed.
Test: atest SubscriptionControllerTest
Test: atest android.telephony.cts.SubscriptionManagerTest

Change-Id: Ifbd380a9281d7bc9c3a9b35c5e93207acabf8d15
parent 19bc3e13
Loading
Loading
Loading
Loading
+42 −18
Original line number Diff line number Diff line
@@ -135,29 +135,28 @@ public class SubscriptionManager {
    public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY =
            "cache_key.telephony.get_default_sub_id";

    private static final int DEFAULT_SUB_ID_CACHE_SIZE = 1;
    /** @hide */
    public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY =
            "cache_key.telephony.get_default_data_sub_id";

    private static final int MAX_CACHE_SIZE = 4;

    private static PropertyInvalidatedCache<Void, Integer> sDefaultSubIdCache =
            new PropertyInvalidatedCache<Void, Integer>(
                    DEFAULT_SUB_ID_CACHE_SIZE,
                    CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) {
                    MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) {
            @Override
            protected Integer recompute(Void query) {
                    int subId = INVALID_SUBSCRIPTION_ID;
                return getDefaultSubscriptionIdInternal();
            }};

                    try {
                        ISub iSub = TelephonyManager.getSubscriptionService();
                        if (iSub != null) {
                            subId = iSub.getDefaultSubId();
                        }
                    } catch (RemoteException ex) {
                        // ignore it
                    }
    private static PropertyInvalidatedCache<Void, Integer> sDefaultDataSubIdCache =
            new PropertyInvalidatedCache<Void, Integer>(
                    MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY) {
            @Override
            protected Integer recompute(Void query) {
                return getDefaultDataSubscriptionIdInternal();
            }};

                    if (VDBG) logd("getDefaultSubId=" + subId);
                    return subId;
                }
            };
    /**
     * Generates a content {@link Uri} used to receive updates on simInfo change
     * on the given subscriptionId
@@ -1857,6 +1856,22 @@ public class SubscriptionManager {
        return sDefaultSubIdCache.query(null);
    }

    private static int getDefaultSubscriptionIdInternal() {
        int subId = INVALID_SUBSCRIPTION_ID;

        try {
            ISub iSub = TelephonyManager.getSubscriptionService();
            if (iSub != null) {
                subId = iSub.getDefaultSubId();
            }
        } catch (RemoteException ex) {
            // ignore it
        }

        if (VDBG) logd("getDefaultSubId=" + subId);
        return subId;
    }

    /**
     * Returns the system's default voice subscription id.
     *
@@ -2007,6 +2022,10 @@ public class SubscriptionManager {
     * @return the default data subscription Id.
     */
    public static int getDefaultDataSubscriptionId() {
        return sDefaultDataSubIdCache.query(null);
    }

    private static int getDefaultDataSubscriptionIdInternal() {
        int subId = INVALID_SUBSCRIPTION_ID;

        try {
@@ -3281,4 +3300,9 @@ public class SubscriptionManager {
    public static void invalidateDefaultSubIdCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY);
    }

    /** @hide */
    public static void invalidateDefaultDataSubIdCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -13080,6 +13080,7 @@ public class TelephonyManager {
                sISub.asBinder().unlinkToDeath(sServiceDeath, 0);
                sISub = null;
                SubscriptionManager.invalidateDefaultSubIdCaches();
                SubscriptionManager.invalidateDefaultDataSubIdCaches();
            }
            if (sISms != null) {
                sISms.asBinder().unlinkToDeath(sServiceDeath, 0);