No more UserHandleCompat
Bug: 32745285 Change-Id: I762fb4e268c1afe48a1860ab12a4ccb3f626aa95
This commit is contained in:
1 parent
338dee9dd7
commit
7c74e4ae64
62 files changed
+376
-505
No files matched your search
@@ -38,13 +38,14 @@ import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.compat.LauncherActivityInfoCompat;
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
import com.android.launcher3.compat.UserHandleCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.graphics.LauncherIcons;
|
||||
@@ -86,7 +87,7 @@ public class IconCache {
|
||||
public boolean isLowResIcon;
|
||||
}
|
||||
|
||||
private final HashMap<UserHandleCompat, Bitmap> mDefaultIcons = new HashMap<>();
|
||||
private final HashMap<UserHandle, Bitmap> mDefaultIcons = new HashMap<>();
|
||||
@Thunk final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
|
||||
|
||||
private final Context mContext;
|
||||
@@ -185,7 +186,7 @@ public class IconCache {
|
||||
return getFullResDefaultActivityIcon();
|
||||
}
|
||||
|
||||
private Bitmap makeDefaultIcon(UserHandleCompat user) {
|
||||
private Bitmap makeDefaultIcon(UserHandle user) {
|
||||
Drawable unbadged = getFullResDefaultActivityIcon();
|
||||
return LauncherIcons.createBadgedIconBitmap(unbadged, user, mContext);
|
||||
}
|
||||
@@ -193,14 +194,14 @@ public class IconCache {
|
||||
/**
|
||||
* Remove any records for the supplied ComponentName.
|
||||
*/
|
||||
public synchronized void remove(ComponentName componentName, UserHandleCompat user) {
|
||||
public synchronized void remove(ComponentName componentName, UserHandle user) {
|
||||
mCache.remove(new ComponentKey(componentName, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any records for the supplied package name from memory.
|
||||
*/
|
||||
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
|
||||
private void removeFromMemCacheLocked(String packageName, UserHandle user) {
|
||||
HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
|
||||
for (ComponentKey key: mCache.keySet()) {
|
||||
if (key.componentName.getPackageName().equals(packageName)
|
||||
@@ -216,7 +217,7 @@ public class IconCache {
|
||||
/**
|
||||
* Updates the entries related to the given package in memory and persistent DB.
|
||||
*/
|
||||
public synchronized void updateIconsForPkg(String packageName, UserHandleCompat user) {
|
||||
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
|
||||
removeIconsForPkg(packageName, user);
|
||||
try {
|
||||
PackageInfo info = mPackageManager.getPackageInfo(packageName,
|
||||
@@ -234,7 +235,7 @@ public class IconCache {
|
||||
/**
|
||||
* Removes the entries related to the given package in memory and persistent DB.
|
||||
*/
|
||||
public synchronized void removeIconsForPkg(String packageName, UserHandleCompat user) {
|
||||
public synchronized void removeIconsForPkg(String packageName, UserHandle user) {
|
||||
removeFromMemCacheLocked(packageName, user);
|
||||
long userSerial = mUserManager.getSerialNumberForUser(user);
|
||||
mIconDb.delete(
|
||||
@@ -247,7 +248,7 @@ public class IconCache {
|
||||
mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);
|
||||
|
||||
mIconProvider.updateSystemStateString();
|
||||
for (UserHandleCompat user : mUserManager.getUserProfiles()) {
|
||||
for (UserHandle user : mUserManager.getUserProfiles()) {
|
||||
// Query for the set of apps
|
||||
final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
|
||||
// Fail if we don't have any apps
|
||||
@@ -258,7 +259,7 @@ public class IconCache {
|
||||
|
||||
// Update icon cache. This happens in segments and {@link #onPackageIconsUpdated}
|
||||
// is called by the icon cache when the job is complete.
|
||||
updateDBIcons(user, apps, UserHandleCompat.myUserHandle().equals(user)
|
||||
updateDBIcons(user, apps, Process.myUserHandle().equals(user)
|
||||
? ignorePackagesForMainUser : Collections.<String>emptySet());
|
||||
}
|
||||
}
|
||||
@@ -268,7 +269,7 @@ public class IconCache {
|
||||
* the DB and are updated.
|
||||
* @return The set of packages for which icons have updated.
|
||||
*/
|
||||
private void updateDBIcons(UserHandleCompat user, List<LauncherActivityInfoCompat> apps,
|
||||
private void updateDBIcons(UserHandle user, List<LauncherActivityInfoCompat> apps,
|
||||
Set<String> ignorePackages) {
|
||||
long userSerial = mUserManager.getSerialNumberForUser(user);
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
@@ -432,7 +433,7 @@ public class IconCache {
|
||||
return new IconLoadRequest(request, mWorkerHandler);
|
||||
}
|
||||
|
||||
private Bitmap getNonNullIcon(CacheEntry entry, UserHandleCompat user) {
|
||||
private Bitmap getNonNullIcon(CacheEntry entry, UserHandle user) {
|
||||
return entry.icon == null ? getDefaultIcon(user) : entry.icon;
|
||||
}
|
||||
|
||||
@@ -441,7 +442,7 @@ public class IconCache {
|
||||
*/
|
||||
public synchronized void getTitleAndIcon(AppInfo application,
|
||||
LauncherActivityInfoCompat info, boolean useLowResIcon) {
|
||||
UserHandleCompat user = info == null ? application.user : info.getUser();
|
||||
UserHandle user = info == null ? application.user : info.getUser();
|
||||
CacheEntry entry = cacheLocked(application.componentName, info, user,
|
||||
false, useLowResIcon);
|
||||
application.title = Utilities.trim(entry.title);
|
||||
@@ -467,7 +468,7 @@ public class IconCache {
|
||||
/**
|
||||
* Returns a high res icon for the given intent and user
|
||||
*/
|
||||
public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) {
|
||||
public synchronized Bitmap getIcon(Intent intent, UserHandle user) {
|
||||
ComponentName component = intent.getComponent();
|
||||
// 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.
|
||||
@@ -485,7 +486,7 @@ public class IconCache {
|
||||
* corresponding activity is not found, it reverts to the package icon.
|
||||
*/
|
||||
public synchronized void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent,
|
||||
UserHandleCompat user, boolean useLowResIcon) {
|
||||
UserHandle user, boolean useLowResIcon) {
|
||||
ComponentName component = intent.getComponent();
|
||||
// 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.
|
||||
@@ -505,7 +506,7 @@ public class IconCache {
|
||||
*/
|
||||
public synchronized void getTitleAndIcon(
|
||||
ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info,
|
||||
UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) {
|
||||
UserHandle user, boolean usePkgIcon, boolean useLowResIcon) {
|
||||
CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
|
||||
shortcutInfo.iconBitmap = getNonNullIcon(entry, user);
|
||||
shortcutInfo.title = Utilities.trim(entry.title);
|
||||
@@ -526,14 +527,14 @@ public class IconCache {
|
||||
infoInOut.usingLowResIcon = entry.isLowResIcon;
|
||||
}
|
||||
|
||||
public synchronized Bitmap getDefaultIcon(UserHandleCompat user) {
|
||||
public synchronized Bitmap getDefaultIcon(UserHandle user) {
|
||||
if (!mDefaultIcons.containsKey(user)) {
|
||||
mDefaultIcons.put(user, makeDefaultIcon(user));
|
||||
}
|
||||
return mDefaultIcons.get(user);
|
||||
}
|
||||
|
||||
public boolean isDefaultIcon(Bitmap icon, UserHandleCompat user) {
|
||||
public boolean isDefaultIcon(Bitmap icon, UserHandle user) {
|
||||
return mDefaultIcons.get(user) == icon;
|
||||
}
|
||||
|
||||
@@ -542,7 +543,7 @@ public class IconCache {
|
||||
* This method is not thread safe, it must be called from a synchronized method.
|
||||
*/
|
||||
protected CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
|
||||
UserHandleCompat user, boolean usePackageIcon, boolean useLowResIcon) {
|
||||
UserHandle user, boolean usePackageIcon, boolean useLowResIcon) {
|
||||
ComponentKey cacheKey = new ComponentKey(componentName, user);
|
||||
CacheEntry entry = mCache.get(cacheKey);
|
||||
if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
|
||||
@@ -587,7 +588,7 @@ public class IconCache {
|
||||
* Adds a default package entry in the cache. This entry is not persisted and will be removed
|
||||
* when the cache is flushed.
|
||||
*/
|
||||
public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user,
|
||||
public synchronized void cachePackageInstallInfo(String packageName, UserHandle user,
|
||||
Bitmap icon, CharSequence title) {
|
||||
removeFromMemCacheLocked(packageName, user);
|
||||
|
||||
@@ -607,7 +608,7 @@ public class IconCache {
|
||||
}
|
||||
}
|
||||
|
||||
private static ComponentKey getPackageKey(String packageName, UserHandleCompat user) {
|
||||
private static ComponentKey getPackageKey(String packageName, UserHandle user) {
|
||||
ComponentName cn = new ComponentName(packageName, packageName + EMPTY_CLASS_NAME);
|
||||
return new ComponentKey(cn, user);
|
||||
}
|
||||
@@ -616,7 +617,7 @@ public class IconCache {
|
||||
* Gets an entry for the package, which can be used as a fallback entry for various components.
|
||||
* This method is not thread safe, it must be called from a synchronized method.
|
||||
*/
|
||||
private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user,
|
||||
private CacheEntry getEntryForPackageLocked(String packageName, UserHandle user,
|
||||
boolean useLowResIcon) {
|
||||
ComponentKey cacheKey = getPackageKey(packageName, user);
|
||||
CacheEntry entry = mCache.get(cacheKey);
|
||||
@@ -628,7 +629,7 @@ public class IconCache {
|
||||
// Check the DB first.
|
||||
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
|
||||
try {
|
||||
int flags = UserHandleCompat.myUserHandle().equals(user) ? 0 :
|
||||
int flags = Process.myUserHandle().equals(user) ? 0 :
|
||||
PackageManager.GET_UNINSTALLED_PACKAGES;
|
||||
PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
|
||||
ApplicationInfo appInfo = info.applicationInfo;
|
||||
|
||||
Reference in new issue
Block a user