Merge "Updating logic to check if icon needs badging"
This commit is contained in:
@@ -28,6 +28,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
@@ -62,7 +63,9 @@ public class TaskIconCache implements DisplayInfoChangeListener {
|
||||
|
||||
private final Context mContext;
|
||||
private final TaskKeyLruCache<TaskCacheEntry> mIconCache;
|
||||
private final BitmapInfo[] mDefaultIcons = new BitmapInfo[1];
|
||||
private final SparseArray<BitmapInfo> mDefaultIcons = new SparseArray<>();
|
||||
private BitmapInfo mDefaultIconBase = null;
|
||||
|
||||
private final IconProvider mIconProvider;
|
||||
|
||||
private BaseIconFactory mIconFactory;
|
||||
@@ -208,12 +211,23 @@ public class TaskIconCache implements DisplayInfoChangeListener {
|
||||
@WorkerThread
|
||||
private Drawable getDefaultIcon(int userId) {
|
||||
synchronized (mDefaultIcons) {
|
||||
if (mDefaultIcons[0] == null) {
|
||||
if (mDefaultIconBase == null) {
|
||||
try (BaseIconFactory bif = getIconFactory()) {
|
||||
mDefaultIcons[0] = bif.makeDefaultIcon();
|
||||
mDefaultIconBase = bif.makeDefaultIcon();
|
||||
}
|
||||
}
|
||||
|
||||
int index;
|
||||
if ((index = mDefaultIcons.indexOfKey(userId)) >= 0) {
|
||||
return mDefaultIcons.valueAt(index).newIcon(mContext);
|
||||
} else {
|
||||
try (BaseIconFactory li = getIconFactory()) {
|
||||
BitmapInfo info = mDefaultIconBase.withFlags(
|
||||
li.getBitmapFlagOp(new IconOptions().setUser(UserHandle.of(userId))));
|
||||
mDefaultIcons.put(userId, info);
|
||||
return info.newIcon(mContext);
|
||||
}
|
||||
}
|
||||
return mDefaultIcons[0].clone().withUser(UserHandle.of(userId)).newIcon(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
||||
activitiesLists.put(
|
||||
packages[i], appsList.addPackage(context, packages[i], mUser));
|
||||
}
|
||||
flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
flagOp = FlagOp.NO_OP.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
break;
|
||||
}
|
||||
case OP_UPDATE:
|
||||
@@ -134,7 +134,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
||||
}
|
||||
}
|
||||
// Since package was just updated, the target must be available now.
|
||||
flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
flagOp = FlagOp.NO_OP.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
break;
|
||||
case OP_REMOVE: {
|
||||
for (int i = 0; i < N; i++) {
|
||||
@@ -148,13 +148,12 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
||||
if (DEBUG) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
|
||||
appsList.removePackage(packages[i], mUser);
|
||||
}
|
||||
flagOp = FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
flagOp = FlagOp.NO_OP.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
|
||||
break;
|
||||
case OP_SUSPEND:
|
||||
case OP_UNSUSPEND:
|
||||
flagOp = mOp == OP_SUSPEND ?
|
||||
FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED) :
|
||||
FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED);
|
||||
flagOp = FlagOp.NO_OP.setFlag(
|
||||
WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED, mOp == OP_SUSPEND);
|
||||
if (DEBUG) Log.d(TAG, "mAllAppsList.(un)suspend " + N);
|
||||
appsList.updateDisabledFlags(matcher, flagOp);
|
||||
break;
|
||||
@@ -162,9 +161,8 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
||||
UserManagerState ums = new UserManagerState();
|
||||
ums.init(UserCache.INSTANCE.get(context),
|
||||
context.getSystemService(UserManager.class));
|
||||
flagOp = ums.isUserQuiet(mUser)
|
||||
? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER)
|
||||
: FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
|
||||
flagOp = FlagOp.NO_OP.setFlag(
|
||||
WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER, ums.isUserQuiet(mUser));
|
||||
appsList.updateDisabledFlags(matcher, flagOp);
|
||||
|
||||
// We are not synchronizing here, as int operations are atomic
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.android.launcher3.util;
|
||||
|
||||
public interface FlagOp {
|
||||
|
||||
FlagOp NO_OP = i -> i;
|
||||
|
||||
int apply(int flags);
|
||||
|
||||
static FlagOp addFlag(int flag) {
|
||||
return i -> i | flag;
|
||||
}
|
||||
|
||||
static FlagOp removeFlag(int flag) {
|
||||
return i -> i & ~flag;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user