From 7d7ce5135ccc3d08c03b31fd69b9101c081ec439 Mon Sep 17 00:00:00 2001 From: Collin Fijalkovich Date: Thu, 2 Apr 2020 13:32:32 -0700 Subject: [PATCH] Cache getActiveDataSubscriptionId Binder calls Use PropertyInvalidatedCache to avoid redundant calls to SubscriptionController.getActiveDataSubscriptionId. Bug: 151953109 Test: Verified cache operated correctly when phone process is killed. Test: atest SubscriptionControllerTest Test: atest android.telephony.cts.SubscriptionManagerTest Merged-In: I45d1abf15e4b105c966d4a786a4dc33aa67b20aa Change-Id: I45d1abf15e4b105c966d4a786a4dc33aa67b20aa --- .../telephony/SubscriptionManager.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 45dc7afc3dc01..a254f240a20b4 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -139,6 +139,10 @@ public class SubscriptionManager { public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY = "cache_key.telephony.get_default_data_sub_id"; + /** @hide */ + public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY = + "cache_key.telephony.get_active_data_sub_id"; + private static final int MAX_CACHE_SIZE = 4; private static PropertyInvalidatedCache sDefaultSubIdCache = @@ -157,6 +161,14 @@ public class SubscriptionManager { return getDefaultDataSubscriptionIdInternal(); }}; + private static PropertyInvalidatedCache sActiveDataSubIdCache = + new PropertyInvalidatedCache( + MAX_CACHE_SIZE, CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY) { + @Override + protected Integer recompute(Void query) { + return getActiveDataSubscriptionIdInternal(); + }}; + /** * Generates a content {@link Uri} used to receive updates on simInfo change * on the given subscriptionId @@ -3285,6 +3297,10 @@ public class SubscriptionManager { * SubscriptionManager.INVALID_SUBSCRIPTION_ID if not. */ public static int getActiveDataSubscriptionId() { + return sActiveDataSubIdCache.query(null); + } + + private static int getActiveDataSubscriptionIdInternal() { try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { @@ -3320,6 +3336,11 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY); } + /** @hide */ + public static void invalidateActiveDataSubIdCaches() { + PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY); + } + /** * Clears all process-local binder caches. * @@ -3328,5 +3349,17 @@ public class SubscriptionManager { public static void clearCaches() { sDefaultSubIdCache.clear(); sDefaultDataSubIdCache.clear(); + sActiveDataSubIdCache.clear(); + } + + /** + * Allows a test process to disable client-side caching operations. + * + * @hide + */ + public static void disableCaching() { + sDefaultSubIdCache.disableLocal(); + sDefaultDataSubIdCache.disableLocal(); + sActiveDataSubIdCache.disableLocal(); } }