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

Commit 6ecaff15 authored by Fred Quintana's avatar Fred Quintana
Browse files

add a optional String to the key of notifications to allow users

to scope them
parent ed7f0955
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -23166,6 +23166,21 @@
<parameter name="id" type="int">
</parameter>
</method>
<method name="cancel"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="id" type="int">
</parameter>
</method>
<method name="cancelAll"
 return="void"
 abstract="false"
@@ -23192,6 +23207,23 @@
<parameter name="notification" type="android.app.Notification">
</parameter>
</method>
<method name="notify"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="id" type="int">
</parameter>
<parameter name="notification" type="android.app.Notification">
</parameter>
</method>
</class>
<class name="PendingIntent"
 extends="java.lang.Object"
+4 −0
Original line number Diff line number Diff line
@@ -24,11 +24,15 @@ import android.content.Intent;
/** {@hide} */
interface INotificationManager
{
    /** @deprecated use {@link #enqueueNotificationWithTag} instead */
    void enqueueNotification(String pkg, int id, in Notification notification, inout int[] idReceived);
    /** @deprecated use {@link #cancelNotificationWithTag} instead */
    void cancelNotification(String pkg, int id);
    void cancelAllNotifications(String pkg);

    void enqueueToast(String pkg, ITransientNotification callback, int duration);
    void cancelToast(String pkg, ITransientNotification callback);
    void enqueueNotificationWithTag(String pkg, String tag, int id, in Notification notification, inout int[] idReceived);
    void cancelNotificationWithTag(String pkg, String tag, int id);
}
+27 −2
Original line number Diff line number Diff line
@@ -86,13 +86,28 @@ public class NotificationManager
     *        notify the user, other than the view you're providing. Must not be null.
     */
    public void notify(int id, Notification notification)
    {
        notify(null, id, notification);
    }

    /**
     * Persistent notification on the status bar,
     *
     * @param tag An string identifier for this notification unique within your
     *        application.
     * @param notification A {@link Notification} object describing how to
     *        notify the user, other than the view you're providing. Must not be null.
     * @return the id of the notification that is associated with the string identifier that
     * can be used to cancel the notification
     */
    public void notify(String tag, int id, Notification notification)
    {
        int[] idOut = new int[1];
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
        try {
            service.enqueueNotification(pkg, id, notification, idOut);
            service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut);
            if (id != idOut[0]) {
                Log.w(TAG, "notify: id corrupted: sent " + id + ", got back " + idOut[0]);
            }
@@ -106,12 +121,22 @@ public class NotificationManager
     * bar.
     */
    public void cancel(int id)
    {
        cancel(null, id);
    }

    /**
     * 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.
     */
    public void cancel(String tag, int id)
    {
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")");
        try {
            service.cancelNotification(pkg, id);
            service.cancelNotificationWithTag(pkg, tag, id);
        } catch (RemoteException e) {
        }
    }
+51 −31
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentQueryMap;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -103,7 +102,8 @@ class NotificationManagerService extends INotificationManager.Stub
    private boolean mAdbNotificationShown = false;
    private Notification mAdbNotification;
    
    private ArrayList<NotificationRecord> mNotificationList;
    private final ArrayList<NotificationRecord> mNotificationList =
            new ArrayList<NotificationRecord>();

    private ArrayList<ToastRecord> mToastQueue;

@@ -152,16 +152,18 @@ class NotificationManagerService extends INotificationManager.Stub

    private static final class NotificationRecord
    {
        String pkg;
        int id;
        final String pkg;
        final String tag;
        final int id;
        ITransientNotification callback;
        int duration;
        Notification notification;
        final Notification notification;
        IBinder statusBarKey;

        NotificationRecord(String pkg, int id, Notification notification)
        NotificationRecord(String pkg, String tag, int id, Notification notification)
        {
            this.pkg = pkg;
            this.tag = tag;
            this.id = id;
            this.notification = notification;
        }
@@ -189,7 +191,8 @@ class NotificationManagerService extends INotificationManager.Stub
            return "NotificationRecord{"
                + Integer.toHexString(System.identityHashCode(this))
                + " pkg=" + pkg
                + " id=" + Integer.toHexString(id) + "}";
                + " id=" + Integer.toHexString(id)
                + " tag=" + tag + "}";
        }
    }

