From b96792dcc654626cf1a57bd1b23efbb330de4664 Mon Sep 17 00:00:00 2001 From: Raj Yengisetty Date: Mon, 24 Nov 2014 11:21:48 -0800 Subject: Protected Apps: Re-add filtering in App Drawer and fixing protected folders Change-Id: Ia0899f79248647dbacf44cf917a27ebe62d20e4d --- Android.mk | 1 + src/com/android/launcher3/AppInfo.java | 13 +++ .../android/launcher3/AppsCustomizePagedView.java | 103 ++++++++++++++++++--- src/com/android/launcher3/LauncherModel.java | 2 + 4 files changed, 106 insertions(+), 13 deletions(-) diff --git a/Android.mk b/Android.mk index 5cdc0030d..1f98b76d8 100644 --- a/Android.mk +++ b/Android.mk @@ -39,6 +39,7 @@ LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/protos/ # LOCAL_SDK_VERSION := 21 LOCAL_PACKAGE_NAME := Trebuchet +LOCAL_PRIVILEGED_MODULE := true #LOCAL_CERTIFICATE := shared LOCAL_AAPT_FLAGS += --rename-manifest-package com.cyanogenmod.trebuchet diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java index b1af370b1..674d8e819 100644 --- a/src/com/android/launcher3/AppInfo.java +++ b/src/com/android/launcher3/AppInfo.java @@ -110,6 +110,19 @@ public class AppInfo extends ItemInfo { return flags; } + public static int initFlags(PackageInfo info) { + int appFlags = info.applicationInfo.flags; + int flags = 0; + if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { + flags |= DOWNLOADED_FLAG; + + if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { + flags |= UPDATED_SYSTEM_APP_FLAG; + } + } + return flags; + } + public AppInfo(AppInfo info) { super(info); componentName = info.componentName; diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index c9be6265e..46703979e 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -207,7 +207,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private ArrayList mApps; private ArrayList mWidgets; + private ArrayList mFilteredApps; private ArrayList mFilteredWidgets; + private ArrayList mProtectedApps; private ArrayList mProtectedPackages; @@ -331,7 +333,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mLayoutInflater = LayoutInflater.from(context); mPackageManager = context.getPackageManager(); mApps = new ArrayList(); + mFilteredApps = new ArrayList(); mWidgets = new ArrayList(); + mFilteredWidgets = new ArrayList(); mIconCache = (LauncherAppState.getInstance()).getIconCache(); mRunningTasks = new ArrayList(); @@ -416,7 +420,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen i = (currentPage * numItemsPerPage) + (childCount / 2); } } else if (mContentType == ContentType.Widgets) { - int numApps = mApps.size(); + int numApps = mFilteredApps.size(); PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage); int numItemsPerPage = mWidgetCountX * mWidgetCountY; int childCount = layout.getChildCount(); @@ -444,12 +448,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int getPageForComponent(int index) { if (index < 0) return 0; - if (index < mApps.size()) { + if (index < mFilteredApps.size()) { int numItemsPerPage = mCellCountX * mCellCountY; return (index / numItemsPerPage); } else { int numItemsPerPage = mWidgetCountX * mWidgetCountY; - return (index - mApps.size()) / numItemsPerPage; + return (index - mFilteredApps.size()) / numItemsPerPage; } } @@ -460,9 +464,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } private void updatePageCounts() { - mNumWidgetPages = (int) Math.ceil(mWidgets.size() / + mNumWidgetPages = (int) Math.ceil((float) mFilteredWidgets.size() / (float) (mWidgetCountX * mWidgetCountY)); - mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + mNumAppsPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)); if(LauncherApplication.SHOW_CTAPP_FEATURE){ mNumAppsPages = mNumAppsPages + 2; //for ct } @@ -493,7 +497,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen super.onLayout(changed, l, t, r, b); if (!isDataReady()) { - if ((LauncherAppState.isDisableAllApps() || !mApps.isEmpty()) && !mWidgets.isEmpty()) { + if ((LauncherAppState.isDisableAllApps() || !mFilteredApps.isEmpty()) + && !mFilteredWidgets.isEmpty()) { post(new Runnable() { // This code triggers requestLayout so must be posted outside of the // layout pass. @@ -546,7 +551,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgets.add(o); } } - updatePageCountsAndInvalidateData(); + filterWidgets(); } public void setBulkBind(boolean bulkBind) { @@ -1093,7 +1098,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int ctEndIndex = (page == 0) ? Math.min(startIndex + numCells, ctFirstPageApps.size()) : Math.min(startIndex + numCells, ctApps.size()); - int defEndIndex = Math.min(startIndex + numCells, mApps.size()); + int defEndIndex = Math.min(startIndex + numCells, mFilteredApps.size()); int endIndex = isCTFlag ? ctEndIndex : defEndIndex ; layout.removeAllViewsOnPage(); @@ -1105,7 +1110,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen for (int i = startIndex; i < endIndex; ++i) { AppInfo info = isCTFlag ? ((page == 0) ? ctFirstPageApps.get(i) : ctApps.get(i)) - : mApps.get(i); + : mFilteredApps.get(i); BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate( R.layout.apps_customize_application, layout, false); @@ -1262,8 +1267,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Prepare the set of widgets to load previews for in the background int offset = page * numItemsPerPage; - for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { - items.add(mWidgets.get(i)); + int size = Math.min(offset + numItemsPerPage, mFilteredWidgets.size()); + for (int i = offset; i < size; ++i) { + items.add(mFilteredWidgets.get(i)); } // Prepopulate the pages with the other widget info, and fill in the previews later @@ -1606,7 +1612,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } public void sortApps() { - Collections.sort(mApps, getComparatorForSortMode()); + Collections.sort(mFilteredApps, getComparatorForSortMode()); if (mContentType == ContentType.Applications) { for (int i = 0; i < getChildCount(); i++) { @@ -1673,7 +1679,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen removePreInstallApps(); } - Collections.sort(mApps, getComparatorForSortMode()); + filterAppsWithoutInvalidate(); if (mPreInstallConfig) { addPreInstallApps(); @@ -1741,6 +1747,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } addAppsWithoutInvalidate(list); + filterAppsWithoutInvalidate(); if (mPreInstallConfig) { addPreInstallApps(); @@ -1789,6 +1796,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void removeApps(ArrayList appInfos) { if (!LauncherAppState.isDisableAllApps()) { removeAppsWithoutInvalidate(appInfos); + filterAppsWithoutInvalidate(); updatePageCountsAndInvalidateData(); } } @@ -1805,6 +1813,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } addAppsWithoutInvalidate(list); + filterAppsWithoutInvalidate(); if (mPreInstallConfig) { addPreInstallApps(); } @@ -1812,6 +1821,74 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } + public void filterAppsWithoutInvalidate() { + updateProtectedAppsList(mLauncher); + + mFilteredApps = new ArrayList(mApps); + Iterator iterator = mFilteredApps.iterator(); + while (iterator.hasNext()) { + AppInfo appInfo = iterator.next(); + boolean system = (appInfo.flags & AppInfo.DOWNLOADED_FLAG) == 0; + if (mProtectedApps.contains(appInfo.componentName) || + (system && !getShowSystemApps()) || + (!system && !getShowDownloadedApps())) { + iterator.remove(); + } + } + Collections.sort(mFilteredApps, getComparatorForSortMode()); + } + + public void filterApps() { + filterAppsWithoutInvalidate(); + updatePageCountsAndInvalidateData(); + } + + public void filterWidgetsWithoutInvalidate() { + updateProtectedAppsList(mLauncher); + + mFilteredWidgets = new ArrayList(mWidgets); + + Iterator iterator = mFilteredWidgets.iterator(); + while (iterator.hasNext()) { + Object o = iterator.next(); + + String packageName; + if (o instanceof AppWidgetProviderInfo) { + AppWidgetProviderInfo widgetInfo = (AppWidgetProviderInfo) o; + if (widgetInfo.provider == null) { + continue; + } + packageName = widgetInfo.provider.getPackageName(); + } else if (o instanceof ResolveInfo) { + ResolveInfo shortcut = (ResolveInfo) o; + packageName = shortcut.activityInfo.applicationInfo.packageName; + } else { + Log.w(TAG, "Unknown class in widgets list: " + o.getClass()); + continue; + } + + int flags; + try { + flags = AppInfo.initFlags(mPackageManager.getPackageInfo(packageName, 0)); + } catch (PackageManager.NameNotFoundException e) { + flags = 0; + } + + boolean system = (flags & AppInfo.DOWNLOADED_FLAG) == 0; + if (mProtectedPackages.contains(packageName) || + (system && !getShowSystemApps()) || + (!system && !getShowDownloadedApps())) { + iterator.remove(); + } + } + } + + public void filterWidgets() { + filterWidgetsWithoutInvalidate(); + updatePageCountsAndInvalidateData(); + } + + private void updateProtectedAppsList(Context context) { String protectedComponents = Settings.Secure.getString(context.getContentResolver(), LauncherModel.SETTINGS_PROTECTED_COMPONENTS); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 17c5ddd4f..4da49ce34 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2778,6 +2778,8 @@ public class LauncherModel extends BroadcastReceiver final boolean postOnMainThread = (deferredBindRunnables != null); + removeHiddenAppsWorkspaceItems(workspaceItems, appWidgets, folders); + // Bind the workspace items int N = workspaceItems.size(); for (int i = 0; i < N; i += ITEMS_CHUNK) { -- cgit v1.2.3