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

Commit eda84a7b authored by Tony Mak's avatar Tony Mak
Browse files

Introduce onNotificationExpansionChanged and onNotificationDirectReplied ..

in NAS

Also, avoid the code duplication around all the notifyAssistant* methods
by pulling out the common piece of code to notifyAssistantLocked.

Bug: 111437455
Bug: 111406942

Test: Observe logs from ExtServices when a notification is expanded
      / direct replied.
Test: atest NotificationManagerServiceTest

Change-Id: I5e135d704763ecf847f82a4ff7ffe439fa56fb5c
parent c61363e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -5022,8 +5022,10 @@ package android.service.notification {
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onNotificationDirectReply(java.lang.String);
    method public android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification);
    method public 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 android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, android.app.NotificationChannel);
    method public void onNotificationExpansionChanged(java.lang.String, boolean, boolean);
    method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap, android.service.notification.NotificationStats, int);
    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, java.lang.String);
    method public abstract void onNotificationSnoozedUntilContext(android.service.notification.StatusBarNotification, java.lang.String);
    method public void onNotificationsSeen(java.util.List<java.lang.String>);
    method public void onNotificationsSeen(java.util.List<java.lang.String>);
+2 −0
Original line number Original line Diff line number Diff line
@@ -1155,8 +1155,10 @@ package android.service.notification {
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotification(android.service.notification.Adjustment);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public final void adjustNotifications(java.util.List<android.service.notification.Adjustment>);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onNotificationDirectReply(java.lang.String);
    method public android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification);
    method public 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 android.service.notification.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, android.app.NotificationChannel);
    method public void onNotificationExpansionChanged(java.lang.String, boolean, boolean);
    method public abstract void onNotificationSnoozedUntilContext(android.service.notification.StatusBarNotification, java.lang.String);
    method public abstract void onNotificationSnoozedUntilContext(android.service.notification.StatusBarNotification, java.lang.String);
    method public void onNotificationsSeen(java.util.List<java.lang.String>);
    method public void onNotificationsSeen(java.util.List<java.lang.String>);
    method public final void unsnoozeNotification(java.lang.String);
    method public final void unsnoozeNotification(java.lang.String);
+2 −0
Original line number Original line Diff line number Diff line
@@ -47,4 +47,6 @@ oneway interface INotificationListener
    void onNotificationEnqueuedWithChannel(in IStatusBarNotificationHolder notificationHolder, in NotificationChannel channel);
    void onNotificationEnqueuedWithChannel(in IStatusBarNotificationHolder notificationHolder, in NotificationChannel channel);
    void onNotificationSnoozedUntilContext(in IStatusBarNotificationHolder notificationHolder, String snoozeCriterionId);
    void onNotificationSnoozedUntilContext(in IStatusBarNotificationHolder notificationHolder, String snoozeCriterionId);
    void onNotificationsSeen(in List<String> keys);
    void onNotificationsSeen(in List<String> keys);
    void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded);
    void onNotificationDirectReply(String key);
}
}
+52 −0
Original line number Original line Diff line number Diff line
@@ -159,6 +159,21 @@ public abstract class NotificationAssistantService extends NotificationListenerS


    }
    }


    /**
     * Implement this to know when a notification is expanded / collapsed.
     * @param key the notification key
     * @param isUserAction whether the expanded change is caused by user action.
     * @param isExpanded whether the notification is expanded.
     */
    public void onNotificationExpansionChanged(
            String key, boolean isUserAction, boolean isExpanded) {}

    /**
     * Implement this to know when a direct reply is sent from a notification.
     * @param key the notification key
     */
    public void onNotificationDirectReply(String key) {}

    /**
    /**
     * Updates a notification.  N.B. this won’t cause
     * Updates a notification.  N.B. this won’t cause
     * an existing notification to alert, but might allow a future update to
     * an existing notification to alert, but might allow a future update to
@@ -255,12 +270,33 @@ public abstract class NotificationAssistantService extends NotificationListenerS
            mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATIONS_SEEN,
            mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATIONS_SEEN,
                    args).sendToTarget();
                    args).sendToTarget();
        }
        }

        @Override
        public void onNotificationExpansionChanged(String key, boolean isUserAction,
                boolean isExpanded) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = key;
            args.argi1 = isUserAction ? 1 : 0;
            args.argi2 = isExpanded ? 1 : 0;
            mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_EXPANSION_CHANGED, args)
                    .sendToTarget();
        }

        @Override
        public void onNotificationDirectReply(String key) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = key;
            mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_DIRECT_REPLY_SENT, args)
                    .sendToTarget();
        }
    }
    }


    private final class MyHandler extends Handler {
    private final class MyHandler extends Handler {
        public static final int MSG_ON_NOTIFICATION_ENQUEUED = 1;
        public static final int MSG_ON_NOTIFICATION_ENQUEUED = 1;
        public static final int MSG_ON_NOTIFICATION_SNOOZED = 2;
        public static final int MSG_ON_NOTIFICATION_SNOOZED = 2;
        public static final int MSG_ON_NOTIFICATIONS_SEEN = 3;
        public static final int MSG_ON_NOTIFICATIONS_SEEN = 3;
        public static final int MSG_ON_NOTIFICATION_EXPANSION_CHANGED = 4;
        public static final int MSG_ON_NOTIFICATION_DIRECT_REPLY_SENT = 5;


        public MyHandler(Looper looper) {
        public MyHandler(Looper looper) {
            super(looper, null, false);
            super(looper, null, false);
@@ -305,6 +341,22 @@ public abstract class NotificationAssistantService extends NotificationListenerS
                    onNotificationsSeen(keys);
                    onNotificationsSeen(keys);
                    break;
                    break;
                }
                }
                case MSG_ON_NOTIFICATION_EXPANSION_CHANGED: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    String key = (String) args.arg1;
                    boolean isUserAction = args.argi1 == 1;
                    boolean isExpanded = args.argi2 == 1;
                    args.recycle();
                    onNotificationExpansionChanged(key, isUserAction, isExpanded);
                    break;
                }
                case MSG_ON_NOTIFICATION_DIRECT_REPLY_SENT: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    String key = (String) args.arg1;
                    args.recycle();
                    onNotificationDirectReply(key);
                    break;
                }
            }
            }
        }
        }
    }
    }
+11 −0
Original line number Original line Diff line number Diff line
@@ -1365,6 +1365,17 @@ public abstract class NotificationListenerService extends Service {
            // no-op in the listener
            // no-op in the listener
        }
        }


        @Override
        public void onNotificationExpansionChanged(
                String key, boolean isUserAction, boolean isExpanded) {
            // no-op in the listener
        }

        @Override
        public void onNotificationDirectReply(String key) {
            // no-op in the listener
        }

        @Override
        @Override
        public void onNotificationChannelModification(String pkgName, UserHandle user,
        public void onNotificationChannelModification(String pkgName, UserHandle user,
                NotificationChannel channel,
                NotificationChannel channel,
Loading