2010-02-08 13:44:00 -08: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-09-21 14:41:05 -07:00
|
|
|
package com.android.launcher3.icons;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2022-03-17 12:13:13 -07:00
|
|
|
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
|
2019-08-15 14:53:41 -07:00
|
|
|
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
|
|
|
|
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
2021-09-24 12:39:55 +01:00
|
|
|
import static com.android.launcher3.widget.WidgetSections.NO_CATEGORY;
|
2019-08-15 14:53:41 -07:00
|
|
|
|
2021-08-18 14:53:50 -07:00
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
2020-02-06 11:28:01 -08:00
|
|
|
import android.content.ComponentName;
|
2012-02-13 14:27:42 -08:00
|
|
|
import android.content.Context;
|
2010-02-08 13:44:00 -08:00
|
|
|
import android.content.Intent;
|
2018-11-06 10:28:37 -08:00
|
|
|
import android.content.pm.ApplicationInfo;
|
2017-01-05 15:22:41 -08:00
|
|
|
import android.content.pm.LauncherActivityInfo;
|
2019-10-02 16:13:34 -07:00
|
|
|
import android.content.pm.LauncherApps;
|
2015-02-18 16:46:50 -08:00
|
|
|
import android.content.pm.PackageInfo;
|
2019-09-20 12:51:37 -07:00
|
|
|
import android.content.pm.PackageInstaller;
|
2010-02-08 13:44:00 -08:00
|
|
|
import android.content.pm.PackageManager;
|
2014-08-11 17:05:23 -07:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2019-10-23 17:47:28 +00:00
|
|
|
import android.content.pm.ShortcutInfo;
|
2021-08-18 14:53:50 -07:00
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.database.sqlite.SQLiteException;
|
2018-11-05 17:05:35 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.Process;
|
2021-08-18 14:53:50 -07:00
|
|
|
import android.os.Trace;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2021-08-18 14:53:50 -07:00
|
|
|
import android.text.TextUtils;
|
2014-02-10 12:16:54 -05:00
|
|
|
import android.util.Log;
|
2022-04-11 03:29:16 -07:00
|
|
|
import android.util.SparseArray;
|
2017-11-08 16:52:34 -08:00
|
|
|
|
2019-08-06 09:48:36 -07:00
|
|
|
import androidx.annotation.NonNull;
|
2022-04-11 03:29:16 -07:00
|
|
|
import androidx.annotation.Nullable;
|
2022-02-18 15:12:27 -08:00
|
|
|
import androidx.core.util.Pair;
|
2019-08-06 09:48:36 -07:00
|
|
|
|
2018-09-21 14:41:05 -07:00
|
|
|
import com.android.launcher3.InvariantDeviceProfile;
|
2018-11-06 10:28:37 -08:00
|
|
|
import com.android.launcher3.LauncherFiles;
|
2018-09-21 14:41:05 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2019-09-09 23:32:17 -07:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2018-11-05 17:05:35 -08:00
|
|
|
import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic;
|
2018-11-08 10:51:05 -08:00
|
|
|
import com.android.launcher3.icons.cache.BaseIconCache;
|
|
|
|
|
import com.android.launcher3.icons.cache.CachingLogic;
|
|
|
|
|
import com.android.launcher3.icons.cache.HandlerRunnable;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.AppInfo;
|
2021-08-18 14:53:50 -07:00
|
|
|
import com.android.launcher3.model.data.IconRequestInfo;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
|
|
|
|
import com.android.launcher3.model.data.PackageItemInfo;
|
|
|
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
2019-12-10 12:19:13 -08:00
|
|
|
import com.android.launcher3.pm.UserCache;
|
2019-10-23 17:47:28 +00:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutKey;
|
2018-11-06 10:28:37 -08:00
|
|
|
import com.android.launcher3.util.InstantAppResolver;
|
2019-09-20 12:51:37 -07:00
|
|
|
import com.android.launcher3.util.PackageUserKey;
|
2017-01-06 16:32:57 -08:00
|
|
|
import com.android.launcher3.util.Preconditions;
|
2021-09-24 12:39:55 +01:00
|
|
|
import com.android.launcher3.widget.WidgetSections;
|
|
|
|
|
import com.android.launcher3.widget.WidgetSections.WidgetSection;
|
2019-01-25 15:10:18 -08:00
|
|
|
|
2021-08-18 14:53:50 -07:00
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
2020-02-06 11:28:01 -08:00
|
|
|
import java.util.function.Predicate;
|
2019-01-25 15:10:18 -08:00
|
|
|
import java.util.function.Supplier;
|
2021-08-18 14:53:50 -07:00
|
|
|
import java.util.stream.Stream;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cache of application icons. Icons can be made from any thread.
|
|
|
|
|
*/
|
2018-09-24 10:51:52 -07:00
|
|
|
public class IconCache extends BaseIconCache {
|
2014-08-11 17:05:23 -07:00
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
private static final String TAG = "Launcher.IconCache";
|
|
|
|
|
|
2020-09-02 17:46:27 -07:00
|
|
|
private final Predicate<ItemInfoWithIcon> mIsUsingFallbackOrNonDefaultIconCheck = w ->
|
|
|
|
|
w.bitmap != null && (w.bitmap.isNullOrLowRes() || !isDefaultIcon(w.bitmap, w.user));
|
2020-02-06 11:28:01 -08:00
|
|
|
|
2018-11-05 17:05:35 -08:00
|
|
|
private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic;
|
|
|
|
|
private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic;
|
2019-10-23 17:47:28 +00:00
|
|
|
private final CachingLogic<ShortcutInfo> mShortcutCachingLogic;
|
2018-11-05 17:05:35 -08:00
|
|
|
|
2019-10-02 16:13:34 -07:00
|
|
|
private final LauncherApps mLauncherApps;
|
2019-12-10 12:19:13 -08:00
|
|
|
private final UserCache mUserManager;
|
2018-11-06 10:28:37 -08:00
|
|
|
private final InstantAppResolver mInstantAppResolver;
|
2018-11-08 10:51:05 -08:00
|
|
|
private final IconProvider mIconProvider;
|
2018-11-05 17:05:35 -08:00
|
|
|
|
2022-04-11 03:29:16 -07:00
|
|
|
private final SparseArray<BitmapInfo> mWidgetCategoryBitmapInfos;
|
|
|
|
|
|
2018-05-11 09:18:50 -07:00
|
|
|
private int mPendingIconRequestCount = 0;
|
|
|
|
|
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
public IconCache(Context context, InvariantDeviceProfile idp) {
|
2021-05-03 19:59:51 -07:00
|
|
|
this(context, idp, LauncherFiles.APP_ICONS_DB, new IconProvider(context));
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
}
|
|
|
|
|
|
2021-05-03 19:59:51 -07:00
|
|
|
public IconCache(Context context, InvariantDeviceProfile idp, String dbFileName,
|
|
|
|
|
IconProvider iconProvider) {
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
super(context, dbFileName, MODEL_EXECUTOR.getLooper(),
|
|
|
|
|
idp.fillResIconDpi, idp.iconBitmapSize, true /* inMemoryCache */);
|
2019-09-17 23:34:50 -07:00
|
|
|
mComponentWithLabelCachingLogic = new ComponentCachingLogic(context, false);
|
2019-08-06 09:48:36 -07:00
|
|
|
mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
|
2019-10-23 17:47:28 +00:00
|
|
|
mShortcutCachingLogic = new ShortcutCachingLogic();
|
2019-10-02 16:13:34 -07:00
|
|
|
mLauncherApps = mContext.getSystemService(LauncherApps.class);
|
2019-12-10 12:19:13 -08:00
|
|
|
mUserManager = UserCache.INSTANCE.get(mContext);
|
2018-11-06 10:28:37 -08:00
|
|
|
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
|
2021-05-03 19:59:51 -07:00
|
|
|
mIconProvider = iconProvider;
|
2022-04-11 03:29:16 -07:00
|
|
|
mWidgetCategoryBitmapInfos = new SparseArray<>();
|
2018-11-06 10:28:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected long getSerialNumberForUser(UserHandle user) {
|
|
|
|
|
return mUserManager.getSerialNumberForUser(user);
|
|
|
|
|
}
|
2018-11-05 17:05:35 -08:00
|
|
|
|
2018-11-06 10:28:37 -08:00
|
|
|
@Override
|
|
|
|
|
protected boolean isInstantApp(ApplicationInfo info) {
|
|
|
|
|
return mInstantAppResolver.isInstantApp(info);
|
2014-02-10 12:16:54 -05:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 10:51:05 -08:00
|
|
|
@Override
|
2021-04-23 11:40:58 -07:00
|
|
|
public BaseIconFactory getIconFactory() {
|
2018-11-08 10:51:05 -08:00
|
|
|
return LauncherIcons.obtain(mContext);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 16:46:50 -08:00
|
|
|
/**
|
|
|
|
|
* Updates the entries related to the given package in memory and persistent DB.
|
|
|
|
|
*/
|
2016-12-15 15:53:17 -08:00
|
|
|
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
|
2015-02-18 16:46:50 -08:00
|
|
|
removeIconsForPkg(packageName, user);
|
|
|
|
|
try {
|
|
|
|
|
PackageInfo info = mPackageManager.getPackageInfo(packageName,
|
|
|
|
|
PackageManager.GET_UNINSTALLED_PACKAGES);
|
|
|
|
|
long userSerial = mUserManager.getSerialNumberForUser(user);
|
2017-01-05 15:22:41 -08:00
|
|
|
for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
|
2018-11-05 17:05:35 -08:00
|
|
|
addIconToDBAndMemCache(app, mLauncherActivityInfoCachingLogic, info, userSerial,
|
2018-09-24 10:51:52 -07:00
|
|
|
false /*replace existing*/);
|
2015-02-18 16:46:50 -08:00
|
|
|
}
|
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
|
Log.d(TAG, "Package not found", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 19:42:14 -07:00
|
|
|
/**
|
|
|
|
|
* Closes the cache DB. This will clear any in-memory cache.
|
|
|
|
|
*/
|
|
|
|
|
public void close() {
|
2021-08-27 21:22:17 +00:00
|
|
|
// This will clear all pending updates
|
|
|
|
|
getUpdateHandler();
|
|
|
|
|
|
2021-05-19 19:42:14 -07:00
|
|
|
mIconDb.close();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
/**
|
2015-03-11 16:56:52 -07:00
|
|
|
* Fetches high-res icon for the provided ItemInfo and updates the caller when done.
|
2021-03-10 11:02:19 -06:00
|
|
|
*
|
2015-03-11 16:56:52 -07:00
|
|
|
* @return a request ID that can be used to cancel the request.
|
2010-02-08 13:44:00 -08:00
|
|
|
*/
|
2021-02-03 10:22:28 -08:00
|
|
|
public HandlerRunnable updateIconInBackground(final ItemInfoUpdateReceiver caller,
|
2017-01-03 16:52:43 -08:00
|
|
|
final ItemInfoWithIcon info) {
|
2018-05-11 09:18:50 -07:00
|
|
|
Preconditions.assertUIThread();
|
|
|
|
|
if (mPendingIconRequestCount <= 0) {
|
2019-08-15 14:53:41 -07:00
|
|
|
MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
|
2018-05-11 09:18:50 -07:00
|
|
|
}
|
2021-03-10 11:02:19 -06:00
|
|
|
mPendingIconRequestCount++;
|
2015-03-11 16:56:52 -07:00
|
|
|
|
2021-02-03 10:22:28 -08:00
|
|
|
HandlerRunnable<ItemInfoWithIcon> request = new HandlerRunnable<>(mWorkerHandler,
|
|
|
|
|
() -> {
|
|
|
|
|
if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
|
|
|
|
|
getTitleAndIcon(info, false);
|
|
|
|
|
} else if (info instanceof PackageItemInfo) {
|
|
|
|
|
getTitleAndIconForApp((PackageItemInfo) info, false);
|
|
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
},
|
|
|
|
|
MAIN_EXECUTOR,
|
|
|
|
|
caller::reapplyItemInfo,
|
|
|
|
|
this::onIconRequestEnd);
|
2018-05-11 09:18:50 -07:00
|
|
|
Utilities.postAsyncCallback(mWorkerHandler, request);
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onIconRequestEnd() {
|
2021-03-10 11:02:19 -06:00
|
|
|
mPendingIconRequestCount--;
|
2018-05-11 09:18:50 -07:00
|
|
|
if (mPendingIconRequestCount <= 0) {
|
2019-08-15 14:53:41 -07:00
|
|
|
MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
2018-05-11 09:18:50 -07:00
|
|
|
}
|
2015-03-11 16:56:52 -07:00
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2015-05-06 16:53:21 -07:00
|
|
|
/**
|
|
|
|
|
* Updates {@param application} only if a valid entry is found.
|
|
|
|
|
*/
|
|
|
|
|
public synchronized void updateTitleAndIcon(AppInfo application) {
|
2016-12-15 17:40:07 -08:00
|
|
|
CacheEntry entry = cacheLocked(application.componentName,
|
2019-01-25 15:10:18 -08:00
|
|
|
application.user, () -> null, mLauncherActivityInfoCachingLogic,
|
2018-09-26 12:00:30 -07:00
|
|
|
false, application.usingLowResIcon());
|
2019-10-25 13:41:28 -07:00
|
|
|
if (entry.bitmap != null && !isDefaultIcon(entry.bitmap, application.user)) {
|
2016-12-15 17:40:07 -08:00
|
|
|
applyCacheEntry(entry, application);
|
2015-05-06 16:53:21 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 16:56:52 -07:00
|
|
|
/**
|
2016-12-15 17:40:07 -08:00
|
|
|
* Fill in {@param info} with the icon and label for {@param activityInfo}
|
2015-03-11 16:56:52 -07:00
|
|
|
*/
|
2016-12-15 17:40:07 -08:00
|
|
|
public synchronized void getTitleAndIcon(ItemInfoWithIcon info,
|
2017-01-05 15:22:41 -08:00
|
|
|
LauncherActivityInfo activityInfo, boolean useLowResIcon) {
|
2016-12-15 17:40:07 -08:00
|
|
|
// If we already have activity info, no need to use package icon
|
2019-01-25 15:10:18 -08:00
|
|
|
getTitleAndIcon(info, () -> activityInfo, false, useLowResIcon);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
2020-02-06 11:28:01 -08:00
|
|
|
/**
|
|
|
|
|
* Fill in {@param info} with the icon for {@param si}
|
|
|
|
|
*/
|
|
|
|
|
public void getShortcutIcon(ItemInfoWithIcon info, ShortcutInfo si) {
|
2021-11-24 18:07:04 -08:00
|
|
|
getShortcutIcon(info, si, mIsUsingFallbackOrNonDefaultIconCheck);
|
2020-02-06 11:28:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fill in {@param info} with the icon and label for {@param si}. If the icon is not
|
|
|
|
|
* available, and fallback check returns true, it keeps the old icon.
|
|
|
|
|
*/
|
|
|
|
|
public <T extends ItemInfoWithIcon> void getShortcutIcon(T info, ShortcutInfo si,
|
|
|
|
|
@NonNull Predicate<T> fallbackIconCheck) {
|
|
|
|
|
BitmapInfo bitmapInfo;
|
|
|
|
|
if (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) {
|
|
|
|
|
bitmapInfo = cacheLocked(ShortcutKey.fromInfo(si).componentName, si.getUserHandle(),
|
|
|
|
|
() -> si, mShortcutCachingLogic, false, false).bitmap;
|
|
|
|
|
} else {
|
|
|
|
|
// If caching is disabled, load the full icon
|
|
|
|
|
bitmapInfo = mShortcutCachingLogic.loadIcon(mContext, si);
|
|
|
|
|
}
|
|
|
|
|
if (bitmapInfo.isNullOrLowRes()) {
|
|
|
|
|
bitmapInfo = getDefaultIcon(si.getUserHandle());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isDefaultIcon(bitmapInfo, si.getUserHandle()) && fallbackIconCheck.test(info)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-24 18:07:04 -08:00
|
|
|
info.bitmap = bitmapInfo.withBadgeInfo(getShortcutInfoBadge(si));
|
2020-02-06 11:28:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the badging info for the shortcut
|
|
|
|
|
*/
|
|
|
|
|
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
|
|
|
|
|
ComponentName cn = shortcutInfo.getActivity();
|
|
|
|
|
if (cn != null) {
|
|
|
|
|
// Get the app info for the source activity.
|
|
|
|
|
AppInfo appInfo = new AppInfo();
|
|
|
|
|
appInfo.user = shortcutInfo.getUserHandle();
|
|
|
|
|
appInfo.componentName = cn;
|
|
|
|
|
appInfo.intent = new Intent(Intent.ACTION_MAIN)
|
|
|
|
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
|
|
|
.setComponent(cn);
|
|
|
|
|
getTitleAndIcon(appInfo, false);
|
|
|
|
|
return appInfo.bitmap;
|
|
|
|
|
} else {
|
2021-09-24 12:39:55 +01:00
|
|
|
PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(),
|
|
|
|
|
shortcutInfo.getUserHandle());
|
2020-02-06 11:28:01 -08:00
|
|
|
getTitleAndIconForApp(pkgInfo, false);
|
|
|
|
|
return pkgInfo.bitmap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
/**
|
2016-12-15 17:40:07 -08:00
|
|
|
* Fill in {@param info} with the icon and label. If the
|
2015-02-18 16:46:50 -08:00
|
|
|
* corresponding activity is not found, it reverts to the package icon.
|
2014-08-29 17:20:55 -07:00
|
|
|
*/
|
2016-12-15 17:40:07 -08:00
|
|
|
public synchronized void getTitleAndIcon(ItemInfoWithIcon info, boolean useLowResIcon) {
|
2014-10-16 14:07:29 -07:00
|
|
|
// null info means not installed, but if we have a component from the intent then
|
|
|
|
|
// we should still look in the cache for restored app icons.
|
2016-12-15 17:40:07 -08:00
|
|
|
if (info.getTargetComponent() == null) {
|
2019-10-25 13:41:28 -07:00
|
|
|
info.bitmap = getDefaultIcon(info.user);
|
2016-12-15 17:40:07 -08:00
|
|
|
info.title = "";
|
|
|
|
|
info.contentDescription = "";
|
2014-10-16 14:07:29 -07:00
|
|
|
} else {
|
2018-07-09 16:47:01 -07:00
|
|
|
Intent intent = info.getIntent();
|
|
|
|
|
getTitleAndIcon(info, () -> mLauncherApps.resolveActivity(intent, info.user),
|
2016-12-15 17:40:07 -08:00
|
|
|
true, useLowResIcon);
|
2014-08-29 17:20:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 12:00:30 -07:00
|
|
|
public synchronized String getTitleNoCache(ComponentWithLabel info) {
|
2019-01-25 15:10:18 -08:00
|
|
|
CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info,
|
2018-11-05 17:05:35 -08:00
|
|
|
mComponentWithLabelCachingLogic, false /* usePackageIcon */,
|
2019-09-17 23:34:50 -07:00
|
|
|
true /* useLowResIcon */);
|
2018-09-26 12:00:30 -07:00
|
|
|
return Utilities.trim(entry.title);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 16:46:50 -08:00
|
|
|
/**
|
2019-03-27 16:03:06 -07:00
|
|
|
* Fill in {@param mWorkspaceItemInfo} with the icon and label for {@param info}
|
2015-02-18 16:46:50 -08:00
|
|
|
*/
|
2020-08-07 16:32:18 -07:00
|
|
|
public synchronized void getTitleAndIcon(
|
2016-12-15 17:40:07 -08:00
|
|
|
@NonNull ItemInfoWithIcon infoInOut,
|
2019-01-25 15:10:18 -08:00
|
|
|
@NonNull Supplier<LauncherActivityInfo> activityInfoProvider,
|
2016-12-15 17:40:07 -08:00
|
|
|
boolean usePkgIcon, boolean useLowResIcon) {
|
2018-09-26 12:00:30 -07:00
|
|
|
CacheEntry entry = cacheLocked(infoInOut.getTargetComponent(), infoInOut.user,
|
2021-03-10 11:02:19 -06:00
|
|
|
activityInfoProvider, mLauncherActivityInfoCachingLogic, usePkgIcon,
|
|
|
|
|
useLowResIcon);
|
2016-12-15 17:40:07 -08:00
|
|
|
applyCacheEntry(entry, infoInOut);
|
2015-02-18 16:46:50 -08:00
|
|
|
}
|
2014-08-29 17:20:55 -07:00
|
|
|
|
2021-08-18 14:53:50 -07:00
|
|
|
/**
|
|
|
|
|
* Creates an sql cursor for a query of a set of ItemInfoWithIcon icons and titles.
|
|
|
|
|
*
|
|
|
|
|
* @param iconRequestInfos List of IconRequestInfos representing titles and icons to query.
|
|
|
|
|
* @param user UserHandle all the given iconRequestInfos share
|
|
|
|
|
* @param useLowResIcons whether we should exclude the icon column from the sql results.
|
|
|
|
|
*/
|
|
|
|
|
private <T extends ItemInfoWithIcon> Cursor createBulkQueryCursor(
|
|
|
|
|
List<IconRequestInfo<T>> iconRequestInfos, UserHandle user, boolean useLowResIcons)
|
|
|
|
|
throws SQLiteException {
|
|
|
|
|
String[] queryParams = Stream.concat(
|
|
|
|
|
iconRequestInfos.stream()
|
|
|
|
|
.map(r -> r.itemInfo.getTargetComponent())
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.distinct()
|
|
|
|
|
.map(ComponentName::flattenToString),
|
|
|
|
|
Stream.of(Long.toString(getSerialNumberForUser(user)))).toArray(String[]::new);
|
|
|
|
|
String componentNameQuery = TextUtils.join(
|
|
|
|
|
",", Collections.nCopies(queryParams.length - 1, "?"));
|
|
|
|
|
|
|
|
|
|
return mIconDb.query(
|
|
|
|
|
useLowResIcons ? IconDB.COLUMNS_LOW_RES : IconDB.COLUMNS_HIGH_RES,
|
|
|
|
|
IconDB.COLUMN_COMPONENT
|
|
|
|
|
+ " IN ( " + componentNameQuery + " )"
|
|
|
|
|
+ " AND " + IconDB.COLUMN_USER + " = ?",
|
|
|
|
|
queryParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load and fill icons requested in iconRequestInfos using a single bulk sql query.
|
|
|
|
|
*/
|
|
|
|
|
public synchronized <T extends ItemInfoWithIcon> void getTitlesAndIconsInBulk(
|
|
|
|
|
List<IconRequestInfo<T>> iconRequestInfos) {
|
|
|
|
|
Map<Pair<UserHandle, Boolean>, List<IconRequestInfo<T>>> iconLoadSubsectionsMap =
|
|
|
|
|
iconRequestInfos.stream()
|
2022-02-18 15:12:27 -08:00
|
|
|
.filter(iconRequest -> {
|
2022-03-17 12:13:13 -07:00
|
|
|
if (iconRequest.itemInfo.getTargetComponent() == null) {
|
|
|
|
|
Log.i(TAG,
|
|
|
|
|
"Skipping Item info with null component name: "
|
|
|
|
|
+ iconRequest.itemInfo);
|
|
|
|
|
iconRequest.itemInfo.bitmap = getDefaultIcon(
|
|
|
|
|
iconRequest.itemInfo.user);
|
|
|
|
|
return false;
|
2022-02-18 15:12:27 -08:00
|
|
|
}
|
2022-03-17 12:13:13 -07:00
|
|
|
return true;
|
2022-02-18 15:12:27 -08:00
|
|
|
})
|
2021-08-18 14:53:50 -07:00
|
|
|
.collect(groupingBy(iconRequest ->
|
|
|
|
|
Pair.create(iconRequest.itemInfo.user, iconRequest.useLowResIcon)));
|
|
|
|
|
|
|
|
|
|
Trace.beginSection("loadIconsInBulk");
|
|
|
|
|
iconLoadSubsectionsMap.forEach((sectionKey, filteredList) -> {
|
|
|
|
|
Map<ComponentName, List<IconRequestInfo<T>>> duplicateIconRequestsMap =
|
|
|
|
|
filteredList.stream()
|
2022-03-17 12:13:13 -07:00
|
|
|
.filter(iconRequest -> {
|
|
|
|
|
// Filter out icons that should not share the same bitmap and title
|
|
|
|
|
if (iconRequest.itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
|
|
|
|
|
Log.e(TAG,
|
|
|
|
|
"Skipping Item info for deep shortcut: "
|
|
|
|
|
+ iconRequest.itemInfo,
|
|
|
|
|
new IllegalStateException());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
})
|
2021-08-18 14:53:50 -07:00
|
|
|
.collect(groupingBy(iconRequest ->
|
|
|
|
|
iconRequest.itemInfo.getTargetComponent()));
|
|
|
|
|
|
|
|
|
|
Trace.beginSection("loadIconSubsectionInBulk");
|
2022-01-28 13:44:49 -08:00
|
|
|
loadIconSubsection(sectionKey, filteredList, duplicateIconRequestsMap);
|
|
|
|
|
Trace.endSection();
|
|
|
|
|
});
|
|
|
|
|
Trace.endSection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T extends ItemInfoWithIcon> void loadIconSubsection(
|
|
|
|
|
Pair<UserHandle, Boolean> sectionKey,
|
|
|
|
|
List<IconRequestInfo<T>> filteredList,
|
|
|
|
|
Map<ComponentName, List<IconRequestInfo<T>>> duplicateIconRequestsMap) {
|
|
|
|
|
Trace.beginSection("loadIconSubsectionWithDatabase");
|
|
|
|
|
try (Cursor c = createBulkQueryCursor(
|
|
|
|
|
filteredList,
|
|
|
|
|
/* user = */ sectionKey.first,
|
|
|
|
|
/* useLowResIcons = */ sectionKey.second)) {
|
|
|
|
|
// Database title and icon loading
|
|
|
|
|
int componentNameColumnIndex = c.getColumnIndexOrThrow(IconDB.COLUMN_COMPONENT);
|
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
|
ComponentName cn = ComponentName.unflattenFromString(
|
|
|
|
|
c.getString(componentNameColumnIndex));
|
|
|
|
|
List<IconRequestInfo<T>> duplicateIconRequests =
|
|
|
|
|
duplicateIconRequestsMap.get(cn);
|
|
|
|
|
|
|
|
|
|
if (cn != null) {
|
|
|
|
|
CacheEntry entry = cacheLocked(
|
|
|
|
|
cn,
|
|
|
|
|
/* user = */ sectionKey.first,
|
|
|
|
|
() -> duplicateIconRequests.get(0).launcherActivityInfo,
|
|
|
|
|
mLauncherActivityInfoCachingLogic,
|
|
|
|
|
c,
|
|
|
|
|
/* usePackageIcon= */ false,
|
|
|
|
|
/* useLowResIcons = */ sectionKey.second);
|
|
|
|
|
|
|
|
|
|
for (IconRequestInfo<T> iconRequest : duplicateIconRequests) {
|
|
|
|
|
applyCacheEntry(entry, iconRequest.itemInfo);
|
2021-08-18 14:53:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 13:44:49 -08:00
|
|
|
} catch (SQLiteException e) {
|
|
|
|
|
Log.d(TAG, "Error reading icon cache", e);
|
|
|
|
|
} finally {
|
|
|
|
|
Trace.endSection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Trace.beginSection("loadIconSubsectionWithFallback");
|
|
|
|
|
// Fallback title and icon loading
|
|
|
|
|
for (ComponentName cn : duplicateIconRequestsMap.keySet()) {
|
|
|
|
|
IconRequestInfo<T> iconRequestInfo = duplicateIconRequestsMap.get(cn).get(0);
|
|
|
|
|
ItemInfoWithIcon itemInfo = iconRequestInfo.itemInfo;
|
|
|
|
|
BitmapInfo icon = itemInfo.bitmap;
|
|
|
|
|
boolean loadFallbackTitle = TextUtils.isEmpty(itemInfo.title);
|
|
|
|
|
boolean loadFallbackIcon = icon == null
|
|
|
|
|
|| isDefaultIcon(icon, itemInfo.user)
|
|
|
|
|
|| icon == BitmapInfo.LOW_RES_INFO;
|
|
|
|
|
|
|
|
|
|
if (loadFallbackTitle || loadFallbackIcon) {
|
|
|
|
|
Log.i(TAG,
|
|
|
|
|
"Database bulk icon loading failed, using fallback bulk icon loading "
|
|
|
|
|
+ "for: " + cn);
|
|
|
|
|
CacheEntry entry = new CacheEntry();
|
|
|
|
|
LauncherActivityInfo lai = iconRequestInfo.launcherActivityInfo;
|
|
|
|
|
|
|
|
|
|
// Fill fields that are not updated below so they are not subsequently
|
|
|
|
|
// deleted.
|
|
|
|
|
entry.title = itemInfo.title;
|
|
|
|
|
if (icon != null) {
|
|
|
|
|
entry.bitmap = icon;
|
|
|
|
|
}
|
|
|
|
|
entry.contentDescription = itemInfo.contentDescription;
|
|
|
|
|
|
|
|
|
|
if (loadFallbackIcon) {
|
|
|
|
|
loadFallbackIcon(
|
|
|
|
|
lai,
|
|
|
|
|
entry,
|
|
|
|
|
mLauncherActivityInfoCachingLogic,
|
|
|
|
|
/* usePackageIcon= */ false,
|
|
|
|
|
/* usePackageTitle= */ loadFallbackTitle,
|
|
|
|
|
cn,
|
|
|
|
|
sectionKey.first);
|
|
|
|
|
}
|
2022-03-07 12:46:36 -08:00
|
|
|
if (loadFallbackTitle && TextUtils.isEmpty(entry.title) && lai != null) {
|
2022-01-28 13:44:49 -08:00
|
|
|
loadFallbackTitle(
|
|
|
|
|
lai,
|
|
|
|
|
entry,
|
|
|
|
|
mLauncherActivityInfoCachingLogic,
|
|
|
|
|
sectionKey.first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (IconRequestInfo<T> iconRequest : duplicateIconRequestsMap.get(cn)) {
|
|
|
|
|
applyCacheEntry(entry, iconRequest.itemInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-18 14:53:50 -07:00
|
|
|
Trace.endSection();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 17:05:35 -08:00
|
|
|
/**
|
|
|
|
|
* Fill in {@param infoInOut} with the corresponding icon and label.
|
|
|
|
|
*/
|
|
|
|
|
public synchronized void getTitleAndIconForApp(
|
|
|
|
|
PackageItemInfo infoInOut, boolean useLowResIcon) {
|
|
|
|
|
CacheEntry entry = getEntryForPackageLocked(
|
|
|
|
|
infoInOut.packageName, infoInOut.user, useLowResIcon);
|
|
|
|
|
applyCacheEntry(entry, infoInOut);
|
2022-04-11 03:29:16 -07:00
|
|
|
if (infoInOut.widgetCategory == NO_CATEGORY) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WidgetSection widgetSection = WidgetSections.getWidgetSections(mContext)
|
|
|
|
|
.get(infoInOut.widgetCategory);
|
|
|
|
|
infoInOut.title = mContext.getString(widgetSection.mSectionTitle);
|
|
|
|
|
infoInOut.contentDescription = mPackageManager.getUserBadgedLabel(
|
|
|
|
|
infoInOut.title, infoInOut.user);
|
|
|
|
|
final BitmapInfo cachedBitmap = mWidgetCategoryBitmapInfos.get(infoInOut.widgetCategory);
|
|
|
|
|
if (cachedBitmap != null) {
|
|
|
|
|
infoInOut.bitmap = getBadgedIcon(cachedBitmap, infoInOut.user);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
|
|
|
|
|
final BitmapInfo tempBitmap = li.createBadgedIconBitmap(
|
|
|
|
|
mContext.getDrawable(widgetSection.mSectionDrawable),
|
|
|
|
|
new BaseIconFactory.IconOptions().setShrinkNonAdaptiveIcons(false));
|
|
|
|
|
mWidgetCategoryBitmapInfos.put(infoInOut.widgetCategory, tempBitmap);
|
|
|
|
|
infoInOut.bitmap = getBadgedIcon(tempBitmap, infoInOut.user);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "Error initializing bitmap for icons with widget category", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private synchronized BitmapInfo getBadgedIcon(@Nullable final BitmapInfo bitmap,
|
|
|
|
|
@NonNull final UserHandle user) {
|
|
|
|
|
if (bitmap == null) {
|
|
|
|
|
return getDefaultIcon(user);
|
2021-04-08 22:32:57 +01:00
|
|
|
}
|
2022-04-11 03:29:16 -07:00
|
|
|
return bitmap.withFlags(getUserFlagOpLocked(user));
|
2018-11-05 17:05:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void applyCacheEntry(CacheEntry entry, ItemInfoWithIcon info) {
|
|
|
|
|
info.title = Utilities.trim(entry.title);
|
|
|
|
|
info.contentDescription = entry.contentDescription;
|
2019-10-25 13:41:28 -07:00
|
|
|
info.bitmap = (entry.bitmap == null) ? getDefaultIcon(info.user) : entry.bitmap;
|
2018-11-05 17:05:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Drawable getFullResIcon(LauncherActivityInfo info) {
|
2019-10-24 15:59:49 -07:00
|
|
|
return mIconProvider.getIcon(info, mIconDpi);
|
2018-11-05 17:05:35 -08:00
|
|
|
}
|
|
|
|
|
|
2019-09-20 12:51:37 -07:00
|
|
|
public void updateSessionCache(PackageUserKey key, PackageInstaller.SessionInfo info) {
|
2021-03-10 11:02:19 -06:00
|
|
|
cachePackageInstallInfo(key.mPackageName, key.mUser, info.getAppIcon(),
|
|
|
|
|
info.getAppLabel());
|
2019-09-20 12:51:37 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 10:51:05 -08:00
|
|
|
@Override
|
|
|
|
|
protected String getIconSystemState(String packageName) {
|
2021-06-03 16:47:54 -07:00
|
|
|
return mIconProvider.getSystemStateForPackage(mSystemState, packageName);
|
2018-11-08 10:51:05 -08:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 16:52:43 -08:00
|
|
|
/**
|
|
|
|
|
* Interface for receiving itemInfo with high-res icon.
|
|
|
|
|
*/
|
|
|
|
|
public interface ItemInfoUpdateReceiver {
|
|
|
|
|
|
|
|
|
|
void reapplyItemInfo(ItemInfoWithIcon info);
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|