Loading core/java/android/app/ApplicationPackageManager.java +62 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,11 @@ package android.app; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA256; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA512; import static android.content.pm.Checksum.TYPE_WHOLE_MD5; Loading @@ -31,6 +36,7 @@ import android.annotation.Nullable; import android.annotation.StringRes; import android.annotation.UserIdInt; import android.annotation.XmlRes; import android.app.admin.DevicePolicyManager; import android.app.role.RoleManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; Loading Loading @@ -62,7 +68,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageInstaller; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; Loading @@ -74,7 +79,6 @@ import android.content.pm.SuspendDialogInfo; import android.content.pm.VerifierDeviceIdentity; import android.content.pm.VersionedPackage; import android.content.pm.dex.ArtManager; import android.content.pm.pkg.FrameworkPackageUserState; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.XmlResourceParser; Loading Loading @@ -122,7 +126,6 @@ import dalvik.system.VMRuntime; import libcore.util.EmptyArray; import java.io.File; import java.lang.ref.WeakReference; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; Loading Loading @@ -172,6 +175,8 @@ public class ApplicationPackageManager extends PackageManager { private PackageInstaller mInstaller; @GuardedBy("mLock") private ArtManager mArtManager; @GuardedBy("mLock") private DevicePolicyManager mDevicePolicyManager; @GuardedBy("mDelegates") private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>(); Loading @@ -188,6 +193,15 @@ public class ApplicationPackageManager extends PackageManager { } } DevicePolicyManager getDevicePolicyManager() { synchronized (mLock) { if (mDevicePolicyManager == null) { mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class); } return mDevicePolicyManager; } } private PermissionManager getPermissionManager() { synchronized (mLock) { if (mPermissionManager == null) { Loading Loading @@ -1876,12 +1890,27 @@ public class ApplicationPackageManager extends PackageManager { if (!hasUserBadge(user.getIdentifier())) { return icon; } final Drawable badgeForeground = getDevicePolicyManager().getDrawable( getUpdatableUserIconBadgeId(user), SOLID_COLORED, () -> getDefaultUserIconBadge(user)); Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( getUserManager().getUserIconBadgeResId(user.getIdentifier()), badgeForeground, getUserBadgeColor(user, false)); return getBadgedDrawable(icon, badge, null, true); } private String getUpdatableUserIconBadgeId(UserHandle user) { return getUserManager().isManagedProfile(user.getIdentifier()) ? WORK_PROFILE_ICON_BADGE : UNDEFINED; } private Drawable getDefaultUserIconBadge(UserHandle user) { return mContext.getDrawable(getUserManager().getUserIconBadgeResId(user.getIdentifier())); } @Override public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, Rect badgeLocation, int badgeDensity) { Loading Loading @@ -1913,13 +1942,28 @@ public class ApplicationPackageManager extends PackageManager { if (badgeColor == null) { return null; } Drawable badgeForeground = getDrawableForDensity( getUserManager().getUserBadgeResId(user.getIdentifier()), density); final Drawable badgeForeground = getDevicePolicyManager().getDrawableForDensity( getUpdatableUserBadgeId(user), SOLID_COLORED, density, () -> getDefaultUserBadgeForDensity(user, density)); badgeForeground.setTint(getUserBadgeColor(user, false)); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); return badge; } private String getUpdatableUserBadgeId(UserHandle user) { return getUserManager().isManagedProfile(user.getIdentifier()) ? WORK_PROFILE_ICON : UNDEFINED; } private Drawable getDefaultUserBadgeForDensity(UserHandle user, int density) { return getDrawableForDensity( getUserManager().getUserBadgeResId(user.getIdentifier()), density); } /** * Returns the badge color based on whether device has dark theme enabled or not. */ Loading @@ -1928,14 +1972,24 @@ public class ApplicationPackageManager extends PackageManager { if (!hasUserBadge(user.getIdentifier())) { return null; } Drawable badge = getDrawableForDensity( getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); final Drawable badge = getDevicePolicyManager().getDrawableForDensity( getUpdatableUserBadgeId(user), SOLID_NOT_COLORED, density, () -> getDefaultUserBadgeNoBackgroundForDensity(user, density)); if (badge != null) { badge.setTint(getUserBadgeColor(user, true)); } return badge; } private Drawable getDefaultUserBadgeNoBackgroundForDensity(UserHandle user, int density) { return getDrawableForDensity( getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); } private Drawable getDrawableForDensity(int drawableId, int density) { if (density <= 0) { density = mContext.getResources().getDisplayMetrics().densityDpi; Loading core/java/android/util/IconDrawableFactory.java +25 −4 Original line number Diff line number Diff line Loading @@ -15,7 +15,12 @@ */ package android.util; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; import android.annotation.UserIdInt; import android.app.admin.DevicePolicyManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; Loading @@ -37,6 +42,7 @@ public class IconDrawableFactory { protected final Context mContext; protected final PackageManager mPm; protected final UserManager mUm; protected final DevicePolicyManager mDpm; protected final LauncherIcons mLauncherIcons; protected final boolean mEmbedShadow; Loading @@ -44,6 +50,7 @@ public class IconDrawableFactory { mContext = context; mPm = context.getPackageManager(); mUm = context.getSystemService(UserManager.class); mDpm = context.getSystemService(DevicePolicyManager.class); mLauncherIcons = new LauncherIcons(context); mEmbedShadow = embedShadow; } Loading Loading @@ -73,18 +80,32 @@ public class IconDrawableFactory { if (appInfo.isInstantApp()) { int badgeColor = Resources.getSystem().getColor( com.android.internal.R.color.instant_app_badge, null); Drawable badge = mContext.getDrawable( com.android.internal.R.drawable.ic_instant_icon_badge_bolt); icon = mLauncherIcons.getBadgedDrawable(icon, com.android.internal.R.drawable.ic_instant_icon_badge_bolt, badge, badgeColor); } if (mUm.hasBadge(userId)) { icon = mLauncherIcons.getBadgedDrawable(icon, mUm.getUserIconBadgeResId(userId), mUm.getUserBadgeColor(userId)); Drawable badge = mDpm.getDrawable( getUpdatableUserIconBadgeId(userId), SOLID_COLORED, () -> getDefaultUserIconBadge(userId)); icon = mLauncherIcons.getBadgedDrawable(icon, badge, mUm.getUserBadgeColor(userId)); } return icon; } private String getUpdatableUserIconBadgeId(int userId) { return mUm.isManagedProfile(userId) ? WORK_PROFILE_ICON_BADGE : UNDEFINED; } private Drawable getDefaultUserIconBadge(int userId) { return mContext.getResources().getDrawable(mUm.getUserIconBadgeResId(userId)); } /** * Add shadow to the icon if {@link AdaptiveIconDrawable} */ Loading core/java/android/util/LauncherIcons.java +6 −5 Original line number Diff line number Diff line Loading @@ -45,10 +45,12 @@ public final class LauncherIcons { private final SparseArray<Bitmap> mShadowCache = new SparseArray<>(); private final int mIconSize; private final Resources mRes; private final Context mContext; public LauncherIcons(Context context) { mRes = context.getResources(); mIconSize = mRes.getDimensionPixelSize(android.R.dimen.app_icon_size); mContext = context; } public Drawable wrapIconDrawableWithShadow(Drawable drawable) { Loading Loading @@ -98,14 +100,14 @@ public final class LauncherIcons { return shadow; } public Drawable getBadgeDrawable(int foregroundRes, int backgroundColor) { return getBadgedDrawable(null, foregroundRes, backgroundColor); public Drawable getBadgeDrawable(Drawable badgeForeground, int backgroundColor) { return getBadgedDrawable(null, badgeForeground, backgroundColor); } public Drawable getBadgedDrawable(Drawable base, int foregroundRes, int backgroundColor) { public Drawable getBadgedDrawable( Drawable base, Drawable badgeForeground, int backgroundColor) { Resources overlayableRes = ActivityThread.currentActivityThread().getApplication().getResources(); // ic_corp_icon_badge_shadow is not work-profile-specific. Drawable badgeShadow = overlayableRes.getDrawable( com.android.internal.R.drawable.ic_corp_icon_badge_shadow); Loading @@ -115,7 +117,6 @@ public final class LauncherIcons { com.android.internal.R.drawable.ic_corp_icon_badge_color) .getConstantState().newDrawable().mutate(); Drawable badgeForeground = overlayableRes.getDrawable(foregroundRes); badgeForeground.setTint(backgroundColor); Drawable[] drawables = base == null Loading Loading
core/java/android/app/ApplicationPackageManager.java +62 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,11 @@ package android.app; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA256; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA512; import static android.content.pm.Checksum.TYPE_WHOLE_MD5; Loading @@ -31,6 +36,7 @@ import android.annotation.Nullable; import android.annotation.StringRes; import android.annotation.UserIdInt; import android.annotation.XmlRes; import android.app.admin.DevicePolicyManager; import android.app.role.RoleManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; Loading Loading @@ -62,7 +68,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageInstaller; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; Loading @@ -74,7 +79,6 @@ import android.content.pm.SuspendDialogInfo; import android.content.pm.VerifierDeviceIdentity; import android.content.pm.VersionedPackage; import android.content.pm.dex.ArtManager; import android.content.pm.pkg.FrameworkPackageUserState; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.XmlResourceParser; Loading Loading @@ -122,7 +126,6 @@ import dalvik.system.VMRuntime; import libcore.util.EmptyArray; import java.io.File; import java.lang.ref.WeakReference; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; Loading Loading @@ -172,6 +175,8 @@ public class ApplicationPackageManager extends PackageManager { private PackageInstaller mInstaller; @GuardedBy("mLock") private ArtManager mArtManager; @GuardedBy("mLock") private DevicePolicyManager mDevicePolicyManager; @GuardedBy("mDelegates") private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>(); Loading @@ -188,6 +193,15 @@ public class ApplicationPackageManager extends PackageManager { } } DevicePolicyManager getDevicePolicyManager() { synchronized (mLock) { if (mDevicePolicyManager == null) { mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class); } return mDevicePolicyManager; } } private PermissionManager getPermissionManager() { synchronized (mLock) { if (mPermissionManager == null) { Loading Loading @@ -1876,12 +1890,27 @@ public class ApplicationPackageManager extends PackageManager { if (!hasUserBadge(user.getIdentifier())) { return icon; } final Drawable badgeForeground = getDevicePolicyManager().getDrawable( getUpdatableUserIconBadgeId(user), SOLID_COLORED, () -> getDefaultUserIconBadge(user)); Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( getUserManager().getUserIconBadgeResId(user.getIdentifier()), badgeForeground, getUserBadgeColor(user, false)); return getBadgedDrawable(icon, badge, null, true); } private String getUpdatableUserIconBadgeId(UserHandle user) { return getUserManager().isManagedProfile(user.getIdentifier()) ? WORK_PROFILE_ICON_BADGE : UNDEFINED; } private Drawable getDefaultUserIconBadge(UserHandle user) { return mContext.getDrawable(getUserManager().getUserIconBadgeResId(user.getIdentifier())); } @Override public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, Rect badgeLocation, int badgeDensity) { Loading Loading @@ -1913,13 +1942,28 @@ public class ApplicationPackageManager extends PackageManager { if (badgeColor == null) { return null; } Drawable badgeForeground = getDrawableForDensity( getUserManager().getUserBadgeResId(user.getIdentifier()), density); final Drawable badgeForeground = getDevicePolicyManager().getDrawableForDensity( getUpdatableUserBadgeId(user), SOLID_COLORED, density, () -> getDefaultUserBadgeForDensity(user, density)); badgeForeground.setTint(getUserBadgeColor(user, false)); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); return badge; } private String getUpdatableUserBadgeId(UserHandle user) { return getUserManager().isManagedProfile(user.getIdentifier()) ? WORK_PROFILE_ICON : UNDEFINED; } private Drawable getDefaultUserBadgeForDensity(UserHandle user, int density) { return getDrawableForDensity( getUserManager().getUserBadgeResId(user.getIdentifier()), density); } /** * Returns the badge color based on whether device has dark theme enabled or not. */ Loading @@ -1928,14 +1972,24 @@ public class ApplicationPackageManager extends PackageManager { if (!hasUserBadge(user.getIdentifier())) { return null; } Drawable badge = getDrawableForDensity( getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); final Drawable badge = getDevicePolicyManager().getDrawableForDensity( getUpdatableUserBadgeId(user), SOLID_NOT_COLORED, density, () -> getDefaultUserBadgeNoBackgroundForDensity(user, density)); if (badge != null) { badge.setTint(getUserBadgeColor(user, true)); } return badge; } private Drawable getDefaultUserBadgeNoBackgroundForDensity(UserHandle user, int density) { return getDrawableForDensity( getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); } private Drawable getDrawableForDensity(int drawableId, int density) { if (density <= 0) { density = mContext.getResources().getDisplayMetrics().densityDpi; Loading
core/java/android/util/IconDrawableFactory.java +25 −4 Original line number Diff line number Diff line Loading @@ -15,7 +15,12 @@ */ package android.util; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; import android.annotation.UserIdInt; import android.app.admin.DevicePolicyManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; Loading @@ -37,6 +42,7 @@ public class IconDrawableFactory { protected final Context mContext; protected final PackageManager mPm; protected final UserManager mUm; protected final DevicePolicyManager mDpm; protected final LauncherIcons mLauncherIcons; protected final boolean mEmbedShadow; Loading @@ -44,6 +50,7 @@ public class IconDrawableFactory { mContext = context; mPm = context.getPackageManager(); mUm = context.getSystemService(UserManager.class); mDpm = context.getSystemService(DevicePolicyManager.class); mLauncherIcons = new LauncherIcons(context); mEmbedShadow = embedShadow; } Loading Loading @@ -73,18 +80,32 @@ public class IconDrawableFactory { if (appInfo.isInstantApp()) { int badgeColor = Resources.getSystem().getColor( com.android.internal.R.color.instant_app_badge, null); Drawable badge = mContext.getDrawable( com.android.internal.R.drawable.ic_instant_icon_badge_bolt); icon = mLauncherIcons.getBadgedDrawable(icon, com.android.internal.R.drawable.ic_instant_icon_badge_bolt, badge, badgeColor); } if (mUm.hasBadge(userId)) { icon = mLauncherIcons.getBadgedDrawable(icon, mUm.getUserIconBadgeResId(userId), mUm.getUserBadgeColor(userId)); Drawable badge = mDpm.getDrawable( getUpdatableUserIconBadgeId(userId), SOLID_COLORED, () -> getDefaultUserIconBadge(userId)); icon = mLauncherIcons.getBadgedDrawable(icon, badge, mUm.getUserBadgeColor(userId)); } return icon; } private String getUpdatableUserIconBadgeId(int userId) { return mUm.isManagedProfile(userId) ? WORK_PROFILE_ICON_BADGE : UNDEFINED; } private Drawable getDefaultUserIconBadge(int userId) { return mContext.getResources().getDrawable(mUm.getUserIconBadgeResId(userId)); } /** * Add shadow to the icon if {@link AdaptiveIconDrawable} */ Loading
core/java/android/util/LauncherIcons.java +6 −5 Original line number Diff line number Diff line Loading @@ -45,10 +45,12 @@ public final class LauncherIcons { private final SparseArray<Bitmap> mShadowCache = new SparseArray<>(); private final int mIconSize; private final Resources mRes; private final Context mContext; public LauncherIcons(Context context) { mRes = context.getResources(); mIconSize = mRes.getDimensionPixelSize(android.R.dimen.app_icon_size); mContext = context; } public Drawable wrapIconDrawableWithShadow(Drawable drawable) { Loading Loading @@ -98,14 +100,14 @@ public final class LauncherIcons { return shadow; } public Drawable getBadgeDrawable(int foregroundRes, int backgroundColor) { return getBadgedDrawable(null, foregroundRes, backgroundColor); public Drawable getBadgeDrawable(Drawable badgeForeground, int backgroundColor) { return getBadgedDrawable(null, badgeForeground, backgroundColor); } public Drawable getBadgedDrawable(Drawable base, int foregroundRes, int backgroundColor) { public Drawable getBadgedDrawable( Drawable base, Drawable badgeForeground, int backgroundColor) { Resources overlayableRes = ActivityThread.currentActivityThread().getApplication().getResources(); // ic_corp_icon_badge_shadow is not work-profile-specific. Drawable badgeShadow = overlayableRes.getDrawable( com.android.internal.R.drawable.ic_corp_icon_badge_shadow); Loading @@ -115,7 +117,6 @@ public final class LauncherIcons { com.android.internal.R.drawable.ic_corp_icon_badge_color) .getConstantState().newDrawable().mutate(); Drawable badgeForeground = overlayableRes.getDrawable(foregroundRes); badgeForeground.setTint(backgroundColor); Drawable[] drawables = base == null Loading