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

Commit 509e5548 authored by Alex Mang's avatar Alex Mang
Browse files

Adding additional listeners (onNotificationVisibilityChanged,

onPanelHidden, onPanelRevealed) to NotificationAssistantService.

Bug: 147149509
Test: atest NotificationManagerServiceTest#testOnPanelRevealedAndHidden,testStats_updatedOnVisibilityChanged
Change-Id: If17070677d01b00d7c3cdda9a0e9d3e8f47f9062
parent 91cc8bc6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8312,7 +8312,10 @@ package android.service.notification {
    method @Nullable public android.service.notification.Adjustment onNotificationEnqueued(@NonNull android.service.notification.StatusBarNotification, @NonNull android.app.NotificationChannel);
    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);
    method public void onNotificationsSeen(@NonNull java.util.List<java.lang.String>);
    method public void onPanelHidden();
    method public void onPanelRevealed(int);
    method public void onSuggestedReplySent(@NonNull String, @NonNull CharSequence, int);
    method public final void unsnoozeNotification(@NonNull String);
    field public static final String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
+5 −0
Original line number Diff line number Diff line
@@ -421,6 +421,8 @@ package android.app {
  }

  public class StatusBarManager {
    method public void collapsePanels();
    method public void expandNotificationsPanel();
    method @NonNull @RequiresPermission(android.Manifest.permission.STATUS_BAR) public android.app.StatusBarManager.DisableInfo getDisableInfo();
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void setDisabledForSetup(boolean);
  }
@@ -2904,7 +2906,10 @@ package android.service.notification {
    method @Nullable public android.service.notification.Adjustment onNotificationEnqueued(@NonNull android.service.notification.StatusBarNotification, @NonNull android.app.NotificationChannel);
    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);
    method public void onNotificationsSeen(@NonNull java.util.List<java.lang.String>);
    method public void onPanelHidden();
    method public void onPanelRevealed(int);
    method public void onSuggestedReplySent(@NonNull String, @NonNull CharSequence, int);
    method public final void unsnoozeNotification(@NonNull String);
    field public static final String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
+2 −0
Original line number Diff line number Diff line
@@ -262,6 +262,7 @@ public class StatusBarManager {
     * @hide
     */
    @UnsupportedAppUsage
    @TestApi
    public void expandNotificationsPanel() {
        try {
            final IStatusBarService svc = getService();
@@ -279,6 +280,7 @@ public class StatusBarManager {
     * @hide
     */
    @UnsupportedAppUsage
    @TestApi
    public void collapsePanels() {
        try {
            final IStatusBarService svc = getService();
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ oneway interface INotificationListener
    void onNotificationEnqueuedWithChannel(in IStatusBarNotificationHolder notificationHolder, in NotificationChannel channel);
    void onNotificationSnoozedUntilContext(in IStatusBarNotificationHolder notificationHolder, String snoozeCriterionId);
    void onNotificationsSeen(in List<String> keys);
    void onPanelRevealed(int items);
    void onPanelHidden();
    void onNotificationVisibilityChanged(String key, boolean isVisible);
    void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded);
    void onNotificationDirectReply(String key);
    void onSuggestedReplySent(String key, in CharSequence reply, int source);
+72 −0
Original line number Diff line number Diff line
@@ -181,6 +181,32 @@ public abstract class NotificationAssistantService extends NotificationListenerS

    }

    /**
     * Implement this to know when the notification panel is revealed
     *
     * @param items Number of items on the panel at time of opening
     */
    public void onPanelRevealed(int items) {

    }

    /**
     * Implement this to know when the notification panel is hidden
     */
    public void onPanelHidden() {

    }

    /**
     * Implement this to know when a notification becomes visible or hidden from the user.
     *
     * @param key the notification key
     * @param isVisible whether the notification is visible.
     */
    public void onNotificationVisibilityChanged(@NonNull String key, boolean isVisible) {

    }

    /**
     * Implement this to know when a notification change (expanded / collapsed) is visible to user.
     *
@@ -336,6 +362,30 @@ public abstract class NotificationAssistantService extends NotificationListenerS
                    args).sendToTarget();
        }

        @Override
        public void onPanelRevealed(int items) {
            SomeArgs args = SomeArgs.obtain();
            args.argi1 = items;
            mHandler.obtainMessage(MyHandler.MSG_ON_PANEL_REVEALED,
                    args).sendToTarget();
        }

        @Override
        public void onPanelHidden() {
            SomeArgs args = SomeArgs.obtain();
            mHandler.obtainMessage(MyHandler.MSG_ON_PANEL_HIDDEN,
                    args).sendToTarget();
        }

        @Override
        public void onNotificationVisibilityChanged(String key, boolean isVisible) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = key;
            args.argi1 = isVisible ? 1 : 0;
            mHandler.obtainMessage(MyHandler.MSG_ON_NOTIFICATION_VISIBILITY_CHANGED,
                    args).sendToTarget();
        }

        @Override
        public void onNotificationExpansionChanged(String key, boolean isUserAction,
                boolean isExpanded) {
@@ -394,6 +444,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS
        public static final int MSG_ON_SUGGESTED_REPLY_SENT = 6;
        public static final int MSG_ON_ACTION_INVOKED = 7;
        public static final int MSG_ON_ALLOWED_ADJUSTMENTS_CHANGED = 8;
        public static final int MSG_ON_PANEL_REVEALED = 9;
        public static final int MSG_ON_PANEL_HIDDEN = 10;
        public static final int MSG_ON_NOTIFICATION_VISIBILITY_CHANGED = 11;

        public MyHandler(Looper looper) {
            super(looper, null, false);
@@ -480,6 +533,25 @@ public abstract class NotificationAssistantService extends NotificationListenerS
                    onAllowedAdjustmentsChanged();
                    break;
                }
                case MSG_ON_PANEL_REVEALED: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    int items = args.argi1;
                    args.recycle();
                    onPanelRevealed(items);
                    break;
                }
                case MSG_ON_PANEL_HIDDEN: {
                    onPanelHidden();
                    break;
                }
                case MSG_ON_NOTIFICATION_VISIBILITY_CHANGED: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    String key = (String) args.arg1;
                    boolean isVisible = args.argi1 == 1;
                    args.recycle();
                    onNotificationVisibilityChanged(key, isVisible);
                    break;
                }
            }
        }
    }
Loading