Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfe2f7ce authored by Vadim Tryshev's avatar Vadim Tryshev Committed by android-build-merger
Browse files

Merge "Adding getManagedUserBadgedDrawableForDensity() to PackageManager." into nyc-dev

am: c9f0a110

* commit 'c9f0a110':
  Adding getManagedUserBadgedDrawableForDensity() to PackageManager.
parents f78f8345 c9f0a110
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -1092,6 +1092,14 @@ public class ApplicationPackageManager extends PackageManager {
        return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
    }

    @Override
    public Drawable getManagedUserBadgedDrawable(Drawable drawable, Rect badgeLocation,
            int badgeDensity) {
        Drawable badgeDrawable = getDrawableForDensity(
            com.android.internal.R.drawable.ic_corp_badge, badgeDensity);
        return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
    }

    @Override
    public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
        final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
@@ -1114,25 +1122,28 @@ public class ApplicationPackageManager extends PackageManager {

    @Override
    public Drawable getUserBadgeForDensity(UserHandle user, int density) {
        return getManagedProfileIconForDensity(user, density,
                com.android.internal.R.drawable.ic_corp_badge);
        return getManagedProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge,
                density);
    }

    @Override
    public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
        return getManagedProfileIconForDensity(user, density,
                com.android.internal.R.drawable.ic_corp_badge_no_background);
        return getManagedProfileIconForDensity(user,
                com.android.internal.R.drawable.ic_corp_badge_no_background, density);
    }

    private Drawable getManagedProfileIconForDensity(UserHandle user, int density,
            int drawableId) {
        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
        if (userInfo != null && userInfo.isManagedProfile()) {
    private Drawable getDrawableForDensity(int drawableId, int density) {
        if (density <= 0) {
            density = mContext.getResources().getDisplayMetrics().densityDpi;
        }
        return Resources.getSystem().getDrawableForDensity(drawableId, density);
    }

    private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
        if (userInfo != null && userInfo.isManagedProfile()) {
            return getDrawableForDensity(drawableId, density);
        }
        return null;
    }

+29 −3
Original line number Diff line number Diff line
@@ -4338,6 +4338,32 @@ public abstract class PackageManager {
    public abstract Drawable getApplicationLogo(String packageName)
            throws NameNotFoundException;

    /**
     * Returns a managed-user-style badged copy of the given drawable allowing the user to
     * distinguish it from the original drawable.
     * The caller can specify the location in the bounds of the drawable to be
     * badged where the badge should be applied as well as the density of the
     * badge to be used.
     * <p>
     * If the original drawable is a BitmapDrawable and the backing bitmap is
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
     * is performed in place and the original drawable is returned.
     * </p>
     *
     * @param drawable The drawable to badge.
     * @param badgeLocation Where in the bounds of the badged drawable to place
     *         the badge. If it's {@code null}, the badge is applied on top of the entire
     *         drawable being badged.
     * @param badgeDensity The optional desired density for the badge as per
     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
     *         the density of the display is used.
     * @return A drawable that combines the original drawable and a badge as
     *         determined by the system.
     * @hide
     */
    public abstract Drawable getManagedUserBadgedDrawable(Drawable drawable, Rect badgeLocation,
        int badgeDensity);

    /**
     * If the target user is a managed profile of the calling user or if the
     * target user is the caller and is itself a managed profile, then this
@@ -4367,17 +4393,17 @@ public abstract class PackageManager {
     * badge to be used.
     * <p>
     * If the original drawable is a BitmapDrawable and the backing bitmap is
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
     * is performed in place and the original drawable is returned.
     * </p>
     *
     * @param drawable The drawable to badge.
     * @param user The target user.
     * @param badgeLocation Where in the bounds of the badged drawable to place
     *         the badge. If not provided, the badge is applied on top of the entire
     *         the badge. If it's {@code null}, the badge is applied on top of the entire
     *         drawable being badged.
     * @param badgeDensity The optional desired density for the badge as per
     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
     *         the density of the display is used.
     * @return A drawable that combines the original drawable and a badge as
     *         determined by the system.
+4 −4
Original line number Diff line number Diff line
@@ -1658,7 +1658,7 @@ public class UserManager {
     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
     * <p>
     * If the original drawable is a BitmapDrawable and the backing bitmap is
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
     * is performed in place and the original drawable is returned.
     * </p>
     *
@@ -1681,17 +1681,17 @@ public class UserManager {
     * badge to be used.
     * <p>
     * If the original drawable is a BitmapDrawable and the backing bitmap is
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
     * is performed in place and the original drawable is returned.
     * </p>
     *
     * @param badgedDrawable The drawable to badge.
     * @param user The target user.
     * @param badgeLocation Where in the bounds of the badged drawable to place
     *         the badge. If not provided, the badge is applied on top of the entire
     *         the badge. If it's {@code null}, the badge is applied on top of the entire
     *         drawable being badged.
     * @param badgeDensity The optional desired density for the badge as per
     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
     *         the density of the display is used.
     * @return A drawable that combines the original drawable and a badge as
     *         determined by the system.
+8 −0
Original line number Diff line number Diff line
@@ -518,6 +518,14 @@ public class MockPackageManager extends PackageManager {
        throw new UnsupportedOperationException();
    }

    /** @hide */
    @Override
    public Drawable getManagedUserBadgedDrawable(Drawable drawable, Rect badgeLocation,
            int badgeDensity) {
        throw new UnsupportedOperationException();
    }


    @Override
    public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
        throw new UnsupportedOperationException();
+6 −0
Original line number Diff line number Diff line
@@ -483,6 +483,12 @@ public class BridgePackageManager extends PackageManager {
        return null;
    }

    @Override
    public Drawable getManagedUserBadgedDrawable(Drawable drawable, Rect badgeLocation,
        int badgeDensity) {
        return null;
    }

    @Override
    public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
        return null;