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

Commit ad6a98eb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow delegates to cancel notifs they posted"

parents 0582f167 e4a47ddc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -5808,8 +5808,9 @@ package android.app {
    method public boolean areNotificationsPaused();
    method public boolean canNotifyAsPackage(@NonNull String);
    method public void cancel(int);
    method public void cancel(String, int);
    method public void cancel(@Nullable String, int);
    method public void cancelAll();
    method public void cancelAsPackage(@NonNull String, @Nullable String, int);
    method public void createNotificationChannel(@NonNull android.app.NotificationChannel);
    method public void createNotificationChannelGroup(@NonNull android.app.NotificationChannelGroup);
    method public void createNotificationChannelGroups(@NonNull java.util.List<android.app.NotificationChannelGroup>);
@@ -5831,7 +5832,7 @@ package android.app {
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
    method public void notify(String, int, android.app.Notification);
    method public void notifyAsPackage(@NonNull String, @NonNull String, int, @NonNull android.app.Notification);
    method public void notifyAsPackage(@NonNull String, @Nullable String, int, @NonNull android.app.Notification);
    method public boolean removeAutomaticZenRule(String);
    method public void setAutomaticZenRuleState(@NonNull String, @NonNull android.service.notification.Condition);
    method public final void setInterruptionFilter(int);
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ interface INotificationManager
    void enqueueNotificationWithTag(String pkg, String opPkg, String tag, int id,
            in Notification notification, int userId);
    @UnsupportedAppUsage
    void cancelNotificationWithTag(String pkg, String tag, int id, int userId);
    void cancelNotificationWithTag(String pkg, String opPkg, String tag, int id, int userId);

    void setShowBadge(String pkg, int uid, boolean showBadge);
    boolean canShowBadge(String pkg, int uid);
+47 −9
Original line number Diff line number Diff line
@@ -466,7 +466,7 @@ public class NotificationManager {
     * @param notification A {@link Notification} object describing what to
     *        show the user. Must not be null.
     */
    public void notifyAsPackage(@NonNull String targetPackage, @NonNull String tag, int id,
    public void notifyAsPackage(@NonNull String targetPackage, @Nullable String tag, int id,
            @NonNull Notification notification) {
        INotificationManager service = getService();
        String sender = mContext.getPackageName();
@@ -532,9 +532,13 @@ public class NotificationManager {
    }

    /**
     * Cancel a previously shown notification.  If it's transient, the view
     * will be hidden.  If it's persistent, it will be removed from the status
     * bar.
     * Cancels a previously posted notification.
     *
     *  <p>If the notification does not currently represent a
     *  {@link Service#startForeground(int, Notification) foreground service}, it will be
     *  removed from the UI and live
     *  {@link android.service.notification.NotificationListenerService notification listeners}
     *  will be informed so they can remove the notification from their UIs.</p>
     */
    public void cancel(int id)
    {
@@ -542,15 +546,48 @@ public class NotificationManager {
    }

    /**
     * Cancel a previously shown notification.  If it's transient, the view
     * will be hidden.  If it's persistent, it will be removed from the status
     * bar.
     * Cancels a previously posted notification.
     *
     *  <p>If the notification does not currently represent a
     *  {@link Service#startForeground(int, Notification) foreground service}, it will be
     *  removed from the UI and live
     *  {@link android.service.notification.NotificationListenerService notification listeners}
     *  will be informed so they can remove the notification from their UIs.</p>
     */
    public void cancel(String tag, int id)
    public void cancel(@Nullable String tag, int id)
    {
        cancelAsUser(tag, id, mContext.getUser());
    }

    /**
     * Cancels a previously posted notification.
     *
     * <p>If the notification does not currently represent a
     * {@link Service#startForeground(int, Notification) foreground service}, it will be
     * removed from the UI and live
     * {@link android.service.notification.NotificationListenerService notification listeners}
     * will be informed so they can remove the notification from their UIs.</p>
     *
     * <p>This method may be used by {@link #getNotificationDelegate() a notification delegate} to
     * cancel notifications that they have posted via {@link #notifyAsPackage(String, String, int,
     * Notification)}.</p>
     *
     * @param targetPackage The package to cancel the notification as. If this package is not your
     *                      package, you can only cancel notifications you posted with
     *                      {@link #notifyAsPackage(String, String, int, Notification).
     * @param tag A string identifier for this notification.  May be {@code null}.
     * @param id An identifier for this notification.
     */
    public void cancelAsPackage(@NonNull String targetPackage, @Nullable String tag, int id) {
        INotificationManager service = getService();
        try {
            service.cancelNotificationWithTag(targetPackage, mContext.getOpPackageName(),
                    tag, id, mContext.getUser().getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
@@ -561,7 +598,8 @@ public class NotificationManager {
        String pkg = mContext.getPackageName();
        if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")");
        try {
            service.cancelNotificationWithTag(pkg, tag, id, user.getIdentifier());
            service.cancelNotificationWithTag(
                    pkg, mContext.getOpPackageName(), tag, id, user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+2 −1
Original line number Diff line number Diff line
@@ -5310,7 +5310,8 @@ public class AccountManagerService
        long identityToken = clearCallingIdentity();
        try {
            INotificationManager service = mInjector.getNotificationManager();
            service.cancelNotificationWithTag(packageName, id.mTag, id.mId, user.getIdentifier());
            service.cancelNotificationWithTag(
                    packageName, "android", id.mTag, id.mId, user.getIdentifier());
        } catch (RemoteException e) {
            /* ignore - local call */
        } finally {
+1 −1
Original line number Diff line number Diff line
@@ -918,7 +918,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
                    return;
                }
                try {
                    inm.cancelNotificationWithTag(localPackageName, null,
                    inm.cancelNotificationWithTag(localPackageName, "android", null,
                            localForegroundId, userId);
                } catch (RuntimeException e) {
                    Slog.w(TAG, "Error canceling notification for service", e);
Loading