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

Commit 4e9db787 authored by Fan Zhang's avatar Fan Zhang Committed by Android (Google) Code Review
Browse files

Merge "Do not clear category tile cache in every reload."

parents 118d0c72 5adc2669
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;

import com.android.settingslib.applications.InterestingConfigChanges;

import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -30,6 +32,7 @@ public class CategoryManager {
    private static final String TAG = "CategoryManager";

    private static CategoryManager sInstance;
    private final InterestingConfigChanges mInterestingConfigChanges;

    // Tile cache (key: <packageName, activityName>, value: tile)
    private final Map<Pair<String, String>, Tile> mTileByComponentCache;
@@ -39,16 +42,18 @@ public class CategoryManager {

    private List<DashboardCategory> mCategories;

    public static CategoryManager get() {
    public static CategoryManager get(Context context) {
        if (sInstance == null) {
            sInstance = new CategoryManager();
            sInstance = new CategoryManager(context);
        }
        return sInstance;
    }

    CategoryManager() {
    CategoryManager(Context context) {
        mTileByComponentCache = new ArrayMap<>();
        mCategoryByKeyMap = new ArrayMap<>();
        mInterestingConfigChanges = new InterestingConfigChanges();
        mInterestingConfigChanges.applyNewConfig(context.getResources());
    }

    public synchronized DashboardCategory getTilesByCategory(Context context, String categoryKey) {
@@ -67,8 +72,10 @@ public class CategoryManager {
    }

    public synchronized void reloadAllCategories(Context context) {
        final boolean forceClearCache = mInterestingConfigChanges.applyNewConfig(
                context.getResources());
        mCategories = null;
        tryInitCategories(context);
        tryInitCategories(context, forceClearCache);
    }

    public synchronized void updateCategoryFromBlacklist(Set<ComponentName> tileBlacklist) {
@@ -87,8 +94,16 @@ public class CategoryManager {
    }

    private synchronized void tryInitCategories(Context context) {
        // Keep cached tiles by default. The cache is only invalidated when InterestingConfigChange
        // happens.
        tryInitCategories(context, false /* forceClearCache */);
    }

    private synchronized void tryInitCategories(Context context, boolean forceClearCache) {
        if (mCategories == null) {
            if (forceClearCache) {
                mTileByComponentCache.clear();
            }
            mCategoryByKeyMap.clear();
            mCategories = TileUtils.getCategories(context, mTileByComponentCache,
                    false /* categoryDefinedInManifest */);
+2 −2
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ public class SettingsDrawerActivity extends Activity {
            return false;
        }
        if (isDashboardFeatureEnabled()) {
            final DashboardCategory homepageCategories = CategoryManager.get()
            final DashboardCategory homepageCategories = CategoryManager.get(this)
                    .getTilesByCategory(this, CategoryKey.CATEGORY_HOMEPAGE);
            return homepageCategories.containsComponent(componentName);
        } else {
@@ -429,7 +429,7 @@ public class SettingsDrawerActivity extends Activity {
        private final CategoryManager mCategoryManager;

        public CategoriesUpdateTask() {
            mCategoryManager = CategoryManager.get();
            mCategoryManager = CategoryManager.get(SettingsDrawerActivity.this);
        }

        @Override
+2 −2
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public class SettingsDrawerAdapter extends BaseAdapter {
    }

    public void updateHomepageCategories() {
        DashboardCategory category =
                CategoryManager.get().getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE);
        final DashboardCategory category = CategoryManager.get(mActivity)
                        .getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE);
        mItems.clear();
        // Spacer.
        mItems.add(null);