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

Commit 72f1cbb3 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add support for snoozing notifications

To a notification listener, snoozing will appear as a cancel
(with reason snoozed) followed by a post (when the snooze period
ends).

Apps can repost a snoozed notification, but the updates will not be shown
to the user until the snooze period ends.

Snoozing is canceled if the posting app or a notification listener
cancels the notification.

Any notification listener can snooze a notification. Technically apps
can snooze their own notifications also, though that's not public.

In this iteration snoozed notifications will be lost on device reboot.

Test: included. Also, various post, snooze, update, cancel tests with
a listener.

Bug: 30997603
Change-Id: I568a6448196f0992a17d20a4dac296321ec5092b
parent 808913e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34853,6 +34853,7 @@ package android.service.notification {
    method public static void requestRebind(android.content.ComponentName);
    method public final void requestUnbind();
    method public final void setNotificationsShown(java.lang.String[]);
    method public final void snoozeNotification(java.lang.String, long);
    field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
    field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
    field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
+2 −0
Original line number Diff line number Diff line
@@ -37633,6 +37633,7 @@ package android.service.notification {
    method public final void requestUnbind();
    method public final void setNotificationsShown(java.lang.String[]);
    method public final void setOnNotificationPostedTrim(int);
    method public final void snoozeNotification(java.lang.String, long);
    method public void unregisterAsSystemService() throws android.os.RemoteException;
    field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
    field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
@@ -37694,6 +37695,7 @@ package android.service.notification {
    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.NotificationRankerService";
+1 −0
Original line number Diff line number Diff line
@@ -34934,6 +34934,7 @@ package android.service.notification {
    method public static void requestRebind(android.content.ComponentName);
    method public final void requestUnbind();
    method public final void setNotificationsShown(java.lang.String[]);
    method public final void snoozeNotification(java.lang.String, long);
    field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
    field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
    field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
+2 −0
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ interface INotificationManager
    void cancelNotificationFromListener(in INotificationListener token, String pkg, String tag, int id);
    void cancelNotificationsFromListener(in INotificationListener token, in String[] keys);

    void snoozeNotificationFromListener(in INotificationListener token, String key, long until);

    void requestBindListener(in ComponentName component);
    void requestUnbindListener(in INotificationListener token);
    void requestBindProvider(in ComponentName component);
+22 −0
Original line number Diff line number Diff line
@@ -449,6 +449,28 @@ public abstract class NotificationListenerService extends Service {
        }
    }

    /**
     * Inform the notification manager about snoozing a specific notification.
     * <p>
     * Use this if your listener has a user interface that allows the user to snooze a notification
     * until a given time.  It should be called after the user snoozes a single notification using
     * your UI; upon being informed, the notification manager will actually remove the notification
     * and you will get an {@link #onNotificationRemoved(StatusBarNotification)} callback. When the
     * snoozing period expires, you will get a
     * {@link #onNotificationPosted(StatusBarNotification, RankingMap)} callback for the
     * notification.
     * @param key The key of the notification to snooze
     * @param snoozeUntil A time in the future, in milliseconds.
     */
    public final void snoozeNotification(String key, long snoozeUntil) {
        if (!isBound()) return;
        try {
            getNotificationInterface().snoozeNotificationFromListener(mWrapper, key, snoozeUntil);
        } catch (android.os.RemoteException ex) {
            Log.v(TAG, "Unable to contact notification manager", ex);
        }
    }

    /**
     * Inform the notification manager that these notifications have been viewed by the
     * user. This should only be called when there is sufficient confidence that the user is
Loading