diff options
| -rw-r--r-- | api/current.txt | 41 | ||||
| -rw-r--r-- | api/system-current.txt | 41 | ||||
| -rw-r--r-- | api/test-current.txt | 41 | ||||
| -rw-r--r-- | core/java/android/service/notification/INotificationListener.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/service/notification/NotificationAssistantService.java | 85 | ||||
| -rw-r--r-- | core/java/android/service/notification/NotificationListenerService.java | 81 | ||||
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationManagerService.java | 49 |
7 files changed, 162 insertions, 179 deletions
diff --git a/api/current.txt b/api/current.txt index dda8ce35daf5..29411cd7344e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -32080,10 +32080,10 @@ package android.provider { field public static final java.lang.String EXTRA_ERROR = "error"; field public static final java.lang.String EXTRA_EXCLUDE_SELF = "android.provider.extra.EXCLUDE_SELF"; field public static final java.lang.String EXTRA_INFO = "info"; + field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String EXTRA_LOADING = "loading"; field public static final java.lang.String EXTRA_ORIENTATION = "android.provider.extra.ORIENTATION"; field public static final java.lang.String EXTRA_PROMPT = "android.provider.extra.PROMPT"; - field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER"; } @@ -34917,25 +34917,6 @@ package android.service.notification { method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>); method public final android.os.IBinder onBind(android.content.Intent); method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean); - method public void onNotificationRemoved(java.lang.String, long, int); - field public static final int REASON_APP_CANCEL = 8; // 0x8 - field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 - field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 - field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 - field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 - field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 - field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 - field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd - field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc - field public static final int REASON_LISTENER_CANCEL = 10; // 0xa - field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb - field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 - field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 - field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe - field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf - field public static final int REASON_SNOOZED = 18; // 0x12 - field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 - field public static final int REASON_USER_STOPPED = 6; // 0x6 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService"; } @@ -34960,6 +34941,7 @@ package android.service.notification { method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap); method public void onNotificationRemoved(android.service.notification.StatusBarNotification); method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap); + method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap, int); method public final void requestInterruptionFilter(int); method public final void requestListenerHints(int); method public static void requestRebind(android.content.ComponentName); @@ -34974,6 +34956,25 @@ package android.service.notification { field public static final int INTERRUPTION_FILTER_NONE = 3; // 0x3 field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2 field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0 + field public static final int REASON_APP_CANCEL = 8; // 0x8 + field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 + field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 + field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 + field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 + field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 + field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 + field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd + field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc + field public static final int REASON_LISTENER_CANCEL = 10; // 0xa + field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb + field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 + field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 + field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe + field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf + field public static final int REASON_SNOOZED = 18; // 0x12 + field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 + field public static final int REASON_USER_STOPPED = 6; // 0x6 + field public static final int REASON_USER_SWITCH = 19; // 0x13 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService"; field public static final int SUPPRESSED_EFFECT_SCREEN_OFF = 1; // 0x1 field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 2; // 0x2 diff --git a/api/system-current.txt b/api/system-current.txt index 42aa329b110c..c528a18576c2 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -34768,10 +34768,10 @@ package android.provider { field public static final java.lang.String EXTRA_ERROR = "error"; field public static final java.lang.String EXTRA_EXCLUDE_SELF = "android.provider.extra.EXCLUDE_SELF"; field public static final java.lang.String EXTRA_INFO = "info"; + field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String EXTRA_LOADING = "loading"; field public static final java.lang.String EXTRA_ORIENTATION = "android.provider.extra.ORIENTATION"; field public static final java.lang.String EXTRA_PROMPT = "android.provider.extra.PROMPT"; - field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER"; } @@ -37710,25 +37710,6 @@ package android.service.notification { method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>); method public final android.os.IBinder onBind(android.content.Intent); method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean); - method public void onNotificationRemoved(java.lang.String, long, int); - field public static final int REASON_APP_CANCEL = 8; // 0x8 - field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 - field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 - field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 - field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 - field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 - field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 - field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd - field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc - field public static final int REASON_LISTENER_CANCEL = 10; // 0xa - field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb - field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 - field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 - field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe - field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf - field public static final int REASON_SNOOZED = 18; // 0x12 - field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 - field public static final int REASON_USER_STOPPED = 6; // 0x6 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService"; } @@ -37755,6 +37736,7 @@ package android.service.notification { method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap); method public void onNotificationRemoved(android.service.notification.StatusBarNotification); method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap); + method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap, int); method public void registerAsSystemService(android.content.Context, android.content.ComponentName, int) throws android.os.RemoteException; method public final void requestInterruptionFilter(int); method public final void requestListenerHints(int); @@ -37772,6 +37754,25 @@ package android.service.notification { field public static final int INTERRUPTION_FILTER_NONE = 3; // 0x3 field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2 field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0 + field public static final int REASON_APP_CANCEL = 8; // 0x8 + field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 + field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 + field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 + field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 + field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 + field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 + field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd + field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc + field public static final int REASON_LISTENER_CANCEL = 10; // 0xa + field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb + field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 + field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 + field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe + field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf + field public static final int REASON_SNOOZED = 18; // 0x12 + field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 + field public static final int REASON_USER_STOPPED = 6; // 0x6 + field public static final int REASON_USER_SWITCH = 19; // 0x13 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService"; field public static final int SUPPRESSED_EFFECT_SCREEN_OFF = 1; // 0x1 field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 2; // 0x2 diff --git a/api/test-current.txt b/api/test-current.txt index 13f31038960c..23dfb32fbf1c 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -32166,10 +32166,10 @@ package android.provider { field public static final java.lang.String EXTRA_ERROR = "error"; field public static final java.lang.String EXTRA_EXCLUDE_SELF = "android.provider.extra.EXCLUDE_SELF"; field public static final java.lang.String EXTRA_INFO = "info"; + field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String EXTRA_LOADING = "loading"; field public static final java.lang.String EXTRA_ORIENTATION = "android.provider.extra.ORIENTATION"; field public static final java.lang.String EXTRA_PROMPT = "android.provider.extra.PROMPT"; - field public static final java.lang.String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; field public static final java.lang.String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER"; } @@ -35007,25 +35007,6 @@ package android.service.notification { method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>); method public final android.os.IBinder onBind(android.content.Intent); method public abstract android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean); - method public void onNotificationRemoved(java.lang.String, long, int); - field public static final int REASON_APP_CANCEL = 8; // 0x8 - field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 - field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 - field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 - field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 - field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 - field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 - field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd - field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc - field public static final int REASON_LISTENER_CANCEL = 10; // 0xa - field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb - field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 - field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 - field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe - field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf - field public static final int REASON_SNOOZED = 18; // 0x12 - field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 - field public static final int REASON_USER_STOPPED = 6; // 0x6 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService"; } @@ -35050,6 +35031,7 @@ package android.service.notification { method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap); method public void onNotificationRemoved(android.service.notification.StatusBarNotification); method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap); + method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap, int); method public final void requestInterruptionFilter(int); method public final void requestListenerHints(int); method public static void requestRebind(android.content.ComponentName); @@ -35064,6 +35046,25 @@ package android.service.notification { field public static final int INTERRUPTION_FILTER_NONE = 3; // 0x3 field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2 field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0 + field public static final int REASON_APP_CANCEL = 8; // 0x8 + field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9 + field public static final int REASON_CHANNEL_BANNED = 17; // 0x11 + field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2 + field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3 + field public static final int REASON_DELEGATE_CLICK = 1; // 0x1 + field public static final int REASON_DELEGATE_ERROR = 4; // 0x4 + field public static final int REASON_GROUP_OPTIMIZATION = 13; // 0xd + field public static final int REASON_GROUP_SUMMARY_CANCELED = 12; // 0xc + field public static final int REASON_LISTENER_CANCEL = 10; // 0xa + field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb + field public static final int REASON_PACKAGE_BANNED = 7; // 0x7 + field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5 + field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe + field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf + field public static final int REASON_SNOOZED = 18; // 0x12 + field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10 + field public static final int REASON_USER_STOPPED = 6; // 0x6 + field public static final int REASON_USER_SWITCH = 19; // 0x13 field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService"; field public static final int SUPPRESSED_EFFECT_SCREEN_OFF = 1; // 0x1 field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 2; // 0x2 diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl index 8c359012bc51..f639c0de2044 100644 --- a/core/java/android/service/notification/INotificationListener.aidl +++ b/core/java/android/service/notification/INotificationListener.aidl @@ -28,7 +28,7 @@ oneway interface INotificationListener void onNotificationPosted(in IStatusBarNotificationHolder notificationHolder, in NotificationRankingUpdate update); void onNotificationRemoved(in IStatusBarNotificationHolder notificationHolder, - in NotificationRankingUpdate update); + in NotificationRankingUpdate update, int reason); void onNotificationRankingUpdate(in NotificationRankingUpdate update); void onListenerHintsChanged(int hints); void onInterruptionFilterChanged(int interruptionFilter); @@ -38,5 +38,4 @@ oneway interface INotificationListener void onNotificationVisibilityChanged(String key, long time, boolean visible); void onNotificationClick(String key, long time); void onNotificationActionClick(String key, long time, int actionIndex); - void onNotificationRemovedReason(String key, long time, int reason); } diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java index fdf1b26aad62..4e00c643d749 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -42,60 +42,6 @@ public abstract class NotificationAssistantService extends NotificationListenerS public static final String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService"; - /** Notification was canceled by the status bar reporting a click. */ - public static final int REASON_DELEGATE_CLICK = 1; - - /** Notification was canceled by the status bar reporting a user dismissal. */ - public static final int REASON_DELEGATE_CANCEL = 2; - - /** Notification was canceled by the status bar reporting a user dismiss all. */ - public static final int REASON_DELEGATE_CANCEL_ALL = 3; - - /** Notification was canceled by the status bar reporting an inflation error. */ - public static final int REASON_DELEGATE_ERROR = 4; - - /** Notification was canceled by the package manager modifying the package. */ - public static final int REASON_PACKAGE_CHANGED = 5; - - /** Notification was canceled by the owning user context being stopped. */ - public static final int REASON_USER_STOPPED = 6; - - /** Notification was canceled by the user banning the package. */ - public static final int REASON_PACKAGE_BANNED = 7; - - /** Notification was canceled by the app canceling this specific notification. */ - public static final int REASON_APP_CANCEL = 8; - - /** Notification was canceled by the app cancelling all its notifications. */ - public static final int REASON_APP_CANCEL_ALL = 9; - - /** Notification was canceled by a listener reporting a user dismissal. */ - public static final int REASON_LISTENER_CANCEL = 10; - - /** Notification was canceled by a listener reporting a user dismiss all. */ - public static final int REASON_LISTENER_CANCEL_ALL = 11; - - /** Notification was canceled because it was a member of a canceled group. */ - public static final int REASON_GROUP_SUMMARY_CANCELED = 12; - - /** Notification was canceled because it was an invisible member of a group. */ - public static final int REASON_GROUP_OPTIMIZATION = 13; - - /** Notification was canceled by the device administrator suspending the package. */ - public static final int REASON_PACKAGE_SUSPENDED = 14; - - /** Notification was canceled by the owning managed profile being turned off. */ - public static final int REASON_PROFILE_TURNED_OFF = 15; - - /** Autobundled summary notification was canceled because its group was unbundled */ - public static final int REASON_UNAUTOBUNDLED = 16; - - /** Notification was canceled by the user banning the channel. */ - public static final int REASON_CHANNEL_BANNED = 17; - - /** Notification was snoozed. */ - public static final int REASON_SNOOZED = 18; - private Handler mHandler; @Override @@ -124,17 +70,6 @@ public abstract class NotificationAssistantService extends NotificationListenerS int importance, boolean user); /** - * A notification was removed. - - * @param key the notification key - * @param time milliseconds since midnight, January 1, 1970 UTC. - * @param reason see {@link #REASON_LISTENER_CANCEL}, etc. - */ - public void onNotificationRemoved(String key, long time, int reason) { - // Do nothing, Override this to collect dismissal statistics - } - - /** * Updates a notification. N.B. this won’t cause * an existing notification to alert, but might allow a future update to * this notification to alert. @@ -185,21 +120,10 @@ public abstract class NotificationAssistantService extends NotificationListenerS mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_ENQUEUED, args).sendToTarget(); } - - @Override - public void onNotificationRemovedReason(String key, long time, int reason) { - SomeArgs args = SomeArgs.obtain(); - args.arg1 = key; - args.arg2 = time; - args.argi1 = reason; - mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_REMOVED_REASON, - args).sendToTarget(); - } } private final class MyHandler extends Handler { public static final int MSG_ON_NOTIFICATION_ENQUEUED = 1; - public static final int MSG_ON_NOTIFICATION_REMOVED_REASON = 5; public MyHandler(Looper looper) { super(looper, null, false); @@ -219,15 +143,6 @@ public abstract class NotificationAssistantService extends NotificationListenerS adjustNotification(adjustment); } } break; - - case MSG_ON_NOTIFICATION_REMOVED_REASON: { - SomeArgs args = (SomeArgs) msg.obj; - final String key = (String) args.arg1; - final long time = (long) args.arg2; - final int reason = args.argi1; - args.recycle(); - onNotificationRemoved(key, time, reason); - } break; } } } diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index e606ebfbfee6..45011eb49905 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -77,6 +77,7 @@ import java.util.List; * </p> */ public abstract class NotificationListenerService extends Service { + // TAG = "NotificationListenerService[MySubclass]" private final String TAG = NotificationListenerService.class.getSimpleName() + "[" + getClass().getSimpleName() + "]"; @@ -146,6 +147,48 @@ public abstract class NotificationListenerService extends Service { public static final int SUPPRESSED_EFFECT_SCREEN_ON = NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON; + + // Notification cancellation reasons + + /** Notification was canceled by the status bar reporting a click. */ + public static final int REASON_DELEGATE_CLICK = 1; + /** Notification was canceled by the status bar reporting a user dismissal. */ + public static final int REASON_DELEGATE_CANCEL = 2; + /** Notification was canceled by the status bar reporting a user dismiss all. */ + public static final int REASON_DELEGATE_CANCEL_ALL = 3; + /** Notification was canceled by the status bar reporting an inflation error. */ + public static final int REASON_DELEGATE_ERROR = 4; + /** Notification was canceled by the package manager modifying the package. */ + public static final int REASON_PACKAGE_CHANGED = 5; + /** Notification was canceled by the owning user context being stopped. */ + public static final int REASON_USER_STOPPED = 6; + /** Notification was canceled by the user banning the package. */ + public static final int REASON_PACKAGE_BANNED = 7; + /** Notification was canceled by the app canceling this specific notification. */ + public static final int REASON_APP_CANCEL = 8; + /** Notification was canceled by the app cancelling all its notifications. */ + public static final int REASON_APP_CANCEL_ALL = 9; + /** Notification was canceled by a listener reporting a user dismissal. */ + public static final int REASON_LISTENER_CANCEL = 10; + /** Notification was canceled by a listener reporting a user dismiss all. */ + public static final int REASON_LISTENER_CANCEL_ALL = 11; + /** Notification was canceled because it was a member of a canceled group. */ + public static final int REASON_GROUP_SUMMARY_CANCELED = 12; + /** Notification was canceled because it was an invisible member of a group. */ + public static final int REASON_GROUP_OPTIMIZATION = 13; + /** Notification was canceled by the device administrator suspending the package. */ + public static final int REASON_PACKAGE_SUSPENDED = 14; + /** Notification was canceled by the owning managed profile being turned off. */ + public static final int REASON_PROFILE_TURNED_OFF = 15; + /** Autobundled summary notification was canceled because its group was unbundled */ + public static final int REASON_UNAUTOBUNDLED = 16; + /** Notification was canceled by the user banning the channel. */ + public static final int REASON_CHANNEL_BANNED = 17; + /** Notification was snoozed. */ + public static final int REASON_SNOOZED = 18; + /** Notification no longer visible because of user switch */ + public static final int REASON_USER_SWITCH = 19; + /** * The full trim of the StatusBarNotification including all its features. * @@ -282,6 +325,32 @@ public abstract class NotificationListenerService extends Service { onNotificationRemoved(sbn); } + + /** + * Implement this method to learn when notifications are removed and why. + * <p> + * This might occur because the user has dismissed the notification using system UI (or another + * notification listener) or because the app has withdrawn the notification. + * <p> + * NOTE: The {@link StatusBarNotification} object you receive will be "light"; that is, the + * result from {@link StatusBarNotification#getNotification} may be missing some heavyweight + * fields such as {@link android.app.Notification#contentView} and + * {@link android.app.Notification#largeIcon}. However, all other fields on + * {@link StatusBarNotification}, sufficient to match this call with a prior call to + * {@link #onNotificationPosted(StatusBarNotification)}, will be intact. + * + ** @param sbn A data structure encapsulating at least the original information (tag and id) + * and source (package name) used to post the {@link android.app.Notification} that + * was just removed. + * @param rankingMap The current ranking map that can be used to retrieve ranking information + * for active notifications. + * @param reason see {@link #REASON_LISTENER_CANCEL}, etc. + */ + public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, + int reason) { + onNotificationRemoved(sbn, rankingMap); + } + /** * Implement this method to learn about when the listener is enabled and connected to * the notification manager. You are safe to call {@link #getActiveNotifications()} @@ -927,7 +996,7 @@ public abstract class NotificationListenerService extends Service { @Override public void onNotificationRemoved(IStatusBarNotificationHolder sbnHolder, - NotificationRankingUpdate update) { + NotificationRankingUpdate update, int reason) { StatusBarNotification sbn; try { sbn = sbnHolder.get(); @@ -941,6 +1010,7 @@ public abstract class NotificationListenerService extends Service { SomeArgs args = SomeArgs.obtain(); args.arg1 = sbn; args.arg2 = mRankingMap; + args.arg3 = reason; mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_REMOVED, args).sendToTarget(); } @@ -1003,12 +1073,6 @@ public abstract class NotificationListenerService extends Service { throws RemoteException { // no-op in the listener } - - @Override - public void onNotificationRemovedReason(String key, long time, int reason) - throws RemoteException { - // no-op in the listener - } } private void applyUpdateLocked(NotificationRankingUpdate update) { @@ -1413,8 +1477,9 @@ public abstract class NotificationListenerService extends Service { SomeArgs args = (SomeArgs) msg.obj; StatusBarNotification sbn = (StatusBarNotification) args.arg1; RankingMap rankingMap = (RankingMap) args.arg2; + int reason = (int) args.arg3; args.recycle(); - onNotificationRemoved(sbn, rankingMap); + onNotificationRemoved(sbn, rankingMap, reason); } break; case MSG_ON_LISTENER_CONNECTED: { diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index df5d6e73ce81..c7f4d6b5e203 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -17,23 +17,23 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_NONE; -import static android.service.notification.NotificationAssistantService.REASON_APP_CANCEL; -import static android.service.notification.NotificationAssistantService.REASON_APP_CANCEL_ALL; -import static android.service.notification.NotificationAssistantService.REASON_CHANNEL_BANNED; -import static android.service.notification.NotificationAssistantService.REASON_DELEGATE_CANCEL; -import static android.service.notification.NotificationAssistantService.REASON_DELEGATE_CANCEL_ALL; -import static android.service.notification.NotificationAssistantService.REASON_DELEGATE_CLICK; -import static android.service.notification.NotificationAssistantService.REASON_DELEGATE_ERROR; -import static android.service.notification.NotificationAssistantService.REASON_GROUP_SUMMARY_CANCELED; -import static android.service.notification.NotificationAssistantService.REASON_LISTENER_CANCEL; -import static android.service.notification.NotificationAssistantService.REASON_LISTENER_CANCEL_ALL; -import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_BANNED; -import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_CHANGED; -import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_SUSPENDED; -import static android.service.notification.NotificationAssistantService.REASON_PROFILE_TURNED_OFF; -import static android.service.notification.NotificationAssistantService.REASON_SNOOZED; -import static android.service.notification.NotificationAssistantService.REASON_UNAUTOBUNDLED; -import static android.service.notification.NotificationAssistantService.REASON_USER_STOPPED; +import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; +import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL; +import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED; +import static android.service.notification.NotificationListenerService.REASON_DELEGATE_CANCEL; +import static android.service.notification.NotificationListenerService.REASON_DELEGATE_CANCEL_ALL; +import static android.service.notification.NotificationListenerService.REASON_DELEGATE_CLICK; +import static android.service.notification.NotificationListenerService.REASON_DELEGATE_ERROR; +import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED; +import static android.service.notification.NotificationListenerService.REASON_LISTENER_CANCEL; +import static android.service.notification.NotificationListenerService.REASON_LISTENER_CANCEL_ALL; +import static android.service.notification.NotificationListenerService.REASON_PACKAGE_BANNED; +import static android.service.notification.NotificationListenerService.REASON_PACKAGE_CHANGED; +import static android.service.notification.NotificationListenerService.REASON_PACKAGE_SUSPENDED; +import static android.service.notification.NotificationListenerService.REASON_PROFILE_TURNED_OFF; +import static android.service.notification.NotificationListenerService.REASON_SNOOZED; +import static android.service.notification.NotificationListenerService.REASON_UNAUTOBUNDLED; +import static android.service.notification.NotificationListenerService.REASON_USER_STOPPED; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS; @@ -2917,7 +2917,8 @@ public class NotificationManagerService extends SystemService { } else { Slog.e(TAG, "Not posting notification without small icon: " + notification); if (old != null && !old.isCanceled) { - mListeners.notifyRemovedLocked(n); + mListeners.notifyRemovedLocked(n, + NotificationListenerService.REASON_DELEGATE_ERROR); mHandler.post(new Runnable() { @Override public void run() { @@ -3529,7 +3530,7 @@ public class NotificationManagerService extends SystemService { // status bar if (r.getNotification().getSmallIcon() != null) { r.isCanceled = true; - mListeners.notifyRemovedLocked(r.sbn); + mListeners.notifyRemovedLocked(r.sbn, reason); mHandler.post(new Runnable() { @Override public void run() { @@ -4232,7 +4233,7 @@ public class NotificationManagerService extends SystemService { mHandler.post(new Runnable() { @Override public void run() { - notifyRemoved(info, oldSbnLightClone, update); + notifyRemoved(info, oldSbnLightClone, update, REASON_USER_STOPPED); } }); continue; @@ -4251,7 +4252,7 @@ public class NotificationManagerService extends SystemService { /** * asynchronously notify all listeners about a removed notification */ - public void notifyRemovedLocked(StatusBarNotification sbn) { + public void notifyRemovedLocked(StatusBarNotification sbn, int reason) { // make a copy in case changes are made to the underlying Notification object // NOTE: this copy is lightweight: it doesn't include heavyweight parts of the // notification @@ -4264,7 +4265,7 @@ public class NotificationManagerService extends SystemService { mHandler.post(new Runnable() { @Override public void run() { - notifyRemoved(info, sbnLight, update); + notifyRemoved(info, sbnLight, update, reason); } }); } @@ -4328,14 +4329,14 @@ public class NotificationManagerService extends SystemService { } private void notifyRemoved(ManagedServiceInfo info, StatusBarNotification sbn, - NotificationRankingUpdate rankingUpdate) { + NotificationRankingUpdate rankingUpdate, int reason) { if (!info.enabledAndUserMatches(sbn.getUserId())) { return; } final INotificationListener listener = (INotificationListener) info.service; StatusBarNotificationHolder sbnHolder = new StatusBarNotificationHolder(sbn); try { - listener.onNotificationRemoved(sbnHolder, rankingUpdate); + listener.onNotificationRemoved(sbnHolder, rankingUpdate, reason); } catch (RemoteException ex) { Log.e(TAG, "unable to notify listener (removed): " + listener, ex); } |