diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 8dba1dcc778c6..5ac2a33938556 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -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); diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index ee219e3d5d368..f7a89ba5452c5 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -690,18 +690,47 @@ 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. - List userProfiles = getProfiles(getUserHandle()); - for (UserInfo user : userProfiles) { - if (user.id == userHandle - && user.isManagedProfile()) { - return com.android.internal.R.drawable.ic_corp_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 userProfiles = getProfiles(getUserHandle()); + for (UserInfo user : userProfiles) { + if (user.id == userHandle) { + return user; + } + } + return null; + } + private Drawable getMergedDrawable(Drawable icon, Drawable badge) { final int width = icon.getIntrinsicWidth(); final int height = icon.getIntrinsicHeight(); diff --git a/core/res/res/drawable-hdpi/ic_corp_badge.png b/core/res/res/drawable-hdpi/ic_corp_badge.png deleted file mode 100644 index f6473757242f6..0000000000000 Binary files a/core/res/res/drawable-hdpi/ic_corp_badge.png and /dev/null differ diff --git a/core/res/res/drawable-xhdpi/ic_corp_badge.png b/core/res/res/drawable-xhdpi/ic_corp_badge.png deleted file mode 100644 index 80d848df99127..0000000000000 Binary files a/core/res/res/drawable-xhdpi/ic_corp_badge.png and /dev/null differ diff --git a/core/res/res/drawable-xxhdpi/ic_corp_badge.png b/core/res/res/drawable-xxhdpi/ic_corp_badge.png deleted file mode 100644 index 885e2ac76cfb2..0000000000000 Binary files a/core/res/res/drawable-xxhdpi/ic_corp_badge.png and /dev/null differ diff --git a/core/res/res/drawable/ic_corp_badge.xml b/core/res/res/drawable/ic_corp_badge.xml new file mode 100644 index 0000000000000..532571245d55c --- /dev/null +++ b/core/res/res/drawable/ic_corp_badge.xml @@ -0,0 +1,34 @@ + + + + + + + + + + diff --git a/core/res/res/drawable/ic_corp_icon_badge.xml b/core/res/res/drawable/ic_corp_icon_badge.xml new file mode 100644 index 0000000000000..7bfab4c55a0db --- /dev/null +++ b/core/res/res/drawable/ic_corp_icon_badge.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + diff --git a/core/res/res/layout/notification_template_quantum_base.xml b/core/res/res/layout/notification_template_quantum_base.xml index 789bf32e33f7f..4265f9da9d340 100644 --- a/core/res/res/layout/notification_template_quantum_base.xml +++ b/core/res/res/layout/notification_template_quantum_base.xml @@ -120,6 +120,15 @@ android:gravity="center" android:paddingStart="8dp" /> + diff --git a/core/res/res/layout/notification_template_quantum_big_base.xml b/core/res/res/layout/notification_template_quantum_big_base.xml index 8cb55494d48ca..95a4c82774cd1 100644 --- a/core/res/res/layout/notification_template_quantum_big_base.xml +++ b/core/res/res/layout/notification_template_quantum_big_base.xml @@ -127,6 +127,15 @@ android:gravity="center" android:paddingStart="8dp" /> + + diff --git a/core/res/res/layout/notification_template_quantum_inbox.xml b/core/res/res/layout/notification_template_quantum_inbox.xml index a071d59fa5968..3851dd3624d40 100644 --- a/core/res/res/layout/notification_template_quantum_inbox.xml +++ b/core/res/res/layout/notification_template_quantum_inbox.xml @@ -249,6 +249,15 @@ android:gravity="center" android:paddingStart="8dp" /> + diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml index c966a12b7c9b4..639091e142847 100644 --- a/core/res/res/values/ids.xml +++ b/core/res/res/values/ids.xml @@ -23,6 +23,7 @@ + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 61b6a0d92c762..80eceb5ecd66c 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -217,6 +217,7 @@ + @@ -1119,6 +1120,7 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 06cc476d02951..d1484e130bdae 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -992,7 +992,10 @@ public abstract class BaseStatusBar extends SystemUI implements title.setText(entry.notification.getPackageName()); } - final ImageView icon = (ImageView) publicViewLocal.findViewById(com.android.internal.R.id.icon); + final ImageView icon = (ImageView) publicViewLocal.findViewById( + com.android.internal.R.id.icon); + final ImageView profileIcon = (ImageView) publicViewLocal.findViewById( + com.android.internal.R.id.profile_icon); final StatusBarIcon ic = new StatusBarIcon(entry.notification.getPackageName(), entry.notification.getUser(), @@ -1008,7 +1011,19 @@ public abstract class BaseStatusBar extends SystemUI implements com.android.internal.R.drawable.notification_icon_legacy_bg_inset); } - final TextView text = (TextView) publicViewLocal.findViewById(com.android.internal.R.id.text); + if (profileIcon != null) { + Drawable profileDrawable + = mUserManager.getBadgeForUser(entry.notification.getUser()); + if (profileDrawable != null) { + profileIcon.setImageDrawable(profileDrawable); + profileIcon.setVisibility(View.VISIBLE); + } else { + profileIcon.setVisibility(View.GONE); + } + } + + final TextView text = (TextView) publicViewLocal.findViewById( + com.android.internal.R.id.text); text.setText("Unlock your device to see this notification."); // TODO: fill out "time" as well diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 227304c2e30b6..c2c671c96dda9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1187,7 +1187,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, Entry ent = mNotificationData.get(i); if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue; - // TODO How do we want to badge notifcations from profiles. if (!notificationIsForCurrentProfiles(ent.notification)) continue; final int vis = ent.notification.getNotification().visibility;