@@ -258,8 +261,8 @@ class NotificationManagerService extends INotificationManager.Stub
            cancelAll();
        }

        public void onNotificationClick(String pkg, int id) {
            cancelNotification(pkg, id, Notification.FLAG_AUTO_CANCEL,
        public void onNotificationClick(String pkg, String tag, int id) {
            cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
                    Notification.FLAG_FOREGROUND_SERVICE);
        }

@@ -369,7 +372,6 @@ class NotificationManagerService extends INotificationManager.Stub
        mSound = new AsyncPlayer(TAG);
        mSound.setUsesWakeLock(context);
        mToastQueue = new ArrayList<ToastRecord>();
        mNotificationList = new ArrayList<NotificationRecord>();
        mHandler = new WorkerHandler();
        mStatusBarService = statusBar;
        statusBar.setNotificationCallbacks(mNotificationCallbacks);
@@ -582,6 +584,12 @@ class NotificationManagerService extends INotificationManager.Stub
    // Notifications
    // ============================================================================
    public void enqueueNotification(String pkg, int id, Notification notification, int[] idOut)
    {
        enqueueNotificationWithTag(pkg, null /* tag */, id, notification, idOut);
    }

    public void enqueueNotificationWithTag(String pkg, String tag, int id,
            Notification notification, int[] idOut)
    {
        checkIncomingCall(pkg);
        
@@ -608,10 +616,10 @@ class NotificationManagerService extends INotificationManager.Stub
        }

        synchronized (mNotificationList) {
            NotificationRecord r = new NotificationRecord(pkg, id, notification);
            NotificationRecord r = new NotificationRecord(pkg, tag, id, notification);
            NotificationRecord old = null;

            int index = indexOfNotificationLocked(pkg, id);
            int index = indexOfNotificationLocked(pkg, tag, id);
            if (index < 0) {
                mNotificationList.add(r);
            } else {
@@ -645,8 +653,9 @@ class NotificationManagerService extends INotificationManager.Stub
                }

                NotificationData n = new NotificationData();
                    n.id = id;
                n.pkg = pkg;
                n.tag = tag;
                n.id = id;
                n.when = notification.when;
                n.tickerText = truncatedTicker;
                n.ongoingEvent = (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0;
@@ -828,16 +837,14 @@ class NotificationManagerService extends INotificationManager.Stub
     * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
     * and none of the {@code mustNotHaveFlags}. 
     */
    private void cancelNotification(String pkg, int id, int mustHaveFlags,
    private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
            int mustNotHaveFlags) {
        EventLog.writeEvent(EVENT_LOG_CANCEL, pkg, id, mustHaveFlags);

        synchronized (mNotificationList) {
            NotificationRecord r = null;

            int index = indexOfNotificationLocked(pkg, id);
            int index = indexOfNotificationLocked(pkg, tag, id);
            if (index >= 0) {
                r = mNotificationList.get(index);
                NotificationRecord r = mNotificationList.get(index);
                
                if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) {
                    return;
@@ -888,9 +895,13 @@ class NotificationManagerService extends INotificationManager.Stub

    
    public void cancelNotification(String pkg, int id) {
        cancelNotificationWithTag(pkg, null /* tag */, id);
    }

    public void cancelNotificationWithTag(String pkg, String tag, int id) {
        checkIncomingCall(pkg);
        // Don't allow client applications to cancel foreground service notis.
        cancelNotification(pkg, id, 0,
        cancelNotification(pkg, tag, id, 0,
                Binder.getCallingUid() == Process.SYSTEM_UID
                ? 0 : Notification.FLAG_FOREGROUND_SERVICE);
    }
@@ -999,12 +1010,21 @@ class NotificationManagerService extends INotificationManager.Stub
    }

    // lock on mNotificationList
    private int indexOfNotificationLocked(String pkg, int id)
    private int indexOfNotificationLocked(String pkg, String tag, int id)
    {
        ArrayList<NotificationRecord> list = mNotificationList;
        final int len = list.size();
        for (int i=0; i<len; i++) {
            NotificationRecord r = list.get(i);
            if (tag == null) {
                if (r.tag != null) {
                    continue;
                }
            } else {
                if (!tag.equals(r.tag)) {
                    continue;
                }
            }
            if (r.id == id && r.pkg.equals(pkg)) {
                return i;
            }
+1 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.widget.RemoteViews;

public class NotificationData {
    public String pkg;
    public String tag;
    public int id;
    public CharSequence tickerText;

@@ -17,9 +18,6 @@ public class NotificationData {

    public PendingIntent deleteIntent;

    public NotificationData() {
    }

    public String toString() {
        return "NotificationData(package=" + pkg + " tickerText=" + tickerText
                + " ongoingEvent=" + ongoingEvent + " contentIntent=" + contentIntent
Loading