Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7236b388 authored by Chloris Kuo's avatar Chloris Kuo
Browse files

NAS API Change

Add onNotificationEnqueued(sbn, channel, rankingMap)

Bug: 177032312
Test: CtsLegacyNotification29TestCases
Change-Id: I116f74317028154ef451a0f1e02ac6a83e6b1012
parent 3164ff66
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9751,6 +9751,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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
+21 −4
Original line number Diff line number Diff line
@@ -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,13 +135,27 @@ 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) {
        return onNotificationEnqueued(sbn);
    }

    /**
     * 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.
@@ -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()) {
+2 −1
Original line number Diff line number Diff line
@@ -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
        }
+23 −14
Original line number Diff line number Diff line
@@ -9333,21 +9333,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) -> {

            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);
                        }
                            assistant.onNotificationEnqueuedWithChannel(sbnHolder, r.getChannel());
                        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")