diff --git a/api/current.txt b/api/current.txt index 10d55f5cb39a6..d4b0c27680738 100644 --- a/api/current.txt +++ b/api/current.txt @@ -41546,6 +41546,7 @@ package android.service.notification { field public static final android.os.Parcelable.Creator CREATOR; field public static final String KEY_CONTEXTUAL_ACTIONS = "key_contextual_actions"; field public static final String KEY_IMPORTANCE = "key_importance"; + field public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria"; field public static final String KEY_TEXT_REPLIES = "key_text_replies"; field public static final String KEY_USER_SENTIMENT = "key_user_sentiment"; } @@ -41603,12 +41604,14 @@ package android.service.notification { method public void onActionInvoked(@NonNull String, @NonNull android.app.Notification.Action, int); method public final android.os.IBinder onBind(android.content.Intent); method public void onNotificationDirectReplied(@NonNull String); - method public android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification); + method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification); method public android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, android.app.NotificationChannel); method public void onNotificationExpansionChanged(@NonNull String, boolean, boolean); method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap, android.service.notification.NotificationStats, int); + method public abstract void onNotificationSnoozedUntilContext(android.service.notification.StatusBarNotification, String); method public void onNotificationsSeen(java.util.List); method public void onSuggestedReplySent(@NonNull String, @NonNull CharSequence, int); + method public final void unsnoozeNotification(String); field public static final String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService"; field public static final int SOURCE_FROM_APP = 0; // 0x0 field public static final int SOURCE_FROM_ASSISTANT = 1; // 0x1 diff --git a/api/system-current.txt b/api/system-current.txt index c9b8c3867e592..c185f3c9afb76 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6500,6 +6500,15 @@ package android.service.euicc { package android.service.notification { + public final class Adjustment implements android.os.Parcelable { + ctor protected Adjustment(android.os.Parcel); + field public static final String KEY_PEOPLE = "key_people"; + } + + public final class NotificationStats implements android.os.Parcelable { + ctor protected NotificationStats(android.os.Parcel); + } + public final class SnoozeCriterion implements android.os.Parcelable { ctor public SnoozeCriterion(String, CharSequence, CharSequence); ctor protected SnoozeCriterion(android.os.Parcel); diff --git a/core/java/android/service/notification/Adjustment.java b/core/java/android/service/notification/Adjustment.java index 93189b310485f..2961426278dc9 100644 --- a/core/java/android/service/notification/Adjustment.java +++ b/core/java/android/service/notification/Adjustment.java @@ -15,6 +15,7 @@ */ package android.service.notification; +import android.annotation.SystemApi; import android.app.Notification; import android.os.Bundle; import android.os.Parcel; @@ -36,13 +37,13 @@ public final class Adjustment implements Parcelable { * See {@link android.app.Notification.Builder#addPerson(String)}. * @hide */ + @SystemApi public static final String KEY_PEOPLE = "key_people"; /** * Parcelable {@code ArrayList} of {@link SnoozeCriterion}. These criteria may be visible to * users. If a user chooses to snooze a notification until one of these criterion, the * assistant will be notified via * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}. - * @hide */ public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria"; /** @@ -111,7 +112,11 @@ public final class Adjustment implements Parcelable { mUser = user; } - private Adjustment(Parcel in) { + /** + * @hide + */ + @SystemApi + protected Adjustment(Parcel in) { if (in.readInt() == 1) { mPackage = in.readString(); } else { diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java index e93b1580bc660..a697248606343 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -21,6 +21,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.SdkConstant; +import android.annotation.SystemApi; import android.app.Notification; import android.app.NotificationChannel; import android.app.admin.DevicePolicyManager; @@ -103,7 +104,6 @@ public abstract class NotificationAssistantService extends NotificationListenerS * * @param sbn the notification to snooze * @param snoozeCriterionId the {@link SnoozeCriterion#getId()} representing a device context. - * @hide */ abstract public void onNotificationSnoozedUntilContext(StatusBarNotification sbn, String snoozeCriterionId); @@ -111,12 +111,13 @@ public abstract class NotificationAssistantService extends NotificationListenerS /** * A notification was posted by an app. Called before post. * + *

Note: this method is only called if you don't override + * {@link #onNotificationEnqueued(StatusBarNotification, NotificationChannel)}.

+ * * @param sbn the new notification * @return an adjustment or null to take no action, within 100ms. */ - public Adjustment onNotificationEnqueued(StatusBarNotification sbn) { - return null; - } + abstract public Adjustment onNotificationEnqueued(StatusBarNotification sbn); /** * A notification was posted by an app. Called before post. @@ -240,12 +241,11 @@ public abstract class NotificationAssistantService extends NotificationListenerS /** * Inform the notification manager about un-snoozing a specific notification. *

- * This should only be used for notifications snoozed by this listener using - * {@link #snoozeNotification(String, String)}. Once un-snoozed, you will get a + * This should only be used for notifications snoozed because of a contextual snooze suggestion + * you provided via {@link Adjustment#KEY_SNOOZE_CRITERIA}. Once un-snoozed, you will get a * {@link #onNotificationPosted(StatusBarNotification, RankingMap)} callback for the * notification. * @param key The key of the notification to snooze - * @hide */ public final void unsnoozeNotification(String key) { if (!isBound()) return; diff --git a/core/java/android/service/notification/NotificationStats.java b/core/java/android/service/notification/NotificationStats.java index 814b4772a395a..ebfabbfda3260 100644 --- a/core/java/android/service/notification/NotificationStats.java +++ b/core/java/android/service/notification/NotificationStats.java @@ -16,6 +16,7 @@ package android.service.notification; import android.annotation.IntDef; +import android.annotation.SystemApi; import android.app.RemoteInput; import android.os.Parcel; import android.os.Parcelable; @@ -98,7 +99,11 @@ public final class NotificationStats implements Parcelable { public NotificationStats() { } - private NotificationStats(Parcel in) { + /** + * @hide + */ + @SystemApi + protected NotificationStats(Parcel in) { mSeen = in.readByte() != 0; mExpanded = in.readByte() != 0; mDirectReplied = in.readByte() != 0; diff --git a/packages/ExtServices/src/android/ext/services/notification/Assistant.java b/packages/ExtServices/src/android/ext/services/notification/Assistant.java index b6b229c770b21..9360260f319e1 100644 --- a/packages/ExtServices/src/android/ext/services/notification/Assistant.java +++ b/packages/ExtServices/src/android/ext/services/notification/Assistant.java @@ -220,6 +220,12 @@ public class Assistant extends NotificationAssistantService { out.endDocument(); } + @Override + public Adjustment onNotificationEnqueued(StatusBarNotification sbn) { + // we use the version with channel, so this is never called. + return null; + } + @Override public Adjustment onNotificationEnqueued(StatusBarNotification sbn, NotificationChannel channel) {