diff options
7 files changed, 52 insertions, 42 deletions
diff --git a/api/current.txt b/api/current.txt index 359ce3aa4373..26c90dff3c6b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5320,10 +5320,12 @@ package android.app { ctor public Notification(android.os.Parcel); method public android.app.Notification clone(); method public int describeContents(); + method @Nullable public android.util.Pair<android.app.RemoteInput,android.app.Notification.Action> findRemoteInputActionPair(boolean); method public boolean getAllowSystemGeneratedContextualActions(); method public int getBadgeIconType(); method @Nullable public android.app.Notification.BubbleMetadata getBubbleMetadata(); method public String getChannelId(); + method @NonNull public java.util.List<android.app.Notification.Action> getContextualActions(); method public String getGroup(); method public int getGroupAlertBehavior(); method public android.graphics.drawable.Icon getLargeIcon(); @@ -5719,6 +5721,7 @@ package android.app { method public String getDataMimeType(); method public android.net.Uri getDataUri(); method public android.os.Bundle getExtras(); + method @NonNull public static java.util.List<android.app.Notification.MessagingStyle.Message> getMessagesFromBundleArray(@Nullable android.os.Parcelable[]); method @Deprecated public CharSequence getSender(); method @Nullable public android.app.Person getSenderPerson(); method public CharSequence getText(); @@ -5816,6 +5819,7 @@ package android.app { method public android.net.Uri getSound(); method public long[] getVibrationPattern(); method public boolean hasUserSetImportance(); + method public boolean hasUserSetSound(); method public void setAllowBubbles(boolean); method public void setBypassDnd(boolean); method public void setDescription(String); @@ -41736,6 +41740,7 @@ package android.service.notification { method public int getUid(); method public android.os.UserHandle getUser(); method @Deprecated public int getUserId(); + method public boolean isAppGroup(); method public boolean isClearable(); method public boolean isGroup(); method public boolean isOngoing(); diff --git a/api/system-current.txt b/api/system-current.txt index 1c5f772f2e1b..8ee6e639cbe8 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -521,8 +521,6 @@ package android.app { } public class Notification implements android.os.Parcelable { - method @Nullable public android.util.Pair<android.app.RemoteInput,android.app.Notification.Action> findRemoteInputActionPair(boolean); - method @NonNull public java.util.List<android.app.Notification.Action> getContextualActions(); field public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; field public static final String CATEGORY_CAR_INFORMATION = "car_information"; field public static final String CATEGORY_CAR_WARNING = "car_warning"; @@ -531,10 +529,6 @@ package android.app { field public static final int FLAG_AUTOGROUP_SUMMARY = 1024; // 0x400 } - public static final class Notification.MessagingStyle.Message { - method @Nullable public static android.app.Notification.MessagingStyle.Message getMessageFromBundle(@NonNull android.os.Bundle); - } - public static final class Notification.TvExtender implements android.app.Notification.Extender { ctor public Notification.TvExtender(); ctor public Notification.TvExtender(android.app.Notification); @@ -6710,10 +6704,6 @@ package android.service.notification { field @NonNull public static final android.os.Parcelable.Creator<android.service.notification.SnoozeCriterion> CREATOR; } - public class StatusBarNotification implements android.os.Parcelable { - method public boolean isAppGroup(); - } - } package android.service.oemlock { diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index f065ff791dce..bb4e99873f26 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3274,11 +3274,8 @@ public class Notification implements Parcelable * * @param requiresFreeform requires the remoteinput to allow freeform or not. * @return the result pair, {@code null} if no result is found. - * - * @hide */ @Nullable - @SystemApi public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { if (actions == null) { return null; @@ -3301,11 +3298,9 @@ public class Notification implements Parcelable } /** - * Returns the actions that are contextual out of the actions in this notification. - * - * @hide + * Returns the actions that are contextual (that is, suggested because of the content of the + * notification) out of the actions in this notification. */ - @SystemApi public @NonNull List<Notification.Action> getContextualActions() { if (actions == null) return Collections.emptyList(); @@ -7705,11 +7700,11 @@ public class Notification implements Parcelable } /** - * @return A list of messages read from the bundles. - * - * @hide + * Returns a list of messages read from the given bundle list, e.g. + * {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}. */ - public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { + @NonNull + public static List<Message> getMessagesFromBundleArray(@Nullable Parcelable[] bundles) { if (bundles == null) { return new ArrayList<>(); } @@ -7726,13 +7721,12 @@ public class Notification implements Parcelable } /** - * @return The message that is stored in the bundle or null if the message couldn't be - * resolved. - * + * Returns the message that is stored in the bundle (e.g. one of the values in the lists + * in {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}) or null if the + * message couldn't be resolved. * @hide */ @Nullable - @SystemApi public static Message getMessageFromBundle(@NonNull Bundle bundle) { try { if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 93e4ddcbb016..20d977b7da10 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -710,6 +710,14 @@ public final class NotificationChannel implements Parcelable { } /** + * Returns whether the user has chosen the sound of this channel. + * @see #getSound() + */ + public boolean hasUserSetSound() { + return (mUserLockedFields & USER_LOCKED_SOUND) != 0; + } + + /** * @hide */ public void populateFromXmlForRestore(XmlPullParser parser, Context context) { diff --git a/core/java/android/service/notification/StatusBarNotification.java b/core/java/android/service/notification/StatusBarNotification.java index 205df7e12483..b8378a3474ac 100644 --- a/core/java/android/service/notification/StatusBarNotification.java +++ b/core/java/android/service/notification/StatusBarNotification.java @@ -170,10 +170,7 @@ public class StatusBarNotification implements Parcelable { /** * Returns true if application asked that this notification be part of a group. - * - * @hide */ - @SystemApi public boolean isAppGroup() { if (getNotification().getGroup() != null || getNotification().getSortKey() != null) { return true; diff --git a/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java b/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java index 6161108d4d70..a5a98a98f0be 100644 --- a/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java +++ b/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java @@ -19,6 +19,8 @@ package android.service.notification; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -181,6 +183,22 @@ public class StatusBarNotificationTest { logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_STYLE)); } + @Test + public void testIsAppGroup() { + StatusBarNotification sbn = getNotification(PKG, GROUP_ID_1, CHANNEL_ID); + assertTrue(sbn.isAppGroup()); + + sbn = getNotification(PKG, null, CHANNEL_ID); + assertFalse(sbn.isAppGroup()); + + Notification.Builder nb = getNotificationBuilder(null, CHANNEL_ID) + .setSortKey("something"); + + sbn = getNotification(PKG, nb); + assertTrue(sbn.isAppGroup()); + + } + private StatusBarNotification getNotification(String pkg, String group, String channelId) { return getNotification(pkg, getNotificationBuilder(group, channelId)); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index 2964889f1399..cd40f0c0ab4e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -31,6 +31,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BA import android.annotation.NonNull; import android.app.Notification; +import android.app.Notification.MessagingStyle.Message; import android.app.NotificationChannel; import android.app.NotificationManager.Policy; import android.app.Person; @@ -545,21 +546,18 @@ public final class NotificationEntry { if (!ArrayUtils.isEmpty(replyTexts)) { return true; } - Parcelable[] messages = extras.getParcelableArray(Notification.EXTRA_MESSAGES); - if (messages != null && messages.length > 0) { - Parcelable message = messages[messages.length - 1]; - if (message instanceof Bundle) { - Notification.MessagingStyle.Message lastMessage = - Notification.MessagingStyle.Message.getMessageFromBundle( - (Bundle) message); - if (lastMessage != null) { - Person senderPerson = lastMessage.getSenderPerson(); - if (senderPerson == null) { - return true; - } - Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON); - return Objects.equals(user, senderPerson); + List<Message> messages = Message.getMessagesFromBundleArray( + extras.getParcelableArray(Notification.EXTRA_MESSAGES)); + if (messages != null && !messages.isEmpty()) { + Message lastMessage = messages.get(messages.size() -1); + + if (lastMessage != null) { + Person senderPerson = lastMessage.getSenderPerson(); + if (senderPerson == null) { + return true; } + Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON); + return Objects.equals(user, senderPerson); } } return false; |