2009-08-17 11:03:03 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Context;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.LauncherActivityInfoCompat;
|
|
|
|
|
import com.android.launcher3.compat.LauncherAppsCompat;
|
2016-03-15 09:16:30 -07:00
|
|
|
import com.android.launcher3.util.FlagOp;
|
2016-09-01 15:17:46 -07:00
|
|
|
import com.android.launcher3.util.ItemInfoMatcher;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2013-12-13 16:07:45 +01:00
|
|
|
import java.util.ArrayList;
|
2015-05-06 16:53:21 -07:00
|
|
|
import java.util.HashSet;
|
2013-12-13 16:07:45 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stores the list of all applications for the all apps view.
|
|
|
|
|
*/
|
2016-10-10 10:41:41 -07:00
|
|
|
public class AllAppsList {
|
2009-08-17 11:03:03 -04:00
|
|
|
public static final int DEFAULT_APPLICATIONS_NUMBER = 42;
|
2014-02-10 12:16:54 -05:00
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/** The list off all apps. */
|
2013-09-04 00:45:37 +02:00
|
|
|
public ArrayList<AppInfo> data =
|
|
|
|
|
new ArrayList<AppInfo>(DEFAULT_APPLICATIONS_NUMBER);
|
2009-08-17 11:03:03 -04:00
|
|
|
/** The list of apps that have been added since the last notify() call. */
|
2013-09-04 00:45:37 +02:00
|
|
|
public ArrayList<AppInfo> added =
|
|
|
|
|
new ArrayList<AppInfo>(DEFAULT_APPLICATIONS_NUMBER);
|
2009-08-17 11:03:03 -04:00
|
|
|
/** The list of apps that have been removed since the last notify() call. */
|
2013-09-04 00:45:37 +02:00
|
|
|
public ArrayList<AppInfo> removed = new ArrayList<AppInfo>();
|
2009-08-17 11:03:03 -04:00
|
|
|
/** The list of apps that have been modified since the last notify() call. */
|
2013-09-04 00:45:37 +02:00
|
|
|
public ArrayList<AppInfo> modified = new ArrayList<AppInfo>();
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
private IconCache mIconCache;
|
|
|
|
|
|
2013-10-03 22:31:03 +01:00
|
|
|
private AppFilter mAppFilter;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* Boring constructor.
|
|
|
|
|
*/
|
2013-10-03 22:31:03 +01:00
|
|
|
public AllAppsList(IconCache iconCache, AppFilter appFilter) {
|
2010-02-08 13:44:00 -08:00
|
|
|
mIconCache = iconCache;
|
2013-10-03 22:31:03 +01:00
|
|
|
mAppFilter = appFilter;
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add the supplied ApplicationInfo objects to the list, and enqueue it into the
|
|
|
|
|
* list to broadcast when notify() is called.
|
2010-04-20 15:43:37 -04:00
|
|
|
*
|
|
|
|
|
* If the app is already in the list, doesn't add it.
|
2009-08-17 11:03:03 -04:00
|
|
|
*/
|
2017-01-06 16:32:57 -08:00
|
|
|
public void add(AppInfo info, LauncherActivityInfoCompat activityInfo) {
|
2016-12-02 19:29:43 +05:30
|
|
|
if (!mAppFilter.shouldShowApp(info.componentName)) {
|
2013-10-03 22:31:03 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2014-04-30 03:02:21 +01:00
|
|
|
if (findActivity(data, info.componentName, info.user)) {
|
2010-04-20 15:43:37 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2017-01-06 16:32:57 -08:00
|
|
|
mIconCache.getTitleAndIcon(info, activityInfo, true /* useLowResIcon */);
|
|
|
|
|
|
2010-04-15 16:28:40 -04:00
|
|
|
data.add(info);
|
|
|
|
|
added.add(info);
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
2013-10-03 22:31:03 +01:00
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
public void clear() {
|
|
|
|
|
data.clear();
|
|
|
|
|
// TODO: do we clear these too?
|
|
|
|
|
added.clear();
|
|
|
|
|
removed.clear();
|
|
|
|
|
modified.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int size() {
|
|
|
|
|
return data.size();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 00:45:37 +02:00
|
|
|
public AppInfo get(int index) {
|
2009-08-17 11:03:03 -04:00
|
|
|
return data.get(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add the icons for the supplied apk called packageName.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
public void addPackage(Context context, String packageName, UserHandle user) {
|
2014-04-30 03:02:21 +01:00
|
|
|
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
|
|
|
|
|
final List<LauncherActivityInfoCompat> matches = launcherApps.getActivityList(packageName,
|
|
|
|
|
user);
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2014-10-06 16:23:56 -07:00
|
|
|
for (LauncherActivityInfoCompat info : matches) {
|
2017-01-06 16:32:57 -08:00
|
|
|
add(new AppInfo(context, info, user), info);
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the apps for the given apk identified by packageName.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
public void removePackage(String packageName, UserHandle user) {
|
2013-09-04 00:45:37 +02:00
|
|
|
final List<AppInfo> data = this.data;
|
2010-01-12 17:24:58 -08:00
|
|
|
for (int i = data.size() - 1; i >= 0; i--) {
|
2013-09-04 00:45:37 +02:00
|
|
|
AppInfo info = data.get(i);
|
2016-10-10 10:41:41 -07:00
|
|
|
if (info.user.equals(user) && packageName.equals(info.componentName.getPackageName())) {
|
2009-08-17 11:03:03 -04:00
|
|
|
removed.add(info);
|
|
|
|
|
data.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2016-01-21 19:50:02 +00:00
|
|
|
/**
|
2016-09-01 15:17:46 -07:00
|
|
|
* Updates the disabled flags of apps matching {@param matcher} based on {@param op}.
|
2016-01-21 19:50:02 +00:00
|
|
|
*/
|
2016-09-01 15:17:46 -07:00
|
|
|
public void updateDisabledFlags(ItemInfoMatcher matcher, FlagOp op) {
|
2016-01-21 19:50:02 +00:00
|
|
|
final List<AppInfo> data = this.data;
|
|
|
|
|
for (int i = data.size() - 1; i >= 0; i--) {
|
|
|
|
|
AppInfo info = data.get(i);
|
2016-10-10 10:41:41 -07:00
|
|
|
if (matcher.matches(info, info.componentName)) {
|
2016-03-15 09:16:30 -07:00
|
|
|
info.isDisabled = op.apply(info.isDisabled);
|
2016-01-21 19:50:02 +00:00
|
|
|
modified.add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 15:53:17 -08:00
|
|
|
public void updateIconsAndLabels(HashSet<String> packages, UserHandle user,
|
2015-05-06 16:53:21 -07:00
|
|
|
ArrayList<AppInfo> outUpdates) {
|
|
|
|
|
for (AppInfo info : data) {
|
|
|
|
|
if (info.user.equals(user) && packages.contains(info.componentName.getPackageName())) {
|
|
|
|
|
mIconCache.updateTitleAndIcon(info);
|
|
|
|
|
outUpdates.add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* Add and remove icons for this package which has been updated.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
public void updatePackage(Context context, String packageName, UserHandle user) {
|
2014-04-30 03:02:21 +01:00
|
|
|
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
|
|
|
|
|
final List<LauncherActivityInfoCompat> matches = launcherApps.getActivityList(packageName,
|
|
|
|
|
user);
|
2009-08-17 11:03:03 -04:00
|
|
|
if (matches.size() > 0) {
|
|
|
|
|
// Find disabled/removed activities and remove them from data and add them
|
|
|
|
|
// to the removed list.
|
2010-01-12 17:24:58 -08:00
|
|
|
for (int i = data.size() - 1; i >= 0; i--) {
|
2013-09-04 00:45:37 +02:00
|
|
|
final AppInfo applicationInfo = data.get(i);
|
2014-04-30 03:02:21 +01:00
|
|
|
if (user.equals(applicationInfo.user)
|
2016-09-09 15:47:55 -07:00
|
|
|
&& packageName.equals(applicationInfo.componentName.getPackageName())) {
|
|
|
|
|
if (!findActivity(matches, applicationInfo.componentName)) {
|
2009-08-17 11:03:03 -04:00
|
|
|
removed.add(applicationInfo);
|
|
|
|
|
data.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find enabled activities and add them to the adapter
|
|
|
|
|
// Also updates existing activities with new labels/icons
|
2014-10-06 16:23:56 -07:00
|
|
|
for (final LauncherActivityInfoCompat info : matches) {
|
2013-09-04 00:45:37 +02:00
|
|
|
AppInfo applicationInfo = findApplicationInfoLocked(
|
2014-04-30 03:02:21 +01:00
|
|
|
info.getComponentName().getPackageName(), user,
|
2014-07-09 11:30:12 -07:00
|
|
|
info.getComponentName().getClassName());
|
2009-08-17 11:03:03 -04:00
|
|
|
if (applicationInfo == null) {
|
2017-01-06 16:32:57 -08:00
|
|
|
add(new AppInfo(context, info, user), info);
|
2009-08-17 11:03:03 -04:00
|
|
|
} else {
|
2015-03-11 16:56:52 -07:00
|
|
|
mIconCache.getTitleAndIcon(applicationInfo, info, true /* useLowResIcon */);
|
2009-08-17 11:03:03 -04:00
|
|
|
modified.add(applicationInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-24 16:48:01 -07:00
|
|
|
} else {
|
|
|
|
|
// Remove all data for this package.
|
|
|
|
|
for (int i = data.size() - 1; i >= 0; i--) {
|
2013-09-04 00:45:37 +02:00
|
|
|
final AppInfo applicationInfo = data.get(i);
|
2014-04-30 03:02:21 +01:00
|
|
|
if (user.equals(applicationInfo.user)
|
2016-09-09 15:47:55 -07:00
|
|
|
&& packageName.equals(applicationInfo.componentName.getPackageName())) {
|
2010-07-24 16:48:01 -07:00
|
|
|
removed.add(applicationInfo);
|
2016-09-09 15:47:55 -07:00
|
|
|
mIconCache.remove(applicationInfo.componentName, user);
|
2010-07-24 16:48:01 -07:00
|
|
|
data.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether <em>apps</em> contains <em>component</em>.
|
|
|
|
|
*/
|
2014-04-30 03:02:21 +01:00
|
|
|
private static boolean findActivity(List<LauncherActivityInfoCompat> apps,
|
|
|
|
|
ComponentName component) {
|
|
|
|
|
for (LauncherActivityInfoCompat info : apps) {
|
|
|
|
|
if (info.getComponentName().equals(component)) {
|
2009-08-17 11:03:03 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
/**
|
|
|
|
|
* Query the launcher apps service for whether the supplied package has
|
|
|
|
|
* MAIN/LAUNCHER activities in the supplied package.
|
|
|
|
|
*/
|
|
|
|
|
static boolean packageHasActivities(Context context, String packageName,
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user) {
|
2014-04-30 03:02:21 +01:00
|
|
|
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
|
|
|
|
|
return launcherApps.getActivityList(packageName, user).size() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 15:43:37 -04:00
|
|
|
/**
|
|
|
|
|
* Returns whether <em>apps</em> contains <em>component</em>.
|
|
|
|
|
*/
|
2014-04-30 03:02:21 +01:00
|
|
|
private static boolean findActivity(ArrayList<AppInfo> apps, ComponentName component,
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user) {
|
2010-04-20 15:43:37 -04:00
|
|
|
final int N = apps.size();
|
2014-04-30 03:02:21 +01:00
|
|
|
for (int i = 0; i < N; i++) {
|
2013-09-04 00:45:37 +02:00
|
|
|
final AppInfo info = apps.get(i);
|
2014-04-30 03:02:21 +01:00
|
|
|
if (info.user.equals(user) && info.componentName.equals(component)) {
|
2010-04-20 15:43:37 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* Find an ApplicationInfo object for the given packageName and className.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
private AppInfo findApplicationInfoLocked(String packageName, UserHandle user,
|
2014-04-30 03:02:21 +01:00
|
|
|
String className) {
|
2013-09-04 00:45:37 +02:00
|
|
|
for (AppInfo info: data) {
|
2016-09-09 15:47:55 -07:00
|
|
|
if (user.equals(info.user) && packageName.equals(info.componentName.getPackageName())
|
|
|
|
|
&& className.equals(info.componentName.getClassName())) {
|
2009-08-17 11:03:03 -04:00
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|