summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adrian Roos <roosa@google.com> 2016-03-08 21:47:02 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-03-08 21:47:03 +0000
commit37b3a4a5440f489f65941b8182b33c34f86ffc1d (patch)
tree2f559ecee66c5e1e594d2dec724f2b2b8201fd56
parentd06e5afd6fef030e731d6c92166dbff70844f88f (diff)
parent184bfe029ec7053418696517987b164a7a224e36 (diff)
Merge "Fix and optimize stripForDelivery" into nyc-dev
-rw-r--r--core/java/android/app/Notification.java58
-rw-r--r--core/java/android/app/NotificationManager.java3
2 files changed, 38 insertions, 23 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index d8f0ac518151..5e32932b50fa 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -3591,37 +3591,53 @@ public class Notification implements Parcelable
}
/**
+ * Removes RemoteViews that were created for compatibility from {@param n}, if they did not
+ * change.
+ *
+ * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}.
+ *
* @hide
*/
- public static void stripForDelivery(Notification n) {
+ public static Notification maybeCloneStrippedForDelivery(Notification n) {
String templateClass = n.extras.getString(EXTRA_TEMPLATE);
- if (TextUtils.isEmpty(templateClass)) {
- return;
- }
+
// Only strip views for known Styles because we won't know how to
// re-create them otherwise.
- if (getNotificationStyleClass(templateClass) == null) {
- return;
+ if (!TextUtils.isEmpty(templateClass)
+ && getNotificationStyleClass(templateClass) == null) {
+ return n;
}
- // Get rid of unmodified BuilderRemoteViews.
- if (n.contentView instanceof BuilderRemoteViews &&
+
+ // Only strip unmodified BuilderRemoteViews.
+ boolean stripContentView = n.contentView instanceof BuilderRemoteViews &&
n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) ==
- n.contentView.getSequenceNumber()) {
- n.contentView = null;
- n.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT);
- }
- if (n.bigContentView instanceof BuilderRemoteViews &&
+ n.contentView.getSequenceNumber();
+ boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews &&
n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) ==
- n.bigContentView.getSequenceNumber()) {
- n.bigContentView = null;
- n.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT);
- }
- if (n.headsUpContentView instanceof BuilderRemoteViews &&
+ n.bigContentView.getSequenceNumber();
+ boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews &&
n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) ==
- n.headsUpContentView.getSequenceNumber()) {
- n.headsUpContentView = null;
- n.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT);
+ n.headsUpContentView.getSequenceNumber();
+
+ // Nothing to do here, no need to clone.
+ if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) {
+ return n;
+ }
+
+ Notification clone = n.clone();
+ if (stripContentView) {
+ clone.contentView = null;
+ clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT);
+ }
+ if (stripBigContentView) {
+ clone.bigContentView = null;
+ clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT);
+ }
+ if (stripHeadsUpContentView) {
+ clone.headsUpContentView = null;
+ clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT);
}
+ return clone;
}
private int getBaseLayoutResource() {
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 16aee786d80c..7cfa0cd36102 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -259,8 +259,7 @@ public class NotificationManager
}
}
if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
- final Notification copy = notification.clone();
- Builder.stripForDelivery(copy);
+ final Notification copy = Builder.maybeCloneStrippedForDelivery(notification);
try {
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
copy, idOut, user.getIdentifier());