Loading telephony/java/android/telephony/SubscriptionManager.java +43 −18 Original line number Original line Diff line number Diff line Loading @@ -135,29 +135,28 @@ public class SubscriptionManager { public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY = public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY = "cache_key.telephony.get_default_sub_id"; "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 = private static PropertyInvalidatedCache<Void, Integer> sDefaultSubIdCache = new PropertyInvalidatedCache<Void, Integer>( new PropertyInvalidatedCache<Void, Integer>( DEFAULT_SUB_ID_CACHE_SIZE, MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) { CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) { @Override @Override protected Integer recompute(Void query) { protected Integer recompute(Void query) { int subId = INVALID_SUBSCRIPTION_ID; return getDefaultSubscriptionIdInternal(); }}; try { private static PropertyInvalidatedCache<Void, Integer> sDefaultDataSubIdCache = ISub iSub = TelephonyManager.getSubscriptionService(); new PropertyInvalidatedCache<Void, Integer>( if (iSub != null) { MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY) { subId = iSub.getDefaultSubId(); @Override } protected Integer recompute(Void query) { } catch (RemoteException ex) { return getDefaultDataSubscriptionIdInternal(); // ignore it }}; } if (VDBG) logd("getDefaultSubId=" + subId); return subId; } }; /** /** * Generates a content {@link Uri} used to receive updates on simInfo change * Generates a content {@link Uri} used to receive updates on simInfo change * on the given subscriptionId * on the given subscriptionId Loading Loading @@ -1875,6 +1874,22 @@ public class SubscriptionManager { return sDefaultSubIdCache.query(null); 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. * Returns the system's default voice subscription id. * * Loading Loading @@ -2025,6 +2040,10 @@ public class SubscriptionManager { * @return the default data subscription Id. * @return the default data subscription Id. */ */ public static int getDefaultDataSubscriptionId() { public static int getDefaultDataSubscriptionId() { return sDefaultDataSubIdCache.query(null); } private static int getDefaultDataSubscriptionIdInternal() { int subId = INVALID_SUBSCRIPTION_ID; int subId = INVALID_SUBSCRIPTION_ID; try { try { Loading Loading @@ -3300,6 +3319,11 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY); PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY); } } /** @hide */ public static void invalidateDefaultDataSubIdCaches() { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY); } /** /** * Clears all process-local binder caches. * Clears all process-local binder caches. * * Loading @@ -3307,5 +3331,6 @@ public class SubscriptionManager { */ */ public static void clearCaches() { public static void clearCaches() { sDefaultSubIdCache.clear(); sDefaultSubIdCache.clear(); sDefaultDataSubIdCache.clear(); } } } } Loading
telephony/java/android/telephony/SubscriptionManager.java +43 −18 Original line number Original line Diff line number Diff line Loading @@ -135,29 +135,28 @@ public class SubscriptionManager { public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY = public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY = "cache_key.telephony.get_default_sub_id"; "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 = private static PropertyInvalidatedCache<Void, Integer> sDefaultSubIdCache = new PropertyInvalidatedCache<Void, Integer>( new PropertyInvalidatedCache<Void, Integer>( DEFAULT_SUB_ID_CACHE_SIZE, MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) { CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) { @Override @Override protected Integer recompute(Void query) { protected Integer recompute(Void query) { int subId = INVALID_SUBSCRIPTION_ID; return getDefaultSubscriptionIdInternal(); }}; try { private static PropertyInvalidatedCache<Void, Integer> sDefaultDataSubIdCache = ISub iSub = TelephonyManager.getSubscriptionService(); new PropertyInvalidatedCache<Void, Integer>( if (iSub != null) { MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY) { subId = iSub.getDefaultSubId(); @Override } protected Integer recompute(Void query) { } catch (RemoteException ex) { return getDefaultDataSubscriptionIdInternal(); // ignore it }}; } if (VDBG) logd("getDefaultSubId=" + subId); return subId; } }; /** /** * Generates a content {@link Uri} used to receive updates on simInfo change * Generates a content {@link Uri} used to receive updates on simInfo change * on the given subscriptionId * on the given subscriptionId Loading Loading @@ -1875,6 +1874,22 @@ public class SubscriptionManager { return sDefaultSubIdCache.query(null); 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. * Returns the system's default voice subscription id. * * Loading Loading @@ -2025,6 +2040,10 @@ public class SubscriptionManager { * @return the default data subscription Id. * @return the default data subscription Id. */ */ public static int getDefaultDataSubscriptionId() { public static int getDefaultDataSubscriptionId() { return sDefaultDataSubIdCache.query(null); } private static int getDefaultDataSubscriptionIdInternal() { int subId = INVALID_SUBSCRIPTION_ID; int subId = INVALID_SUBSCRIPTION_ID; try { try { Loading Loading @@ -3300,6 +3319,11 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY); PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY); } } /** @hide */ public static void invalidateDefaultDataSubIdCaches() { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY); } /** /** * Clears all process-local binder caches. * Clears all process-local binder caches. * * Loading @@ -3307,5 +3331,6 @@ public class SubscriptionManager { */ */ public static void clearCaches() { public static void clearCaches() { sDefaultSubIdCache.clear(); sDefaultSubIdCache.clear(); sDefaultDataSubIdCache.clear(); } } } }