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

Commit 96a18e55 authored by Collin Fijalkovich's avatar Collin Fijalkovich Committed by Automerger Merge Worker
Browse files

Cache getDefaultSmsSubscriptionId Binder calls am: 02e5c590 am: 995278f0

Change-Id: Iccf173260e09a07cff7a31f15e4101a5291847a4
parents c26f625d 995278f0
Loading
Loading
Loading
Loading
+20 −30
Original line number Original line Diff line number Diff line
@@ -139,6 +139,10 @@ public class SubscriptionManager {
    public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY =
    public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY =
            "cache_key.telephony.get_default_data_sub_id";
            "cache_key.telephony.get_default_data_sub_id";


    /** @hide */
    public static final String CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY =
            "cache_key.telephony.get_default_sms_sub_id";

    /** @hide */
    /** @hide */
    public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY =
    public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY =
            "cache_key.telephony.get_active_data_sub_id";
            "cache_key.telephony.get_active_data_sub_id";
@@ -161,13 +165,15 @@ public class SubscriptionManager {
                return getDefaultDataSubscriptionIdInternal();
                return getDefaultDataSubscriptionIdInternal();
            }};
            }};


    private static PropertyInvalidatedCache<Void, Integer> sDefaultSmsSubIdCache =
            new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSmsSubId,
                    CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY,
                    INVALID_SUBSCRIPTION_ID);

    private static PropertyInvalidatedCache<Void, Integer> sActiveDataSubIdCache =
    private static PropertyInvalidatedCache<Void, Integer> sActiveDataSubIdCache =
            new PropertyInvalidatedCache<Void, Integer>(
            new SubscriptionPropertyInvalidatedCache<>(ISub::getActiveDataSubscriptionId,
                    MAX_CACHE_SIZE, CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY) {
                    CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY,
            @Override
                    INVALID_SUBSCRIPTION_ID);
            protected Integer recompute(Void query) {
                return getActiveDataSubscriptionIdInternal();
            }};


    /**
    /**
     * Generates a content {@link Uri} used to receive updates on simInfo change
     * Generates a content {@link Uri} used to receive updates on simInfo change
@@ -1984,19 +1990,7 @@ public class SubscriptionManager {
     * @return the default SMS subscription Id.
     * @return the default SMS subscription Id.
     */
     */
    public static int getDefaultSmsSubscriptionId() {
    public static int getDefaultSmsSubscriptionId() {
        int subId = INVALID_SUBSCRIPTION_ID;
        return sDefaultSmsSubIdCache.query(null);

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

        if (VDBG) logd("getDefaultSmsSubscriptionId, sub id = " + subId);
        return subId;
    }
    }


    /**
    /**
@@ -3300,17 +3294,6 @@ public class SubscriptionManager {
        return sActiveDataSubIdCache.query(null);
        return sActiveDataSubIdCache.query(null);
    }
    }


    private static int getActiveDataSubscriptionIdInternal() {
        try {
            ISub iSub = TelephonyManager.getSubscriptionService();
            if (iSub != null) {
                return iSub.getActiveDataSubscriptionId();
            }
        } catch (RemoteException ex) {
        }
        return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }

    /**
    /**
     * Helper method that puts a subscription id on an intent with the constants:
     * Helper method that puts a subscription id on an intent with the constants:
     * PhoneConstant.SUBSCRIPTION_KEY and SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX.
     * PhoneConstant.SUBSCRIPTION_KEY and SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX.
@@ -3336,6 +3319,11 @@ public class SubscriptionManager {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY);
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY);
    }
    }


    /** @hide */
    public static void invalidateDefaultSmsSubIdCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY);
    }

    /** @hide */
    /** @hide */
    public static void invalidateActiveDataSubIdCaches() {
    public static void invalidateActiveDataSubIdCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY);
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY);
@@ -3350,6 +3338,7 @@ public class SubscriptionManager {
        sDefaultSubIdCache.clear();
        sDefaultSubIdCache.clear();
        sDefaultDataSubIdCache.clear();
        sDefaultDataSubIdCache.clear();
        sActiveDataSubIdCache.clear();
        sActiveDataSubIdCache.clear();
        sDefaultSmsSubIdCache.clear();
    }
    }


    /**
    /**
@@ -3361,5 +3350,6 @@ public class SubscriptionManager {
        sDefaultSubIdCache.disableLocal();
        sDefaultSubIdCache.disableLocal();
        sDefaultDataSubIdCache.disableLocal();
        sDefaultDataSubIdCache.disableLocal();
        sActiveDataSubIdCache.disableLocal();
        sActiveDataSubIdCache.disableLocal();
        sDefaultSmsSubIdCache.disableLocal();
    }
    }
}
}