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)
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 8dba1dc..5ac2a33 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -21,7 +21,10 @@
 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.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 @@
             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 @@
             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);