BubbleMetadata flags: suppress initial notif & auto expand when posted
Test: atest NotificationTest
Bug: 111236845
Change-Id: Idd1d23a91f2bf45454d1598637c8d7979b7f5287
diff --git a/api/current.txt b/api/current.txt
index b9922f4..b5eb4c1 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5466,9 +5466,11 @@
public static final class Notification.BubbleMetadata implements android.os.Parcelable {
method public int describeContents();
+ method public boolean getAutoExpandBubble();
method public int getDesiredHeight();
method public android.graphics.drawable.Icon getIcon();
method public android.app.PendingIntent getIntent();
+ method public boolean getSuppressInitialNotification();
method public CharSequence getTitle();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.Notification.BubbleMetadata> CREATOR;
@@ -5477,9 +5479,11 @@
public static class Notification.BubbleMetadata.Builder {
ctor public Notification.BubbleMetadata.Builder();
method public android.app.Notification.BubbleMetadata build();
+ method public android.app.Notification.BubbleMetadata.Builder setAutoExpandBubble(boolean);
method public android.app.Notification.BubbleMetadata.Builder setDesiredHeight(int);
method public android.app.Notification.BubbleMetadata.Builder setIcon(android.graphics.drawable.Icon);
method public android.app.Notification.BubbleMetadata.Builder setIntent(android.app.PendingIntent);
+ method public android.app.Notification.BubbleMetadata.Builder setSuppressInitialNotification(boolean);
method public android.app.Notification.BubbleMetadata.Builder setTitle(CharSequence);
}
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index b8d748d..a8f2400 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -84,7 +84,6 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ContrastColorUtil;
-import com.android.internal.util.Preconditions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -8399,6 +8398,30 @@
private CharSequence mTitle;
private Icon mIcon;
private int mDesiredHeight;
+ private int mFlags;
+
+ /**
+ * If set and the app creating the bubble is in the foreground, the bubble will be posted
+ * in its expanded state, with the contents of {@link #getIntent()} in a floating window.
+ *
+ * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p>
+ *
+ * <p>Generally this flag should only be set if the user has performed an action to request
+ * or create a bubble.</p>
+ */
+ private static final int FLAG_AUTO_EXPAND_BUBBLE = 0x00000001;
+
+ /**
+ * If set and the app creating the bubble is in the foreground, the bubble will be posted
+ * <b>without</b> the associated notification in the notification shade. Subsequent update
+ * notifications to this bubble will post a notification in the shade.
+ *
+ * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p>
+ *
+ * <p>Generally this flag should only be set if the user has performed an action to request
+ * or create a bubble.</p>
+ */
+ private static final int FLAG_SUPPRESS_INITIAL_NOTIFICATION = 0x00000002;
private BubbleMetadata(PendingIntent intent, CharSequence title, Icon icon, int height) {
mPendingIntent = intent;
@@ -8412,6 +8435,7 @@
mTitle = in.readCharSequence();
mIcon = Icon.CREATOR.createFromParcel(in);
mDesiredHeight = in.readInt();
+ mFlags = in.readInt();
}
/**
@@ -8444,6 +8468,24 @@
return mDesiredHeight;
}
+ /**
+ * @return whether this bubble should auto expand when it is posted.
+ *
+ * @see BubbleMetadata.Builder#setAutoExpandBubble(boolean)
+ */
+ public boolean getAutoExpandBubble() {
+ return (mFlags & FLAG_AUTO_EXPAND_BUBBLE) != 0;
+ }
+
+ /**
+ * @return whether this bubble should suppress the initial notification when it is posted.
+ *
+ * @see BubbleMetadata.Builder#setSuppressInitialNotification(boolean)
+ */
+ public boolean getSuppressInitialNotification() {
+ return (mFlags & FLAG_SUPPRESS_INITIAL_NOTIFICATION) != 0;
+ }
+
public static final Parcelable.Creator<BubbleMetadata> CREATOR =
new Parcelable.Creator<BubbleMetadata>() {
@@ -8469,6 +8511,11 @@
out.writeCharSequence(mTitle);
mIcon.writeToParcel(out, 0);
out.writeInt(mDesiredHeight);
+ out.writeInt(mFlags);
+ }
+
+ private void setFlags(int flags) {
+ mFlags = flags;
}
/**
@@ -8480,6 +8527,7 @@
private CharSequence mTitle;
private Icon mIcon;
private int mDesiredHeight;
+ private int mFlags;
/**
* Constructs a new builder object.
@@ -8539,6 +8587,39 @@
}
/**
+ * If set and the app creating the bubble is in the foreground, the bubble will be
+ * posted in its expanded state, with the contents of {@link #getIntent()} in a
+ * floating window.
+ *
+ * <p>If the app creating the bubble is not in the foreground this flag has no effect.
+ * </p>
+ *
+ * <p>Generally this flag should only be set if the user has performed an action to
+ * request or create a bubble.</p>
+ */
+ public BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand) {
+ setFlag(FLAG_AUTO_EXPAND_BUBBLE, shouldExpand);
+ return this;
+ }
+
+ /**
+ * If set and the app creating the bubble is in the foreground, the bubble will be
+ * posted <b>without</b> the associated notification in the notification shade.
+ * Subsequent update notifications to this bubble will post a notification in the shade.
+ *
+ * <p>If the app creating the bubble is not in the foreground this flag has no effect.
+ * </p>
+ *
+ * <p>Generally this flag should only be set if the user has performed an action to
+ * request or create a bubble.</p>
+ */
+ public BubbleMetadata.Builder setSuppressInitialNotification(
+ boolean shouldSupressNotif) {
+ setFlag(FLAG_SUPPRESS_INITIAL_NOTIFICATION, shouldSupressNotif);
+ return this;
+ }
+
+ /**
* Creates the {@link BubbleMetadata} defined by this builder.
* <p>Will throw {@link IllegalStateException} if required fields have not been set
* on this builder.</p>
@@ -8553,7 +8634,22 @@
if (mIcon == null) {
throw new IllegalStateException("Must supply an icon for the bubble");
}
- return new BubbleMetadata(mPendingIntent, mTitle, mIcon, mDesiredHeight);
+ BubbleMetadata data = new BubbleMetadata(mPendingIntent, mTitle, mIcon,
+ mDesiredHeight);
+ data.setFlags(mFlags);
+ return data;
+ }
+
+ /**
+ * @hide
+ */
+ public BubbleMetadata.Builder setFlag(int mask, boolean value) {
+ if (value) {
+ mFlags |= mask;
+ } else {
+ mFlags &= ~mask;
+ }
+ return this;
}
}
}