Loading iconloaderlib/src/com/android/launcher3/icons/cache/CachingLogic.java +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.icons.cache; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageInfo; import android.os.LocaleList; import android.os.UserHandle; Loading @@ -41,4 +42,11 @@ public interface CachingLogic<T> { default String getKeywords(T object, LocaleList localeList) { return null; } /** * Returns the timestamp the entry was last updated in cache. */ default long getLastUpdatedTime(T object, PackageInfo info) { return info.lastUpdateTime; } } iconloaderlib/src/com/android/launcher3/icons/cache/IconCacheUpdateHandler.java +3 −3 Original line number Diff line number Diff line Loading @@ -171,8 +171,9 @@ public class IconCacheUpdateHandler { long updateTime = c.getLong(indexLastUpdate); int version = c.getInt(indexVersion); T app = componentMap.remove(component); if (version == info.versionCode && updateTime == info.lastUpdateTime && TextUtils.equals(c.getString(systemStateIndex), if (version == info.versionCode && updateTime == cachingLogic.getLastUpdatedTime(app, info) && TextUtils.equals(c.getString(systemStateIndex), mIconCache.getIconSystemState(info.packageName))) { if (mFilterMode == MODE_CLEAR_VALID_ITEMS) { Loading Loading @@ -231,7 +232,6 @@ public class IconCacheUpdateHandler { } } /** * A runnable that updates invalid icons and adds missing icons in the DB for the provided * LauncherActivityInfo list. Items are updated/added one at a time, so that the Loading src/com/android/launcher3/icons/IconCache.java +12 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.pm.LauncherActivityInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Process; Loading @@ -48,6 +49,7 @@ import com.android.launcher3.icons.cache.BaseIconCache; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.icons.cache.HandlerRunnable; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.InstantAppResolver; import com.android.launcher3.util.Preconditions; Loading @@ -62,6 +64,7 @@ public class IconCache extends BaseIconCache { private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic; private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic; private final CachingLogic<ShortcutInfo> mShortcutCachingLogic; private final LauncherAppsCompat mLauncherApps; private final UserManagerCompat mUserManager; Loading @@ -75,6 +78,7 @@ public class IconCache extends BaseIconCache { inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */); mComponentWithLabelCachingLogic = new ComponentCachingLogic(context); mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context); mShortcutCachingLogic = new ShortcutCachingLogic(); mLauncherApps = LauncherAppsCompat.getInstance(mContext); mUserManager = UserManagerCompat.getInstance(mContext); mInstantAppResolver = InstantAppResolver.newInstance(mContext); Loading Loading @@ -172,6 +176,14 @@ public class IconCache extends BaseIconCache { getTitleAndIcon(info, () -> activityInfo, false, useLowResIcon); } /** * Fill in info with the icon and label for deep shortcut. */ public synchronized CacheEntry getDeepShortcutTitleAndIcon(ShortcutInfo info) { return cacheLocked(ShortcutKey.fromInfo(info).componentName, info.getUserHandle(), () -> info, mShortcutCachingLogic, false, false); } /** * Fill in {@param info} with the icon and label. If the * corresponding activity is not found, it reverts to the package icon. Loading src/com/android/launcher3/icons/LauncherIcons.java +6 −8 Original line number Diff line number Diff line Loading @@ -21,9 +21,10 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Process; import androidx.annotation.Nullable; import com.android.launcher3.AppInfo; import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.InvariantDeviceProfile; Loading @@ -31,14 +32,12 @@ import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.graphics.IconShape; import com.android.launcher3.icons.cache.BaseIconCache; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.util.Themes; import java.util.function.Supplier; import androidx.annotation.Nullable; /** * Wrapper class to provide access to {@link BaseIconFactory} and also to provide pool of this class * that are threadsafe. Loading Loading @@ -126,13 +125,12 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) { Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext) .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi); IconCache cache = LauncherAppState.getInstance(mContext).getIconCache(); BaseIconCache.CacheEntry entry = cache.getDeepShortcutTitleAndIcon(shortcutInfo); final Bitmap unbadgedBitmap; if (unbadgedDrawable != null) { unbadgedBitmap = createScaledBitmapWithoutShadow(unbadgedDrawable, 0); if (entry.icon != null) { unbadgedBitmap = entry.icon; } else { if (fallbackIconProvider != null) { // Fallback icons are already badged and with appropriate shadow Loading src/com/android/launcher3/icons/ShortcutCachingLogic.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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. */ package com.android.launcher3.icons; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.os.UserHandle; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutKey; /** * Caching logic for shortcuts. */ public class ShortcutCachingLogic implements CachingLogic<ShortcutInfo> { @Override public ComponentName getComponent(ShortcutInfo info) { return ShortcutKey.fromInfo(info).componentName; } @Override public UserHandle getUser(ShortcutInfo info) { return info.getUserHandle(); } @Override public CharSequence getLabel(ShortcutInfo info) { return info.getShortLabel(); } @Override public void loadIcon(Context context, ShortcutInfo info, BitmapInfo target) { LauncherIcons li = LauncherIcons.obtain(context); Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context) .getShortcutIconDrawable(info, LauncherAppState.getIDP(context).fillResIconDpi); if (unbadgedDrawable != null) { target.icon = li.createScaledBitmapWithoutShadow(unbadgedDrawable, 0); } li.recycle(); } @Override public long getLastUpdatedTime(ShortcutInfo shortcutInfo, PackageInfo info) { if (shortcutInfo == null) return info.lastUpdateTime; return Math.max(shortcutInfo.getLastChangedTimestamp(), info.lastUpdateTime); } } Loading
iconloaderlib/src/com/android/launcher3/icons/cache/CachingLogic.java +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.icons.cache; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageInfo; import android.os.LocaleList; import android.os.UserHandle; Loading @@ -41,4 +42,11 @@ public interface CachingLogic<T> { default String getKeywords(T object, LocaleList localeList) { return null; } /** * Returns the timestamp the entry was last updated in cache. */ default long getLastUpdatedTime(T object, PackageInfo info) { return info.lastUpdateTime; } }
iconloaderlib/src/com/android/launcher3/icons/cache/IconCacheUpdateHandler.java +3 −3 Original line number Diff line number Diff line Loading @@ -171,8 +171,9 @@ public class IconCacheUpdateHandler { long updateTime = c.getLong(indexLastUpdate); int version = c.getInt(indexVersion); T app = componentMap.remove(component); if (version == info.versionCode && updateTime == info.lastUpdateTime && TextUtils.equals(c.getString(systemStateIndex), if (version == info.versionCode && updateTime == cachingLogic.getLastUpdatedTime(app, info) && TextUtils.equals(c.getString(systemStateIndex), mIconCache.getIconSystemState(info.packageName))) { if (mFilterMode == MODE_CLEAR_VALID_ITEMS) { Loading Loading @@ -231,7 +232,6 @@ public class IconCacheUpdateHandler { } } /** * A runnable that updates invalid icons and adds missing icons in the DB for the provided * LauncherActivityInfo list. Items are updated/added one at a time, so that the Loading
src/com/android/launcher3/icons/IconCache.java +12 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.pm.LauncherActivityInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Process; Loading @@ -48,6 +49,7 @@ import com.android.launcher3.icons.cache.BaseIconCache; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.icons.cache.HandlerRunnable; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.InstantAppResolver; import com.android.launcher3.util.Preconditions; Loading @@ -62,6 +64,7 @@ public class IconCache extends BaseIconCache { private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic; private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic; private final CachingLogic<ShortcutInfo> mShortcutCachingLogic; private final LauncherAppsCompat mLauncherApps; private final UserManagerCompat mUserManager; Loading @@ -75,6 +78,7 @@ public class IconCache extends BaseIconCache { inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */); mComponentWithLabelCachingLogic = new ComponentCachingLogic(context); mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context); mShortcutCachingLogic = new ShortcutCachingLogic(); mLauncherApps = LauncherAppsCompat.getInstance(mContext); mUserManager = UserManagerCompat.getInstance(mContext); mInstantAppResolver = InstantAppResolver.newInstance(mContext); Loading Loading @@ -172,6 +176,14 @@ public class IconCache extends BaseIconCache { getTitleAndIcon(info, () -> activityInfo, false, useLowResIcon); } /** * Fill in info with the icon and label for deep shortcut. */ public synchronized CacheEntry getDeepShortcutTitleAndIcon(ShortcutInfo info) { return cacheLocked(ShortcutKey.fromInfo(info).componentName, info.getUserHandle(), () -> info, mShortcutCachingLogic, false, false); } /** * Fill in {@param info} with the icon and label. If the * corresponding activity is not found, it reverts to the package icon. Loading
src/com/android/launcher3/icons/LauncherIcons.java +6 −8 Original line number Diff line number Diff line Loading @@ -21,9 +21,10 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Process; import androidx.annotation.Nullable; import com.android.launcher3.AppInfo; import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.InvariantDeviceProfile; Loading @@ -31,14 +32,12 @@ import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.graphics.IconShape; import com.android.launcher3.icons.cache.BaseIconCache; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.util.Themes; import java.util.function.Supplier; import androidx.annotation.Nullable; /** * Wrapper class to provide access to {@link BaseIconFactory} and also to provide pool of this class * that are threadsafe. Loading Loading @@ -126,13 +125,12 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) { Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext) .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi); IconCache cache = LauncherAppState.getInstance(mContext).getIconCache(); BaseIconCache.CacheEntry entry = cache.getDeepShortcutTitleAndIcon(shortcutInfo); final Bitmap unbadgedBitmap; if (unbadgedDrawable != null) { unbadgedBitmap = createScaledBitmapWithoutShadow(unbadgedDrawable, 0); if (entry.icon != null) { unbadgedBitmap = entry.icon; } else { if (fallbackIconProvider != null) { // Fallback icons are already badged and with appropriate shadow Loading
src/com/android/launcher3/icons/ShortcutCachingLogic.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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. */ package com.android.launcher3.icons; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.os.UserHandle; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutKey; /** * Caching logic for shortcuts. */ public class ShortcutCachingLogic implements CachingLogic<ShortcutInfo> { @Override public ComponentName getComponent(ShortcutInfo info) { return ShortcutKey.fromInfo(info).componentName; } @Override public UserHandle getUser(ShortcutInfo info) { return info.getUserHandle(); } @Override public CharSequence getLabel(ShortcutInfo info) { return info.getShortLabel(); } @Override public void loadIcon(Context context, ShortcutInfo info, BitmapInfo target) { LauncherIcons li = LauncherIcons.obtain(context); Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context) .getShortcutIconDrawable(info, LauncherAppState.getIDP(context).fillResIconDpi); if (unbadgedDrawable != null) { target.icon = li.createScaledBitmapWithoutShadow(unbadgedDrawable, 0); } li.recycle(); } @Override public long getLastUpdatedTime(ShortcutInfo shortcutInfo, PackageInfo info) { if (shortcutInfo == null) return info.lastUpdateTime; return Math.max(shortcutInfo.getLastChangedTimestamp(), info.lastUpdateTime); } }