Merge "Update logic for toast app icons" into sc-dev am: 4499b71b2e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15067463 Change-Id: I9b9987ca1a6792718c3ae4a20dd8db23c1a6053f
This commit is contained in:
@@ -16,13 +16,18 @@
|
|||||||
|
|
||||||
package com.android.systemui.toast;
|
package com.android.systemui.toast;
|
||||||
|
|
||||||
|
import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
|
||||||
|
import static android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.UserIdInt;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@@ -53,7 +58,7 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
|||||||
final ToastPlugin.Toast mPluginToast;
|
final ToastPlugin.Toast mPluginToast;
|
||||||
|
|
||||||
private final String mPackageName;
|
private final String mPackageName;
|
||||||
private final int mUserId;
|
@UserIdInt private final int mUserId;
|
||||||
private final LayoutInflater mLayoutInflater;
|
private final LayoutInflater mLayoutInflater;
|
||||||
|
|
||||||
final int mDefaultX = 0;
|
final int mDefaultX = 0;
|
||||||
@@ -74,7 +79,7 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
|
SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
|
||||||
ToastPlugin.Toast pluginToast, String packageName, int userId,
|
ToastPlugin.Toast pluginToast, String packageName, @UserIdInt int userId,
|
||||||
int orientation) {
|
int orientation) {
|
||||||
mLayoutInflater = layoutInflater;
|
mLayoutInflater = layoutInflater;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -248,6 +253,15 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Context userContext;
|
||||||
|
try {
|
||||||
|
userContext = context.createPackageContextAsUser("android",
|
||||||
|
0, new UserHandle(userId));
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
Log.e(TAG, "Could not create user package context");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final ApplicationsState appState =
|
final ApplicationsState appState =
|
||||||
ApplicationsState.getInstance((Application) context.getApplicationContext());
|
ApplicationsState.getInstance((Application) context.getApplicationContext());
|
||||||
if (!appState.isUserAdded(userId)) {
|
if (!appState.isUserAdded(userId)) {
|
||||||
@@ -255,9 +269,11 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
|||||||
+ "packageName=" + packageName);
|
+ "packageName=" + packageName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final PackageManager packageManager = userContext.getPackageManager();
|
||||||
final AppEntry appEntry = appState.getEntry(packageName, userId);
|
final AppEntry appEntry = appState.getEntry(packageName, userId);
|
||||||
if (appEntry == null || appEntry.info == null
|
if (appEntry == null || appEntry.info == null
|
||||||
|| !ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(appEntry)) {
|
|| !showApplicationIcon(appEntry.info, packageManager)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +281,20 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
|||||||
UserHandle user = UserHandle.getUserHandleForUid(appInfo.uid);
|
UserHandle user = UserHandle.getUserHandleForUid(appInfo.uid);
|
||||||
IconFactory iconFactory = IconFactory.obtain(context);
|
IconFactory iconFactory = IconFactory.obtain(context);
|
||||||
Bitmap iconBmp = iconFactory.createBadgedIconBitmap(
|
Bitmap iconBmp = iconFactory.createBadgedIconBitmap(
|
||||||
appInfo.loadUnbadgedIcon(context.getPackageManager()), user, true).icon;
|
appInfo.loadUnbadgedIcon(packageManager), user, true).icon;
|
||||||
return new BitmapDrawable(context.getResources(), iconBmp);
|
return new BitmapDrawable(context.getResources(), iconBmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean showApplicationIcon(ApplicationInfo appInfo,
|
||||||
|
PackageManager packageManager) {
|
||||||
|
if (hasFlag(appInfo.flags, FLAG_UPDATED_SYSTEM_APP)) {
|
||||||
|
return packageManager.getLaunchIntentForPackage(appInfo.packageName)
|
||||||
|
!= null;
|
||||||
|
}
|
||||||
|
return !hasFlag(appInfo.flags, FLAG_SYSTEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasFlag(int flags, int flag) {
|
||||||
|
return (flags & flag) != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user