From 701ea7cf86b7d408b8d3bc1aab054be0333e1f26 Mon Sep 17 00:00:00 2001 From: Kenny Guy Date: Thu, 8 May 2014 23:34:12 +0100 Subject: [PATCH] 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 --- core/java/android/app/Notification.java | 26 +++++++++++ core/java/android/os/UserManager.java | 41 +++++++++++++++--- core/res/res/drawable-hdpi/ic_corp_badge.png | Bin 2211 -> 0 bytes core/res/res/drawable-xhdpi/ic_corp_badge.png | Bin 2989 -> 0 bytes .../res/res/drawable-xxhdpi/ic_corp_badge.png | Bin 2285 -> 0 bytes core/res/res/drawable/ic_corp_badge.xml | 34 +++++++++++++++ core/res/res/drawable/ic_corp_icon_badge.xml | 40 +++++++++++++++++ .../notification_template_quantum_base.xml | 9 ++++ ...notification_template_quantum_big_base.xml | 9 ++++ ...notification_template_quantum_big_text.xml | 9 ++++ .../notification_template_quantum_inbox.xml | 9 ++++ core/res/res/values/ids.xml | 1 + core/res/res/values/symbols.xml | 2 + .../systemui/statusbar/BaseStatusBar.java | 19 +++++++- .../statusbar/phone/PhoneStatusBar.java | 1 - 15 files changed, 191 insertions(+), 9 deletions(-) delete mode 100644 core/res/res/drawable-hdpi/ic_corp_badge.png delete mode 100644 core/res/res/drawable-xhdpi/ic_corp_badge.png delete mode 100644 core/res/res/drawable-xxhdpi/ic_corp_badge.png create mode 100644 core/res/res/drawable/ic_corp_badge.xml create mode 100644 core/res/res/drawable/ic_corp_icon_badge.xml diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 90aeaae989266..4b8f5f0bcde31 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; @@ -2298,7 +2302,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; @@ -2306,6 +2326,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 f6473757242f67754cf3c1d760dc5edbc7a1ca41..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2211 zcmb`Ji9Zt#AIG;jHsp#$$jBAd$R3kn7>q+-I&#tfU;# zkmDD*nVefI$1<}=qWYCb&)@L8zMs$M{rZ0Xf$ulX$pI}csvrsg0K{#qQ7(tP`Nt69 z!~9qfX?zGE-UW>WG>s~494^AXSI{WH!Jnz?fUL~z#E@Bo0A%pU^*MJ4iwB{;815K@Bw%aZe|)m@)* zKj|HAkolbGtVR3sx`2CZtNXv(jSUv7Y_PUd^#BhzP5c%sk13F%oLG%iSrC4cdo`&kC}m9ds30Ne4Z8+z zJ;;itR%i=}+z8;2(KjMdvHNi~e{n2tI1tuXvSR87+9QaxZ)fC{lLmbvH(?~PA|@x< zB)_PB`&Kdgb4d6%YaqM`d_^BOrd-ON5yPHw0&A#^my_>uX;{6tvEoJdA(Gsr<=#L9 z3*{NBGN9Y@13}xhtu&X^Bd&OB#8gX|%^&e>mU=FfNqg!J$$vj}synbIC(Xh$o4sm8 zi-O7yZ

Qr$9F2qTu?6ZkMq<*ab!0umsvfV%T5o%NWV^>GrEWS`@ht7_P_aJe|C@5|Ke+Hiy#Hq74nZJM7w` zv(-Ek{U!S-4AyuBJ59Xz`3KzlldQE)CL{Vpq4Dc&4OUSa%u1qxFPk%)wcYrPbAtiRSB1$@k%EF8~l9hM}%hP)xMwJg>rl!{i7VaT4(i!0zm zrQ9g@@E{5Co=x=^v-I!?5zgwr~p`Znt$9FH%nbSH^2gkXN@S@qZe zJBwJm6$8`Cd6g=j$FksQ&oI}h|EOLAN*H-eQ!y$Q-PK4@sh!>KOFMx~9aqWihgXsp zbV>DexdSFd$1mhMys?bk7WZVEp!nLL!C^<|dz9BjY3N-0@wrwT>;9XOTK_y*a+V?P z`itmB^iF}5_I%*Cj*dT~rr&jX(w*pJ#MTOS1xIuXMRJKApFFU?--IP#YzHR^h2Uwc z-FWilDtB$@aMSgFiEh*1D2<&U7Q2ZtbjkTIsREs7=8)9l^QC88h@tw-HgRfQ*QRwk z~CTRy_@L!Yxc}A zAx*UzPLSJXTWmVj&CgyNy3;24x5&)3Y4YlHMv0K?31^dgr!TY%_&%Cp0WSOs1+q2P zF$>w!mf+7e^L6^O1e;;)AC57D{8-Ip(_amXjF#59Y4ah&(JnSq<{9O?98t`2Gn)RD z3ri&QH+?%1`YWKP)q;m 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 80d848df99127ede2e2b3bdd53a875c423cf60b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2989 zcmc&$`9BkmAD$d@%#mZUoH-I(w(%*ABKJ)yVXoyCU!T9?`+8o_^Ss{A^W*c&`(Fz)eQr(&CjbE8HZ;(&Jo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b(}^-*#(*=ixSL{qL%<+gUkZV0xhVDGLLssngqhHu`2_nGgn<;@Kh z?jQWXARm$m)Z{By$8xngKM~wj8vI*!#o#h zA|n^cdw2`jAlDMjh*b)9Po|#F57O`q8zy=lKRUSPHLAPIjqx&<>usQ4js!V*5ONZR z8ld^HF{4q7|2P4`18Vt)3!-h*4MQQj8%N{B50&$Un2NI#SJzIT`}6P-S8ZUG7I$L) E2hPSx#sB~S 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 6e1629b8dfad1..b03d9b75fcf4e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -217,6 +217,7 @@ + @@ -1116,6 +1117,7 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 422d47f68be0f..88e2bb829ade9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -993,7 +993,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(), @@ -1009,7 +1012,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 dedfff0ee667c..98c6f8936d16a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1165,7 +1165,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;