From 1307f63f8a93541bf6e2d29c11fab69778a25e42 Mon Sep 17 00:00:00 2001 From: Bjorn Bringert Date: Thu, 3 Oct 2013 22:31:03 +0100 Subject: Add a better app filtering mechanism and filter widgets The old one didn't use the app filter when packages were added or updated, only in the initial load. The app filter is now also used for appwidget providers. Bug: 10895858 Bug: 10898990 Change-Id: Id29bbc3cf7bdb0c360edd92f768b86684bd338ed --- res/values/config.xml | 5 ++++ src/com/android/launcher3/AllAppsList.java | 10 +++++-- src/com/android/launcher3/AppFilter.java | 35 ++++++++++++++++++++++ .../android/launcher3/AppsCustomizePagedView.java | 3 ++ src/com/android/launcher3/Launcher.java | 5 ---- src/com/android/launcher3/LauncherAppState.java | 9 +++++- src/com/android/launcher3/LauncherModel.java | 13 ++++---- 7 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 src/com/android/launcher3/AppFilter.java diff --git a/res/values/config.xml b/res/values/config.xml index 8718f1562..0766d7624 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -81,4 +81,9 @@ false + + + + diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java index 5d3aa3ab7..d955e4eae 100644 --- a/src/com/android/launcher3/AllAppsList.java +++ b/src/com/android/launcher3/AllAppsList.java @@ -46,11 +46,14 @@ class AllAppsList { private IconCache mIconCache; + private AppFilter mAppFilter; + /** * Boring constructor. */ - public AllAppsList(IconCache iconCache) { + public AllAppsList(IconCache iconCache, AppFilter appFilter) { mIconCache = iconCache; + mAppFilter = appFilter; } /** @@ -60,13 +63,16 @@ class AllAppsList { * If the app is already in the list, doesn't add it. */ public void add(AppInfo info) { + if (mAppFilter != null && !mAppFilter.shouldShowApp(info.componentName)) { + return; + } if (findActivity(data, info.componentName)) { return; } data.add(info); added.add(info); } - + public void clear() { data.clear(); // TODO: do we clear these too? diff --git a/src/com/android/launcher3/AppFilter.java b/src/com/android/launcher3/AppFilter.java new file mode 100644 index 000000000..e01436d7a --- /dev/null +++ b/src/com/android/launcher3/AppFilter.java @@ -0,0 +1,35 @@ +package com.android.launcher3; + +import android.content.ComponentName; +import android.text.TextUtils; +import android.util.Log; + +public abstract class AppFilter { + + private static final boolean DBG = false; + private static final String TAG = "AppFilter"; + + public abstract boolean shouldShowApp(ComponentName app); + + public static AppFilter loadByName(String className) { + if (TextUtils.isEmpty(className)) return null; + if (DBG) Log.d(TAG, "Loading AppFilter: " + className); + try { + Class cls = Class.forName(className); + return (AppFilter) cls.newInstance(); + } catch (ClassNotFoundException e) { + Log.e(TAG, "Bad AppFilter class", e); + return null; + } catch (InstantiationException e) { + Log.e(TAG, "Bad AppFilter class", e); + return null; + } catch (IllegalAccessException e) { + Log.e(TAG, "Bad AppFilter class", e); + return null; + } catch (ClassCastException e) { + Log.e(TAG, "Bad AppFilter class", e); + return null; + } + } + +} diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index 4e9d68b50..9b35bb5ea 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -438,6 +438,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen for (Object o : widgetsAndShortcuts) { if (o instanceof AppWidgetProviderInfo) { AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o; + if (!app.shouldShowAppOrWidgetProvider(widget.provider)) { + continue; + } widget.label = widget.label.trim(); if (widget.minWidth > 0 && widget.minHeight > 0) { // Ensure that all widgets we show can be added on a workspace of this size diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 5e10e8b78..d04f7ed10 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -3933,11 +3933,6 @@ public class Launcher extends Activity } } - @Override - public boolean shouldShowApp(ResolveInfo app) { - return true; - } - /** * A package was updated. * diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index ed96310ac..7da1c2af7 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -34,6 +34,7 @@ public class LauncherAppState { private LauncherModel mModel; private IconCache mIconCache; + private AppFilter mAppFilter; private WidgetPreviewLoader.CacheDb mWidgetPreviewCacheDb; private boolean mIsScreenLarge; private float mScreenDensity; @@ -81,7 +82,9 @@ public class LauncherAppState { mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext); mIconCache = new IconCache(sContext); - mModel = new LauncherModel(this, mIconCache); + + mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class)); + mModel = new LauncherModel(this, mIconCache, mAppFilter); // Register intent receivers IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); @@ -147,6 +150,10 @@ public class LauncherAppState { return mModel; } + boolean shouldShowAppOrWidgetProvider(ComponentName componentName) { + return mAppFilter == null || mAppFilter.shouldShowApp(componentName); + } + WidgetPreviewLoader.CacheDb getWidgetPreviewCacheDb() { return mWidgetPreviewCacheDb; } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index cc89d01ac..edfc07059 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -158,7 +158,6 @@ public class LauncherModel extends BroadcastReceiver { public void bindFolders(HashMap folders); public void finishBindingItems(boolean upgradePath); public void bindAppWidget(LauncherAppWidgetInfo info); - public boolean shouldShowApp(ResolveInfo app); public void bindAllApplications(ArrayList apps); public void bindAppsAdded(ArrayList newScreens, ArrayList addNotAnimated, @@ -179,12 +178,12 @@ public class LauncherModel extends BroadcastReceiver { public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn); } - LauncherModel(LauncherAppState app, IconCache iconCache) { + LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { final Context context = app.getContext(); mAppsCanBeOnRemoveableStorage = Environment.isExternalStorageRemovable(); mApp = app; - mBgAllAppsList = new AllAppsList(iconCache); + mBgAllAppsList = new AllAppsList(iconCache, appFilter); mIconCache = iconCache; mDefaultIcon = Utilities.createIconBitmap( @@ -2397,11 +2396,9 @@ public class LauncherModel extends BroadcastReceiver { // Create the ApplicationInfos for (int i = 0; i < apps.size(); i++) { ResolveInfo app = apps.get(i); - if (oldCallbacks.shouldShowApp(app)) { - // This builds the icon bitmaps. - mBgAllAppsList.add(new AppInfo(packageManager, app, - mIconCache, mLabelCache)); - } + // This builds the icon bitmaps. + mBgAllAppsList.add(new AppInfo(packageManager, app, + mIconCache, mLabelCache)); } // Huh? Shouldn't this be inside the Runnable below? -- cgit v1.2.3