Loading telephony/java/android/telephony/SubscriptionManager.java +10 −6 Original line number Original line Diff line number Diff line Loading @@ -1319,8 +1319,11 @@ public class SubscriptionManager { private final Context mContext; private final Context mContext; // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing // the Context and subId. // the Package Name and subId. Applications can create new contexts from private static final Map<Pair<Context, Integer>, Resources> sResourcesCache = // {@link android.content.Context#createPackageContext} with the same resources for different // purposes. Therefore, Cache can be wasted for resources from different contexts in the same // package. Use the package name rather than the context itself as a key value of cache. private static final Map<Pair<String, Integer>, Resources> sResourcesCache = new ConcurrentHashMap<>(); new ConcurrentHashMap<>(); /** /** Loading Loading @@ -2809,12 +2812,13 @@ public class SubscriptionManager { boolean useRootLocale) { boolean useRootLocale) { // Check if resources for this context and subId already exist in the resource cache. // Check if resources for this context and subId already exist in the resource cache. // Resources that use the root locale are not cached. // Resources that use the root locale are not cached. Pair<Context, Integer> cacheKey = null; Pair<String, Integer> cacheKey = null; if (isValidSubscriptionId(subId) && !useRootLocale) { if (isValidSubscriptionId(subId) && !useRootLocale) { cacheKey = Pair.create(context, subId); cacheKey = Pair.create(context.getPackageName(), subId); if (sResourcesCache.containsKey(cacheKey)) { Resources cached = sResourcesCache.get(cacheKey); if (cached != null) { // Cache hit. Use cached Resources. // Cache hit. Use cached Resources. return sResourcesCache.get(cacheKey); return cached; } } } } Loading Loading
telephony/java/android/telephony/SubscriptionManager.java +10 −6 Original line number Original line Diff line number Diff line Loading @@ -1319,8 +1319,11 @@ public class SubscriptionManager { private final Context mContext; private final Context mContext; // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing // the Context and subId. // the Package Name and subId. Applications can create new contexts from private static final Map<Pair<Context, Integer>, Resources> sResourcesCache = // {@link android.content.Context#createPackageContext} with the same resources for different // purposes. Therefore, Cache can be wasted for resources from different contexts in the same // package. Use the package name rather than the context itself as a key value of cache. private static final Map<Pair<String, Integer>, Resources> sResourcesCache = new ConcurrentHashMap<>(); new ConcurrentHashMap<>(); /** /** Loading Loading @@ -2809,12 +2812,13 @@ public class SubscriptionManager { boolean useRootLocale) { boolean useRootLocale) { // Check if resources for this context and subId already exist in the resource cache. // Check if resources for this context and subId already exist in the resource cache. // Resources that use the root locale are not cached. // Resources that use the root locale are not cached. Pair<Context, Integer> cacheKey = null; Pair<String, Integer> cacheKey = null; if (isValidSubscriptionId(subId) && !useRootLocale) { if (isValidSubscriptionId(subId) && !useRootLocale) { cacheKey = Pair.create(context, subId); cacheKey = Pair.create(context.getPackageName(), subId); if (sResourcesCache.containsKey(cacheKey)) { Resources cached = sResourcesCache.get(cacheKey); if (cached != null) { // Cache hit. Use cached Resources. // Cache hit. Use cached Resources. return sResourcesCache.get(cacheKey); return cached; } } } } Loading