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
|
|
|
|
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;
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
import android.os.UserHandle;
|
2014-02-10 12:16:54 -05:00
|
|
|
import android.util.Log;
|
2017-11-08 16:52:34 -08:00
|
|
|
|
2019-08-06 09:48:36 -07:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
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;
|
2021-04-08 22:32:57 +01:00
|
|
|
import com.android.launcher3.R;
|
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;
|
|
|
|
|
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;
|
2019-01-25 15:10:18 -08:00
|
|
|
|
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;
|
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
|
|
|
|
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;
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2020-09-02 17:46:27 -07:00
|
|
|
getShortcutIcon(info, si, true, mIsUsingFallbackOrNonDefaultIconCheck);
|
2020-02-06 11:28:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fill in {@param info} with an unbadged icon for {@param si}
|
|
|
|
|
*/
|
|
|
|
|
public void getUnbadgedShortcutIcon(ItemInfoWithIcon info, ShortcutInfo si) {
|
2020-09-02 17:46:27 -07:00
|
|
|
getShortcutIcon(info, si, false, 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) {
|
|
|
|
|
getShortcutIcon(info, si, true /* use badged */, fallbackIconCheck);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private synchronized <T extends ItemInfoWithIcon> void getShortcutIcon(T info, ShortcutInfo si,
|
|
|
|
|
boolean useBadged, @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;
|
|
|
|
|
}
|
|
|
|
|
info.bitmap = bitmapInfo;
|
|
|
|
|
if (useBadged) {
|
|
|
|
|
BitmapInfo badgeInfo = getShortcutInfoBadge(si);
|
|
|
|
|
try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
|
|
|
|
|
info.bitmap = li.badgeBitmap(info.bitmap.icon, badgeInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 {
|
|
|
|
|
PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
|
|
|
|
|
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
|
|
|
|
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);
|
2021-04-08 22:32:57 +01:00
|
|
|
if (infoInOut.category == PackageItemInfo.CONVERSATIONS) {
|
|
|
|
|
infoInOut.title = mContext.getString(R.string.widget_category_conversations);
|
|
|
|
|
infoInOut.contentDescription = mPackageManager.getUserBadgedLabel(
|
|
|
|
|
infoInOut.title, infoInOut.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) {
|
2019-09-09 23:32:17 -07:00
|
|
|
return mIconProvider.getSystemStateForPackage(mSystemState, packageName)
|
|
|
|
|
+ ",flags_asi:" + FeatureFlags.APP_SEARCH_IMPROVEMENTS.get();
|
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
|
|
|
}
|