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

Commit ef64db40 authored by David Liu's avatar David Liu Committed by Android (Google) Code Review
Browse files

Revert "Change the resource cache key from context to package name."

This reverts commit 611b380c.

Reason for revert: This cl breaks the CTS test CellBroadcastServiceTests com.android.cellbroadcastservice.tests.CellBroadcastHandlerTest#testGetResources(b/294300859)

Change-Id: I4624a216e42a065e31048e6726d9ebde48010ef9
parent 611b380c
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -1306,11 +1306,8 @@ public class SubscriptionManager {
    private final Context mContext;

    // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing
    // the Package Name and subId. Applications can create new contexts from
    // {@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 =
    // the Context and subId.
    private static final Map<Pair<Context, Integer>, Resources> sResourcesCache =
            new ConcurrentHashMap<>();

    /**
@@ -2777,13 +2774,12 @@ public class SubscriptionManager {
            boolean useRootLocale) {
        // Check if resources for this context and subId already exist in the resource cache.
        // Resources that use the root locale are not cached.
        Pair<String, Integer> cacheKey = null;
        Pair<Context, Integer> cacheKey = null;
        if (isValidSubscriptionId(subId) && !useRootLocale) {
            cacheKey = Pair.create(context.getPackageName(), subId);
            Resources cached = sResourcesCache.get(cacheKey);
            if (cached != null) {
            cacheKey = Pair.create(context, subId);
            if (sResourcesCache.containsKey(cacheKey)) {
                // Cache hit. Use cached Resources.
                return cached;
                return sResourcesCache.get(cacheKey);
            }
        }