mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 10:48:19 +00:00
Merge "Explicit Nullbility in Launcher (Part 2)" into tm-qpr-dev
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<ShortcutInfo> {
|
||||
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<ShortcutInfo> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastUpdatedTime(ShortcutInfo shortcutInfo, PackageInfo info) {
|
||||
public long getLastUpdatedTime(@Nullable ShortcutInfo shortcutInfo,
|
||||
@NonNull PackageInfo info) {
|
||||
if (shortcutInfo == null) {
|
||||
return info.lastUpdateTime;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -64,23 +64,26 @@ public class CacheDataUpdatedTaskTest {
|
||||
IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
|
||||
CachingLogic<ItemInfo> placeholderLogic = new CachingLogic<ItemInfo>() {
|
||||
@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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user