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

Commit 8a0101ba authored by Kenny Guy's avatar Kenny Guy
Browse files

Badge notification from managed profiles.

Add a method to the UserManager to provide access
to bitmap of badge for managed profile.
Overlay the icon view in notification templates with
the badge from the UserManager.
Notifications with custom views won't be badged.

Bug: 12641490

Change-Id: I1f2aae927e75fc8a955e4d5bbc3cc81127d87069
(cherry picked from commit 0f4ab980227e8c298bfcd34dd85aad0febad528c)
parent 3af4edf5
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.session.MediaSessionToken;
import android.net.Uri;
@@ -32,6 +35,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
@@ -2305,7 +2309,23 @@ public class Notification implements Parcelable
            return this;
        }

        private Bitmap getProfileBadge() {
            UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            Drawable badge = userManager.getBadgeForUser(android.os.Process.myUserHandle());
            if (badge == null) {
                return null;
            }
            final int width = badge.getIntrinsicWidth();
            final int height = badge.getIntrinsicHeight();
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            badge.setBounds(0, 0, width, height);
            badge.draw(canvas);
            return bitmap;
        }

        private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
            Bitmap profileIcon = getProfileBadge();
            RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
            boolean showLine3 = false;
            boolean showLine2 = false;
@@ -2313,6 +2333,12 @@ public class Notification implements Parcelable
            if (mPriority < PRIORITY_LOW) {
                // TODO: Low priority presentation
            }
            if (profileIcon != null) {
                contentView.setImageViewBitmap(R.id.profile_icon, profileIcon);
                contentView.setViewVisibility(R.id.profile_icon, View.VISIBLE);
            } else {
                contentView.setViewVisibility(R.id.profile_icon, View.GONE);
            }
            if (mLargeIcon != null) {
                contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
                processLargeIcon(mLargeIcon, contentView);
+33 −4
Original line number Diff line number Diff line
@@ -690,16 +690,45 @@ public class UserManager {
        }
    }

    /**
     * If the target user is a managed profile of the calling user or the caller
     * is itself a managed profile, then this returns a drawable to use as a small
     * icon to include in a view to distinguish it from the original icon.
     *
     * @param user The target user.
     * @return the drawable or null if no drawable is required.
     * @hide
     */
    public Drawable getBadgeForUser(UserHandle user) {
        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
        if (userInfo != null && userInfo.isManagedProfile()) {
            return Resources.getSystem().getDrawable(
                    com.android.internal.R.drawable.ic_corp_badge);
        }
        return null;
    }

    private int getBadgeResIdForUser(int userHandle) {
        // Return the framework-provided badge.
        UserInfo userInfo = getUserIfProfile(userHandle);
        if (userInfo != null && userInfo.isManagedProfile()) {
            return com.android.internal.R.drawable.ic_corp_icon_badge;
        }
        return 0;
    }

    /**
     * @return UserInfo for userHandle if it exists and is a profile of the current
     *         user or null.
     */
    private UserInfo getUserIfProfile(int userHandle) {
        List<UserInfo> userProfiles = getProfiles(getUserHandle());
        for (UserInfo user : userProfiles) {
            if (user.id == userHandle
                    && user.isManagedProfile()) {
                return com.android.internal.R.drawable.ic_corp_badge;
            if (user.id == userHandle) {
                return user;
            }
        }
        return 0;
        return null;
    }

    private Drawable getMergedDrawable(Drawable icon, Drawable badge) {
−2.16 KiB
Loading image diff...
−2.92 KiB
Loading image diff...
−2.23 KiB
Loading image diff...
Loading