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);
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index ee219e3..f7a89ba 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -690,18 +690,47 @@
}
}
+ /**
+ * 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<UserInfo> 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<UserInfo> 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 f647375..0000000
--- a/core/res/res/drawable-hdpi/ic_corp_badge.png
+++ /dev/null
Binary files 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 80d848d..0000000
--- a/core/res/res/drawable-xhdpi/ic_corp_badge.png
+++ /dev/null
Binary files 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 885e2ac..0000000
--- a/core/res/res/drawable-xxhdpi/ic_corp_badge.png
+++ /dev/null
Binary files 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 0000000..5325712
--- /dev/null
+++ b/core/res/res/drawable/ic_corp_badge.xml
@@ -0,0 +1,34 @@
+<!--
+Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android" >
+ <size
+ android:width="19.0dp"
+ android:height="19.0dp"/>
+
+ <viewport
+ android:viewportWidth="19.0"
+ android:viewportHeight="19.0"/>
+
+ <path
+ android:pathData="M9.5,9.5m-9.5,0.0a9.5,9.5 0.0,1.0 1.0,19.0 0.0a9.5,9.5 0.0,1.0 1.0,-19.0 0.0"
+ android:fill="#FF5722"/>
+ <path
+ android:pathData="M12.667,7.125l-1.583,0.0L11.084,6.333l-0.792,-0.792L8.708,5.5410004L7.917,6.333l0.0,0.792L6.333,7.125c-0.438,0.0 -0.788,0.354 -0.788,0.792l-0.004,4.354c0.0,0.438 0.354,0.792 0.792,0.792l6.333,0.0c0.438,0.0 0.792,-0.354 0.792,-0.792L13.458,7.917C13.458,7.479 13.104,7.125 12.667,7.125zM10.094,10.687L8.906,10.687L8.906,9.5l1.188,0.0L10.094,10.687zM10.292,7.125L8.708,7.125L8.708,6.333l1.583,0.0L10.291,7.125z"
+ android:fill="#FFFFFF"/>
+ <path
+ android:pathData="M4.75,4.75 h9.5 v9.5 h-9.5z"
+ android:fill="#00000000"/>
+</vector>
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 0000000..7bfab4c
--- /dev/null
+++ b/core/res/res/drawable/ic_corp_icon_badge.xml
@@ -0,0 +1,40 @@
+<!--
+Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android" >
+ <size
+ android:width="64.0dp"
+ android:height="64.0dp"/>
+
+ <viewport
+ android:viewportWidth="64.0"
+ android:viewportHeight="64.0"/>
+
+ <path
+ android:fill="#FF000000"
+ android:pathData="M49.062,50.0m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"/>
+ <path
+ android:fill="#FF000000"
+ android:pathData="M49.0,49.5m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"/>
+ <path
+ android:pathData="M49.0,49.0m-14.0,0.0a14.0,14.0 0.0,1.0 1.0,28.0 0.0a14.0,14.0 0.0,1.0 1.0,-28.0 0.0"
+ android:fill="#FF5722"/>
+ <path
+ android:pathData="M53.667,45.5l-2.333,0.0l0.0,-1.167l-1.167,-1.167l-2.333,0.0l-1.167,1.167L46.667,45.5l-2.333,0.0c-0.645,0.0 -1.161,0.522 -1.161,1.167l-0.006,6.417c0.0,0.645 0.522,1.167 1.167,1.167l9.333,0.0c0.645,0.0 1.167,-0.522 1.167,-1.167l0.0,-6.417C54.833,46.022 54.311,45.5 53.667,45.5zM49.875,50.75l-1.75,0.0L48.125,49.0l1.75,0.0L49.875,50.75zM50.167,45.5l-2.333,0.0l0.0,-1.167l2.333,0.0L50.167,45.5z"
+ android:fill="#FFFFFF"/>
+ <path
+ android:pathData="M42.0,42.0 h14.0 v14.0 h-14.0z"
+ android:fill="#00000000"/>
+</vector>
diff --git a/core/res/res/layout/notification_template_quantum_base.xml b/core/res/res/layout/notification_template_quantum_base.xml
index 789bf32..4265f9d 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"
/>
+ <ImageView android:id="@+id/profile_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center"
+ android:layout_weight="0"
+ android:layout_marginStart="8dp"
+ android:scaleType="centerInside"
+ android:visibility="gone"
+ />
</LinearLayout>
</LinearLayout>
</FrameLayout>
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 8cb5549..95a4c82 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"
/>
+ <ImageView android:id="@+id/profile_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center"
+ android:layout_weight="0"
+ android:layout_marginStart="8dp"
+ android:scaleType="centerInside"
+ android:visibility="gone"
+ />
</LinearLayout>
<ProgressBar
android:id="@android:id/progress"
diff --git a/core/res/res/layout/notification_template_quantum_big_text.xml b/core/res/res/layout/notification_template_quantum_big_text.xml
index bbd1071..45811fc 100644
--- a/core/res/res/layout/notification_template_quantum_big_text.xml
+++ b/core/res/res/layout/notification_template_quantum_big_text.xml
@@ -165,6 +165,15 @@
android:gravity="center"
android:paddingStart="8dp"
/>
+ <ImageView android:id="@+id/profile_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center"
+ android:layout_weight="0"
+ android:layout_marginStart="8dp"
+ android:scaleType="centerInside"
+ android:visibility="gone"
+ />
</LinearLayout>
</LinearLayout>
</FrameLayout>
diff --git a/core/res/res/layout/notification_template_quantum_inbox.xml b/core/res/res/layout/notification_template_quantum_inbox.xml
index a071d59..3851dd3 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"
/>
+ <ImageView android:id="@+id/profile_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center"
+ android:layout_weight="0"
+ android:layout_marginStart="8dp"
+ android:scaleType="centerInside"
+ android:visibility="gone"
+ />
</LinearLayout>
</LinearLayout>
</FrameLayout>
diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml
index c966a12..639091e 100644
--- a/core/res/res/values/ids.xml
+++ b/core/res/res/values/ids.xml
@@ -23,6 +23,7 @@
<item type="id" name="empty" />
<item type="id" name="hint" />
<item type="id" name="icon" />
+ <item type="id" name="icon_badge" />
<item type="id" name="icon1" />
<item type="id" name="icon2" />
<item type="id" name="input" />
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 61b6a0d..80eceb5 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -217,6 +217,7 @@
<java-symbol type="id" name="pin_confirm_text" />
<java-symbol type="id" name="pin_error_message" />
<java-symbol type="id" name="timePickerLayout" />
+ <java-symbol type="id" name="profile_icon" />
<java-symbol type="attr" name="actionModeShareDrawable" />
<java-symbol type="attr" name="alertDialogCenterButtons" />
@@ -1119,6 +1120,7 @@
<java-symbol type="drawable" name="cling_arrow_up" />
<java-symbol type="drawable" name="cling_bg" />
<java-symbol type="drawable" name="ic_corp_badge" />
+ <java-symbol type="drawable" name="ic_corp_icon_badge" />
<java-symbol type="layout" name="action_bar_home" />
<java-symbol type="layout" name="action_bar_title_item" />