diff options
| author | Julia Reynolds <juliacr@google.com> | 2018-10-24 09:22:38 -0400 |
|---|---|---|
| committer | Julia Reynolds <juliacr@google.com> | 2018-10-25 14:17:02 -0400 |
| commit | b6bd93d960676a407ef04cb58a15e9b3b187a42e (patch) | |
| tree | 13fa1306a70c260e7d0789ecc8df90c6c93122a2 /core/java/android/app/NotificationChannelGroup.java | |
| parent | 2a7854adddd652c7488a78fe93e2419b4e023854 (diff) | |
Add APIs for notification app overlays
- Can be enabled/disabled at channel and channel group levels
- An activity to launch can be added to notification
Test: atest, cts
Bug: 111236845
Change-Id: I9a4832211676cca4649d1f28e6e3e3157954d268
Diffstat (limited to 'core/java/android/app/NotificationChannelGroup.java')
| -rw-r--r-- | core/java/android/app/NotificationChannelGroup.java | 113 |
1 files changed, 93 insertions, 20 deletions
diff --git a/core/java/android/app/NotificationChannelGroup.java b/core/java/android/app/NotificationChannelGroup.java index 17c5cba3ed2c..2322a42c93d5 100644 --- a/core/java/android/app/NotificationChannelGroup.java +++ b/core/java/android/app/NotificationChannelGroup.java @@ -32,6 +32,7 @@ import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A grouping of related notification channels. e.g., channels that all belong to a single account. @@ -49,13 +50,33 @@ public final class NotificationChannelGroup implements Parcelable { private static final String ATT_DESC = "desc"; private static final String ATT_ID = "id"; private static final String ATT_BLOCKED = "blocked"; + private static final String ATT_ALLOW_APP_OVERLAY = "app_overlay"; + private static final String ATT_USER_LOCKED = "locked"; + private static final boolean DEFAULT_ALLOW_APP_OVERLAY = true; + + /** + * @hide + */ + public static final int USER_LOCKED_BLOCKED_STATE = 0x00000001; + /** + * @hide + */ + @TestApi + public static final int USER_LOCKED_ALLOW_APP_OVERLAY = 0x00000002; + + /** + * @see #getId() + */ @UnsupportedAppUsage private final String mId; private CharSequence mName; private String mDescription; private boolean mBlocked; private List<NotificationChannel> mChannels = new ArrayList<>(); + private boolean mAllowAppOverlay = DEFAULT_ALLOW_APP_OVERLAY; + // Bitwise representation of fields that have been changed by the user + private int mUserLockedFields; /** * Creates a notification channel group. @@ -89,6 +110,8 @@ public final class NotificationChannelGroup implements Parcelable { } in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader()); mBlocked = in.readBoolean(); + mAllowAppOverlay = in.readBoolean(); + mUserLockedFields = in.readInt(); } private String getTrimmedString(String input) { @@ -115,6 +138,8 @@ public final class NotificationChannelGroup implements Parcelable { } dest.writeParcelableList(mChannels, flags); dest.writeBoolean(mBlocked); + dest.writeBoolean(mAllowAppOverlay); + dest.writeInt(mUserLockedFields); } /** @@ -156,6 +181,15 @@ public final class NotificationChannelGroup implements Parcelable { } /** + * Returns whether notifications posted to this channel group can display outside of the + * notification shade, in a floating window on top of other apps. These may additionally be + * blocked at the notification channel level, see {@link NotificationChannel#canOverlayApps()}. + */ + public boolean canOverlayApps() { + return mAllowAppOverlay; + } + + /** * Sets the user visible description of this group. * * <p>The recommended maximum length is 300 characters; the value may be truncated if it is too @@ -166,6 +200,21 @@ public final class NotificationChannelGroup implements Parcelable { } /** + * Sets whether notifications posted to this channel group can appear outside of the + * notification shade, floating over other apps' content. + * + * <p>This value will be ignored for notifications that are posted to channels that do not + * allow app overlays ({@link NotificationChannel#canOverlayApps()}. + * + * <p>Only modifiable before the channel is submitted to + * {@link NotificationManager#createNotificationChannelGroup(NotificationChannelGroup)}.</p> + * @see Notification#getAppOverlayIntent() + */ + public void setAllowAppOverlay(boolean allowAppOverlay) { + mAllowAppOverlay = allowAppOverlay; + } + + /** * @hide */ @TestApi @@ -190,10 +239,34 @@ public final class NotificationChannelGroup implements Parcelable { /** * @hide */ + @TestApi + public void lockFields(int field) { + mUserLockedFields |= field; + } + + /** + * @hide + */ + public void unlockFields(int field) { + mUserLockedFields &= ~field; + } + + /** + * @hide + */ + @TestApi + public int getUserLockedFields() { + return mUserLockedFields; + } + + /** + * @hide + */ public void populateFromXml(XmlPullParser parser) { // Name, id, and importance are set in the constructor. setDescription(parser.getAttributeValue(null, ATT_DESC)); setBlocked(safeBool(parser, ATT_BLOCKED, false)); + setAllowAppOverlay(safeBool(parser, ATT_ALLOW_APP_OVERLAY, DEFAULT_ALLOW_APP_OVERLAY)); } private static boolean safeBool(XmlPullParser parser, String att, boolean defValue) { @@ -216,6 +289,10 @@ public final class NotificationChannelGroup implements Parcelable { out.attribute(null, ATT_DESC, getDescription().toString()); } out.attribute(null, ATT_BLOCKED, Boolean.toString(isBlocked())); + if (canOverlayApps() != DEFAULT_ALLOW_APP_OVERLAY) { + out.attribute(null, ATT_ALLOW_APP_OVERLAY, Boolean.toString(canOverlayApps())); + } + out.attribute(null, ATT_USER_LOCKED, Integer.toString(mUserLockedFields)); out.endTag(null, TAG_GROUP); } @@ -230,6 +307,8 @@ public final class NotificationChannelGroup implements Parcelable { record.put(ATT_NAME, getName()); record.put(ATT_DESC, getDescription()); record.put(ATT_BLOCKED, isBlocked()); + record.put(ATT_ALLOW_APP_OVERLAY, canOverlayApps()); + record.put(ATT_USER_LOCKED, mUserLockedFields); return record; } @@ -255,30 +334,20 @@ public final class NotificationChannelGroup implements Parcelable { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - NotificationChannelGroup that = (NotificationChannelGroup) o; - - if (isBlocked() != that.isBlocked()) return false; - if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false; - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) { - return false; - } - if (getDescription() != null ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - return getChannels() != null ? getChannels().equals(that.getChannels()) - : that.getChannels() == null; + return isBlocked() == that.isBlocked() && + mAllowAppOverlay == that.mAllowAppOverlay && + mUserLockedFields == that.mUserLockedFields && + Objects.equals(getId(), that.getId()) && + Objects.equals(getName(), that.getName()) && + Objects.equals(getDescription(), that.getDescription()) && + Objects.equals(getChannels(), that.getChannels()); } @Override public int hashCode() { - int result = getId() != null ? getId().hashCode() : 0; - result = 31 * result + (getName() != null ? getName().hashCode() : 0); - result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); - result = 31 * result + (isBlocked() ? 1 : 0); - result = 31 * result + (getChannels() != null ? getChannels().hashCode() : 0); - return result; + return Objects.hash(getId(), getName(), getDescription(), isBlocked(), getChannels(), + mAllowAppOverlay, mUserLockedFields); } @Override @@ -287,6 +356,8 @@ public final class NotificationChannelGroup implements Parcelable { cloned.setDescription(getDescription()); cloned.setBlocked(isBlocked()); cloned.setChannels(getChannels()); + cloned.setAllowAppOverlay(canOverlayApps()); + cloned.lockFields(mUserLockedFields); return cloned; } @@ -298,6 +369,8 @@ public final class NotificationChannelGroup implements Parcelable { + ", mDescription=" + (!TextUtils.isEmpty(mDescription) ? "hasDescription " : "") + ", mBlocked=" + mBlocked + ", mChannels=" + mChannels + + ", mAllowAppOverlay=" + mAllowAppOverlay + + ", mUserLockedFields=" + mUserLockedFields + '}'; } @@ -312,7 +385,7 @@ public final class NotificationChannelGroup implements Parcelable { for (NotificationChannel channel : mChannels) { channel.writeToProto(proto, NotificationChannelGroupProto.CHANNELS); } - + proto.write(NotificationChannelGroupProto.ALLOW_APP_OVERLAY, mAllowAppOverlay); proto.end(token); } } |
