diff options
5 files changed, 48 insertions, 20 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 845bb3d99025..cbda97e76c9e 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -9851,6 +9851,7 @@ package android.service.notification { method public void onNotificationDirectReplied(@NonNull String); method @Nullable public abstract android.service.notification.Adjustment onNotificationEnqueued(@NonNull android.service.notification.StatusBarNotification); method @Nullable public android.service.notification.Adjustment onNotificationEnqueued(@NonNull android.service.notification.StatusBarNotification, @NonNull android.app.NotificationChannel); + method @Nullable public android.service.notification.Adjustment onNotificationEnqueued(@NonNull android.service.notification.StatusBarNotification, @NonNull android.app.NotificationChannel, @NonNull android.service.notification.NotificationListenerService.RankingMap); method public void onNotificationExpansionChanged(@NonNull String, boolean, boolean); method public abstract void onNotificationSnoozedUntilContext(@NonNull android.service.notification.StatusBarNotification, @NonNull String); method public void onNotificationVisibilityChanged(@NonNull String, boolean); diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl index e0f3018e3d0e..44daeff76997 100644 --- a/core/java/android/service/notification/INotificationListener.aidl +++ b/core/java/android/service/notification/INotificationListener.aidl @@ -46,7 +46,7 @@ oneway interface INotificationListener void onNotificationChannelGroupModification(String pkgName, in UserHandle user, in NotificationChannelGroup group, int modificationType); // assistants only - void onNotificationEnqueuedWithChannel(in IStatusBarNotificationHolder notificationHolder, in NotificationChannel channel); + void onNotificationEnqueuedWithChannel(in IStatusBarNotificationHolder notificationHolder, in NotificationChannel channel, in NotificationRankingUpdate update); void onNotificationSnoozedUntilContext(in IStatusBarNotificationHolder notificationHolder, String snoozeCriterionId); void onNotificationsSeen(in List<String> keys); void onPanelRevealed(int items); diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java index cf2152cc3ad4..1d49a7206023 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -126,7 +126,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS * {@link #onNotificationEnqueued(StatusBarNotification, NotificationChannel)}.</p> * * @param sbn the new notification - * @return an adjustment or null to take no action, within 100ms. + * @return an adjustment or null to take no action, within 200ms. */ abstract public @Nullable Adjustment onNotificationEnqueued(@NonNull StatusBarNotification sbn); @@ -135,7 +135,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS * * @param sbn the new notification * @param channel the channel the notification was posted to - * @return an adjustment or null to take no action, within 100ms. + * @return an adjustment or null to take no action, within 200ms. */ public @Nullable Adjustment onNotificationEnqueued(@NonNull StatusBarNotification sbn, @NonNull NotificationChannel channel) { @@ -143,6 +143,20 @@ public abstract class NotificationAssistantService extends NotificationListenerS } /** + * A notification was posted by an app. Called before post. + * + * @param sbn the new notification + * @param channel the channel the notification was posted to + * @param rankingMap The current ranking map that can be used to retrieve ranking information + * for active notifications. + * @return an adjustment or null to take no action, within 200ms. + */ + public @Nullable Adjustment onNotificationEnqueued(@NonNull StatusBarNotification sbn, + @NonNull NotificationChannel channel, @NonNull RankingMap rankingMap) { + return onNotificationEnqueued(sbn, channel); + } + + /** * Implement this method to learn when notifications are removed, how they were interacted with * before removal, and why they were removed. * <p> @@ -316,7 +330,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS private class NotificationAssistantServiceWrapper extends NotificationListenerWrapper { @Override public void onNotificationEnqueuedWithChannel(IStatusBarNotificationHolder sbnHolder, - NotificationChannel channel) { + NotificationChannel channel, NotificationRankingUpdate update) { StatusBarNotification sbn; try { sbn = sbnHolder.get(); @@ -330,9 +344,11 @@ public abstract class NotificationAssistantService extends NotificationListenerS return; } + applyUpdateLocked(update); SomeArgs args = SomeArgs.obtain(); args.arg1 = sbn; args.arg2 = channel; + args.arg3 = getCurrentRanking(); mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_ENQUEUED, args).sendToTarget(); } @@ -472,8 +488,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS SomeArgs args = (SomeArgs) msg.obj; StatusBarNotification sbn = (StatusBarNotification) args.arg1; NotificationChannel channel = (NotificationChannel) args.arg2; + RankingMap ranking = (RankingMap) args.arg3; args.recycle(); - Adjustment adjustment = onNotificationEnqueued(sbn, channel); + Adjustment adjustment = onNotificationEnqueued(sbn, channel, ranking); setAdjustmentIssuer(adjustment); if (adjustment != null) { if (!isBound()) { diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index c41e599d5cae..64cddc35d2bb 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -1431,7 +1431,8 @@ public abstract class NotificationListenerService extends Service { @Override public void onNotificationEnqueuedWithChannel( - IStatusBarNotificationHolder notificationHolder, NotificationChannel channel) + IStatusBarNotificationHolder notificationHolder, NotificationChannel channel, + NotificationRankingUpdate update) throws RemoteException { // no-op in the listener } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index e32c00fe9a39..8fa3a00f3294 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -9302,21 +9302,30 @@ public class NotificationManagerService extends SystemService { Slog.v(TAG, "onNotificationEnqueuedLocked() called with: r = [" + r + "]"); } final StatusBarNotification sbn = r.getSbn(); - notifyAssistantLocked( - sbn, - r.getNotificationType(), - true /* sameUserOnly */, - (assistant, sbnHolder) -> { - try { - if (debug) { - Slog.v(TAG, - "calling onNotificationEnqueuedWithChannel " + sbnHolder); - } - assistant.onNotificationEnqueuedWithChannel(sbnHolder, r.getChannel()); - } catch (RemoteException ex) { - Slog.e(TAG, "unable to notify assistant (enqueued): " + assistant, ex); + + for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) { + boolean sbnVisible = isVisibleToListener( + sbn, r.getNotificationType(), info) + && info.isSameUser(r.getUserId()); + if (sbnVisible) { + TrimCache trimCache = new TrimCache(sbn); + final INotificationListener assistant = (INotificationListener) info.service; + final StatusBarNotification sbnToPost = trimCache.ForListener(info); + final StatusBarNotificationHolder sbnHolder = + new StatusBarNotificationHolder(sbnToPost); + try { + if (debug) { + Slog.v(TAG, + "calling onNotificationEnqueuedWithChannel " + sbnHolder); } - }); + final NotificationRankingUpdate update = makeRankingUpdateLocked(info); + assistant.onNotificationEnqueuedWithChannel(sbnHolder, r.getChannel(), + update); + } catch (RemoteException ex) { + Slog.e(TAG, "unable to notify assistant (enqueued): " + assistant, ex); + } + } + } } @GuardedBy("mNotificationLock") |