Fixed the public notifications views on the lockscreen
The views were based on a legacy systemUI notification.
We are now creating it in Notification.java in order to
always have the latest visuals and avoiding duplicate work.
Change-Id: I3f544cad069a8eab34d4464404d020e06d7f6626
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 620ab50..15967c8 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -3312,6 +3312,37 @@
return applyStandardTemplateWithActions(getBigBaseLayoutResource());
}
+ /**
+ * Construct a RemoteViews for the display in public contexts like on the lockscreen.
+ *
+ * @hide
+ */
+ public RemoteViews makePublicContentView() {
+ if (mN.publicVersion != null) {
+ final Builder builder = recoverBuilder(mContext, mN.publicVersion);
+ return builder.makeContentView();
+ }
+ Bundle savedBundle = mN.extras;
+ Style style = mStyle;
+ mStyle = null;
+ Icon largeIcon = mN.mLargeIcon;
+ mN.mLargeIcon = null;
+ Bundle publicExtras = new Bundle();
+ publicExtras.putBoolean(EXTRA_SHOW_WHEN,
+ savedBundle.getBoolean(EXTRA_SHOW_WHEN));
+ publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER,
+ savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER));
+ publicExtras.putCharSequence(EXTRA_TITLE,
+ mContext.getString(R.string.notification_hidden_text));
+ mN.extras = publicExtras;
+ final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource());
+ mN.extras = savedBundle;
+ mN.mLargeIcon = largeIcon;
+ mStyle = style;
+ return publicView;
+ }
+
+
private RemoteViews generateActionButton(Action action) {
final boolean tombstone = (action.actionIntent == null);
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index a127d94..595ef54 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -537,6 +537,9 @@
<!-- The divider symbol between different parts of the notification header. not translatable [CHAR LIMIT=1] -->
<string name="notification_header_divider_symbol" translatable="false">•</string>
+ <!-- Text shown in place of notification contents when the notification is hidden on a secure lockscreen -->
+ <string name="notification_hidden_text">Contents hidden</string>
+
<!-- Displayed to the user to tell them that they have started up the phone in "safe mode" -->
<string name="safeMode">Safe mode</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 3ee1ca9..1f398e1 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2362,6 +2362,7 @@
<java-symbol type="id" name="deleteButton" />
<java-symbol type="string" name="notification_children_count_bracketed" />
+ <java-symbol type="string" name="notification_hidden_text" />
<java-symbol type="id" name="app_name_text" />
<java-symbol type="id" name="number_of_children" />
<java-symbol type="id" name="header_sub_text" />
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 50e0661..6658cfe 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -906,9 +906,6 @@
<!-- Battery saver notification action text. [CHAR LIMIT=60] -->
<string name="battery_saver_notification_action_text">Turn off battery saver</string>
- <!-- Text shown in place of notification contents when the notification is hidden on a secure lockscreen -->
- <string name="notification_hidden_text">Contents hidden</string>
-
<!-- Media projection permission dialog warning text. [CHAR LIMIT=NONE] -->
<string name="media_projection_dialog_text"><xliff:g id="app_seeking_permission" example="Hangouts">%s</xliff:g> will start capturing everything that\'s displayed on your screen.</string>
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index aad428a..7e01866 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -237,12 +237,6 @@
<item name="android:gravity">center</item>
</style>
- <style name="TextAppearance.Material.Notification.Parenthetical"
- parent="@*android:style/TextAppearance.Material.Notification">
- <item name="android:textStyle">italic</item>
- <item name="android:textColor">#60000000</item>
- </style>
-
<style name="TextAppearance.Material.Notification.HeaderTitle"
parent="@*android:style/TextAppearance.Material.Notification.Info">
</style>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index a6ca50a..11e38ce 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -1382,6 +1382,7 @@
View contentViewLocal = null;
View bigContentViewLocal = null;
View headsUpContentViewLocal = null;
+ View publicViewLocal = null;
try {
contentViewLocal = contentView.apply(
sbn.getPackageContext(mContext),
@@ -1399,6 +1400,11 @@
contentContainer,
mOnClickHandler);
}
+ if (publicContentView != null) {
+ publicViewLocal = publicContentView.apply(
+ sbn.getPackageContext(mContext),
+ contentContainerPublic, mOnClickHandler);
+ }
}
catch (RuntimeException e) {
final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
@@ -1418,25 +1424,9 @@
headsUpContentViewLocal.setIsRootNamespace(true);
contentContainer.setHeadsUpChild(headsUpContentViewLocal);
}
-
- // now the public version
- View publicViewLocal = null;
- if (publicContentView != null) {
- try {
- publicViewLocal = publicContentView.apply(
- sbn.getPackageContext(mContext),
- contentContainerPublic, mOnClickHandler);
-
- if (publicViewLocal != null) {
- publicViewLocal.setIsRootNamespace(true);
- contentContainerPublic.setContractedChild(publicViewLocal);
- }
- }
- catch (RuntimeException e) {
- final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
- Log.e(TAG, "couldn't inflate public view for notification " + ident, e);
- publicViewLocal = null;
- }
+ if (publicViewLocal != null) {
+ publicViewLocal.setIsRootNamespace(true);
+ contentContainerPublic.setContractedChild(publicViewLocal);
}
// Extract target SDK version.
@@ -1446,65 +1436,7 @@
} catch (NameNotFoundException ex) {
Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
}
-
- if (publicViewLocal == null) {
- // Add a basic notification template
- publicViewLocal = LayoutInflater.from(mContext).inflate(
- R.layout.notification_public_default,
- contentContainerPublic, false);
- publicViewLocal.setIsRootNamespace(true);
-
- final TextView title = (TextView) publicViewLocal.findViewById(R.id.title);
- try {
- title.setText(pmUser.getApplicationLabel(
- pmUser.getApplicationInfo(entry.notification.getPackageName(), 0)));
- } catch (NameNotFoundException e) {
- title.setText(entry.notification.getPackageName());
- }
-
- final ImageView icon = (ImageView) publicViewLocal.findViewById(R.id.icon);
- final ImageView profileBadge = (ImageView) publicViewLocal.findViewById(
- R.id.profile_badge_line3);
-
- final StatusBarIcon ic = new StatusBarIcon(
- entry.notification.getUser(),
- entry.notification.getPackageName(),
- entry.notification.getNotification().getSmallIcon(),
- entry.notification.getNotification().iconLevel,
- entry.notification.getNotification().number,
- entry.notification.getNotification().tickerText);
-
- Drawable iconDrawable = StatusBarIconView.getIcon(mContext, ic);
- icon.setImageDrawable(iconDrawable);
-
- if (profileBadge != null) {
- Drawable profileDrawable = mContext.getPackageManager().getUserBadgeForDensity(
- entry.notification.getUser(), 0);
- if (profileDrawable != null) {
- profileBadge.setImageDrawable(profileDrawable);
- profileBadge.setVisibility(View.VISIBLE);
- } else {
- profileBadge.setVisibility(View.GONE);
- }
- }
-
- final View privateTime = contentViewLocal.findViewById(com.android.internal.R.id.time);
- final DateTimeView time = (DateTimeView) publicViewLocal.findViewById(R.id.time);
- if (privateTime != null && privateTime.getVisibility() == View.VISIBLE) {
- time.setVisibility(View.VISIBLE);
- time.setTime(entry.notification.getNotification().when);
- }
-
- final TextView text = (TextView) publicViewLocal.findViewById(R.id.text);
- if (text != null) {
- text.setText(R.string.notification_hidden_text);
- text.setTextAppearance(mContext,
- R.style.TextAppearance_Material_Notification_Parenthetical);
- }
-
- contentContainerPublic.setContractedChild(publicViewLocal);
- entry.autoRedacted = true;
- }
+ entry.autoRedacted = entry.notification.getNotification().publicVersion == null;
if (MULTIUSER_DEBUG) {
TextView debug = (TextView) row.findViewById(R.id.debug_info);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
index 1e73811..fc70ce3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
@@ -117,7 +117,7 @@
private OnClickListener mExpandClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
- if (mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
+ if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
mGroupManager.toggleGroupExpansion(mStatusBarNotification);
mOnExpandClickListener.onExpandClicked(ExpandableNotificationRow.this,
mGroupManager.isGroupExpanded(mStatusBarNotification));
@@ -212,6 +212,8 @@
mNotificationParent.updateChildrenHeaderAppearance();
}
onChildrenCountChanged();
+ // The public layouts expand button is always visible
+ mPublicLayout.updateExpandButtons(true);
updateLimits();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
index c458d21..f7680a7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
@@ -115,17 +115,14 @@
updatedNotificationBuilder.makeBigContentView();
final RemoteViews newHeadsUpContentView =
updatedNotificationBuilder.makeHeadsUpContentView();
- final Notification updatedPublicNotification = updatedNotification.publicVersion;
- final RemoteViews newPubContentView = (updatedPublicNotification != null)
- ? Notification.Builder.recoverBuilder(
- ctx, updatedPublicNotification).makeContentView()
- : null;
+ final RemoteViews newPublicNotification
+ = updatedNotificationBuilder.makePublicContentView();
applyInPlace = compareRemoteViews(cachedContentView, newContentView)
&& compareRemoteViews(cachedBigContentView, newBigContentView)
&& compareRemoteViews(cachedHeadsUpContentView, newHeadsUpContentView)
- && compareRemoteViews(cachedPublicContentView, newPubContentView);
- cachedPublicContentView = newPubContentView;
+ && compareRemoteViews(cachedPublicContentView, newPublicNotification);
+ cachedPublicContentView = newPublicNotification;
cachedHeadsUpContentView = newHeadsUpContentView;
cachedBigContentView = newBigContentView;
cachedContentView = newContentView;
@@ -136,14 +133,8 @@
cachedContentView = builder.makeContentView();
cachedBigContentView = builder.makeBigContentView();
cachedHeadsUpContentView = builder.makeHeadsUpContentView();
+ cachedPublicContentView = builder.makePublicContentView();
- final Notification publicNotification =
- notification.getNotification().publicVersion;
- if (publicNotification != null) {
- final Notification.Builder publicBuilder
- = Notification.Builder.recoverBuilder(ctx, publicNotification);
- cachedPublicContentView = publicBuilder.makeContentView();
- }
applyInPlace = false;
}
return applyInPlace;