diff --git a/quickstep/src/com/android/launcher3/appprediction/InstantAppItemInfo.java b/quickstep/src/com/android/launcher3/appprediction/InstantAppItemInfo.java index 9c3b8816cb..8baee004cc 100644 --- a/quickstep/src/com/android/launcher3/appprediction/InstantAppItemInfo.java +++ b/quickstep/src/com/android/launcher3/appprediction/InstantAppItemInfo.java @@ -22,6 +22,8 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import androidx.annotation.NonNull; + import com.android.launcher3.LauncherSettings; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; @@ -33,11 +35,13 @@ public class InstantAppItemInfo extends AppInfo { this.componentName = new ComponentName(packageName, COMPONENT_CLASS_MARKER); } + @NonNull @Override public ComponentName getTargetComponent() { return componentName; } + @NonNull @Override public WorkspaceItemInfo makeWorkspaceItem(Context context) { WorkspaceItemInfo workspaceItemInfo = super.makeWorkspaceItem(context); diff --git a/src/com/android/launcher3/icons/ComponentWithLabel.java b/src/com/android/launcher3/icons/ComponentWithLabel.java index 372c59166e..30575fcbe5 100644 --- a/src/com/android/launcher3/icons/ComponentWithLabel.java +++ b/src/com/android/launcher3/icons/ComponentWithLabel.java @@ -20,6 +20,8 @@ import android.content.Context; import android.content.pm.PackageManager; import android.os.UserHandle; +import androidx.annotation.NonNull; + import com.android.launcher3.icons.cache.CachingLogic; public interface ComponentWithLabel { @@ -42,22 +44,26 @@ public interface ComponentWithLabel { } @Override - public ComponentName getComponent(T object) { + @NonNull + public ComponentName getComponent(@NonNull T object) { return object.getComponent(); } + @NonNull @Override - public UserHandle getUser(T object) { + public UserHandle getUser(@NonNull T object) { return object.getUser(); } + @NonNull @Override - public CharSequence getLabel(T object) { + public CharSequence getLabel(@NonNull T object) { return object.getLabel(mPackageManager); } + @NonNull @Override - public BitmapInfo loadIcon(Context context, T object) { + public BitmapInfo loadIcon(@NonNull Context context, @NonNull T object) { return BitmapInfo.LOW_RES_INFO; } diff --git a/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java b/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java index c8606b1002..0a52dd7191 100644 --- a/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java +++ b/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java @@ -41,7 +41,8 @@ public interface ComponentWithLabelAndIcon extends ComponentWithLabel { @NonNull @Override - public BitmapInfo loadIcon(Context context, ComponentWithLabelAndIcon object) { + public BitmapInfo loadIcon(@NonNull Context context, + @NonNull ComponentWithLabelAndIcon object) { Drawable d = object.getFullResIcon(LauncherAppState.getInstance(context) .getIconCache()); if (d == null) { diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java index 7621dc206b..0b4a4a53d4 100644 --- a/src/com/android/launcher3/icons/IconCache.java +++ b/src/com/android/launcher3/icons/IconCache.java @@ -118,15 +118,16 @@ public class IconCache extends BaseIconCache { } @Override - protected long getSerialNumberForUser(UserHandle user) { + protected long getSerialNumberForUser(@NonNull UserHandle user) { return mUserManager.getSerialNumberForUser(user); } @Override - protected boolean isInstantApp(ApplicationInfo info) { + protected boolean isInstantApp(@NonNull ApplicationInfo info) { return mInstantAppResolver.isInstantApp(info); } + @NonNull @Override public BaseIconFactory getIconFactory() { return LauncherIcons.obtain(mContext); @@ -135,7 +136,8 @@ public class IconCache extends BaseIconCache { /** * Updates the entries related to the given package in memory and persistent DB. */ - public synchronized void updateIconsForPkg(String packageName, UserHandle user) { + public synchronized void updateIconsForPkg(@NonNull final String packageName, + @NonNull final UserHandle user) { removeIconsForPkg(packageName, user); try { PackageInfo info = mPackageManager.getPackageInfo(packageName, @@ -471,7 +473,7 @@ public class IconCache extends BaseIconCache { * Fill in {@param infoInOut} with the corresponding icon and label. */ public synchronized void getTitleAndIconForApp( - PackageItemInfo infoInOut, boolean useLowResIcon) { + @NonNull final PackageItemInfo infoInOut, final boolean useLowResIcon) { CacheEntry entry = getEntryForPackageLocked( infoInOut.packageName, infoInOut.user, useLowResIcon); applyCacheEntry(entry, infoInOut); @@ -510,10 +512,16 @@ public class IconCache extends BaseIconCache { return bitmap.withFlags(getUserFlagOpLocked(user)); } - protected void applyCacheEntry(CacheEntry entry, ItemInfoWithIcon info) { + protected void applyCacheEntry(@NonNull final CacheEntry entry, + @NonNull final ItemInfoWithIcon info) { info.title = Utilities.trim(entry.title); info.contentDescription = entry.contentDescription; - info.bitmap = (entry.bitmap == null) ? getDefaultIcon(info.user) : entry.bitmap; + info.bitmap = entry.bitmap; + if (entry.bitmap == null) { + // TODO: entry.bitmap can never be null, so this should not happen at all. + Log.wtf(TAG, "Cannot find bitmap from the cache, default icon was loaded."); + info.bitmap = getDefaultIcon(info.user); + } } public Drawable getFullResIcon(LauncherActivityInfo info) { @@ -526,6 +534,7 @@ public class IconCache extends BaseIconCache { } @Override + @NonNull protected String getIconSystemState(String packageName) { return mIconProvider.getSystemStateForPackage(mSystemState, packageName); } diff --git a/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java b/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java index 4b8c1ad590..406f69758c 100644 --- a/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java +++ b/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java @@ -20,6 +20,8 @@ import android.content.Context; import android.content.pm.LauncherActivityInfo; import android.os.UserHandle; +import androidx.annotation.NonNull; + import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.icons.BaseIconFactory.IconOptions; @@ -40,23 +42,27 @@ public class LauncherActivityCachingLogic R.string.launcher_activity_logic_class); } + @NonNull @Override - public ComponentName getComponent(LauncherActivityInfo object) { + public ComponentName getComponent(@NonNull LauncherActivityInfo object) { return object.getComponentName(); } + @NonNull @Override - public UserHandle getUser(LauncherActivityInfo object) { + public UserHandle getUser(@NonNull LauncherActivityInfo object) { return object.getUser(); } + @NonNull @Override - public CharSequence getLabel(LauncherActivityInfo object) { + public CharSequence getLabel(@NonNull LauncherActivityInfo object) { return object.getLabel(); } + @NonNull @Override - public BitmapInfo loadIcon(Context context, LauncherActivityInfo object) { + public BitmapInfo loadIcon(@NonNull Context context, @NonNull LauncherActivityInfo object) { try (LauncherIcons li = LauncherIcons.obtain(context)) { return li.createBadgedIconBitmap(LauncherAppState.getInstance(context) .getIconProvider().getIcon(object, li.mFillResIconDpi), diff --git a/src/com/android/launcher3/icons/ShortcutCachingLogic.java b/src/com/android/launcher3/icons/ShortcutCachingLogic.java index 1e46344725..4890ba6d8a 100644 --- a/src/com/android/launcher3/icons/ShortcutCachingLogic.java +++ b/src/com/android/launcher3/icons/ShortcutCachingLogic.java @@ -29,6 +29,7 @@ import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.cache.CachingLogic; @@ -43,29 +44,34 @@ public class ShortcutCachingLogic implements CachingLogic { private static final String TAG = "ShortcutCachingLogic"; @Override - public ComponentName getComponent(ShortcutInfo info) { + @NonNull + public ComponentName getComponent(@NonNull ShortcutInfo info) { return ShortcutKey.fromInfo(info).componentName; } + @NonNull @Override - public UserHandle getUser(ShortcutInfo info) { + public UserHandle getUser(@NonNull ShortcutInfo info) { return info.getUserHandle(); } + @NonNull @Override - public CharSequence getLabel(ShortcutInfo info) { + public CharSequence getLabel(@NonNull ShortcutInfo info) { return info.getShortLabel(); } @Override - public CharSequence getDescription(ShortcutInfo object, CharSequence fallback) { + @NonNull + public CharSequence getDescription(@NonNull ShortcutInfo object, + @NonNull CharSequence fallback) { CharSequence label = object.getLongLabel(); return TextUtils.isEmpty(label) ? fallback : label; } @NonNull @Override - public BitmapInfo loadIcon(Context context, ShortcutInfo info) { + public BitmapInfo loadIcon(@NonNull Context context, @NonNull ShortcutInfo info) { try (LauncherIcons li = LauncherIcons.obtain(context)) { Drawable unbadgedDrawable = ShortcutCachingLogic.getIcon( context, info, LauncherAppState.getIDP(context).fillResIconDpi); @@ -76,7 +82,8 @@ public class ShortcutCachingLogic implements CachingLogic { } @Override - public long getLastUpdatedTime(ShortcutInfo shortcutInfo, PackageInfo info) { + public long getLastUpdatedTime(@Nullable ShortcutInfo shortcutInfo, + @NonNull PackageInfo info) { if (shortcutInfo == null) { return info.lastUpdateTime; } diff --git a/src/com/android/launcher3/model/data/AppInfo.java b/src/com/android/launcher3/model/data/AppInfo.java index 5b2bcf5819..24e7dd3c92 100644 --- a/src/com/android/launcher3/model/data/AppInfo.java +++ b/src/com/android/launcher3/model/data/AppInfo.java @@ -29,7 +29,6 @@ import android.os.UserHandle; import android.os.UserManager; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.LauncherSettings; @@ -55,6 +54,7 @@ public class AppInfo extends ItemInfoWithIcon implements WorkspaceItemFactory { */ public Intent intent; + @NonNull public ComponentName componentName; // Section name used for indexing. @@ -151,7 +151,7 @@ public class AppInfo extends ItemInfoWithIcon implements WorkspaceItemFactory { | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } - @Nullable + @NonNull @Override public ComponentName getTargetComponent() { return componentName; diff --git a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java index 960d27d27f..7d36740734 100644 --- a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java +++ b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java @@ -64,23 +64,26 @@ public class CacheDataUpdatedTaskTest { IconCache iconCache = LauncherAppState.getInstance(context).getIconCache(); CachingLogic placeholderLogic = new CachingLogic() { @Override - public ComponentName getComponent(ItemInfo info) { + @NonNull + public ComponentName getComponent(@NonNull ItemInfo info) { return info.getTargetComponent(); } + @NonNull @Override - public UserHandle getUser(ItemInfo info) { + public UserHandle getUser(@NonNull ItemInfo info) { return info.user; } + @NonNull @Override - public CharSequence getLabel(ItemInfo info) { + public CharSequence getLabel(@NonNull ItemInfo info) { return NEW_LABEL_PREFIX + info.id; } @NonNull @Override - public BitmapInfo loadIcon(Context context, ItemInfo info) { + public BitmapInfo loadIcon(@NonNull Context context, @NonNull ItemInfo info) { return BitmapInfo.of(Bitmap.createBitmap(1, 1, Config.ARGB_8888), Color.RED); } };