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

Commit 069438d3 authored by Dan Sandler's avatar Dan Sandler Committed by Android Git Automerger
Browse files

am 54c4c19b: Merge "NotificationListenerService: API updates" into lmp-preview-dev

* commit '54c4c19bc95e839cfce3d10f0e842ed5588391eb':
  NotificationListenerService: API updates
parents 439688cf 59c11b5d
Loading
Loading
Loading
Loading
+15 −8
Original line number Original line Diff line number Diff line
@@ -26015,21 +26015,28 @@ package android.service.notification {
    method public final void cancelNotification(java.lang.String);
    method public final void cancelNotification(java.lang.String);
    method public final void cancelNotifications(java.lang.String[]);
    method public final void cancelNotifications(java.lang.String[]);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.service.notification.NotificationListenerService.Ranking getCurrentRanking();
    method public android.service.notification.NotificationListenerService.RankingMap getCurrentRanking();
    method public android.os.IBinder onBind(android.content.Intent);
    method public android.os.IBinder onBind(android.content.Intent);
    method public void onListenerConnected();
    method public void onListenerConnected();
    method public abstract void onNotificationPosted(android.service.notification.StatusBarNotification);
    method public void onNotificationPosted(android.service.notification.StatusBarNotification);
    method public void onNotificationRankingUpdate();
    method public void onNotificationPosted(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap);
    method public abstract void onNotificationRemoved(android.service.notification.StatusBarNotification);
    method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap);
    method public void onNotificationRemoved(android.service.notification.StatusBarNotification);
    method public void onNotificationRemoved(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
  }
  }
  public static class NotificationListenerService.Ranking implements android.os.Parcelable {
  public static class NotificationListenerService.Ranking {
    method public java.lang.String getKey();
    method public int getRank();
    method public boolean isAmbient();
    method public boolean isInterceptedByDoNotDisturb();
  }
  public static class NotificationListenerService.RankingMap implements android.os.Parcelable {
    method public int describeContents();
    method public int describeContents();
    method public java.lang.String[] getOrderedKeys();
    method public java.lang.String[] getOrderedKeys();
    method public int getRank(java.lang.String);
    method public android.service.notification.NotificationListenerService.Ranking getRanking(java.lang.String);
    method public boolean isAmbient(java.lang.String);
    method public boolean isInterceptedByDoNotDisturb(java.lang.String);
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  }
+154 −66
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;


import java.util.List;
import java.util.List;
@@ -54,7 +55,7 @@ public abstract class NotificationListenerService extends Service {
            + "[" + getClass().getSimpleName() + "]";
            + "[" + getClass().getSimpleName() + "]";


    private INotificationListenerWrapper mWrapper = null;
    private INotificationListenerWrapper mWrapper = null;
    private Ranking mRanking;
    private RankingMap mRankingMap;


    private INotificationManager mNoMan;
    private INotificationManager mNoMan;


@@ -75,7 +76,43 @@ public abstract class NotificationListenerService extends Service {
     *            object as well as its identifying information (tag and id) and source
     *            object as well as its identifying information (tag and id) and source
     *            (package name).
     *            (package name).
     */
     */
    public abstract void onNotificationPosted(StatusBarNotification sbn);
    public void onNotificationPosted(StatusBarNotification sbn) {
        // optional
    }

    /**
     * Implement this method to learn about new notifications as they are posted by apps.
     *
     * @param sbn A data structure encapsulating the original {@link android.app.Notification}
     *            object as well as its identifying information (tag and id) and source
     *            (package name).
     * @param rankingMap The current ranking map that can be used to retrieve ranking information
     *                   for active notifications, including the newly posted one.
     */
    public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
        onNotificationPosted(sbn);
    }

    /**
     * Implement this method to learn when notifications are removed.
     * <P>
     * This might occur because the user has dismissed the notification using system UI (or another
     * notification listener) or because the app has withdrawn the notification.
     * <P>
     * NOTE: The {@link StatusBarNotification} object you receive will be "light"; that is, the
     * result from {@link StatusBarNotification#getNotification} may be missing some heavyweight
     * fields such as {@link android.app.Notification#contentView} and
     * {@link android.app.Notification#largeIcon}. However, all other fields on
     * {@link StatusBarNotification}, sufficient to match this call with a prior call to
     * {@link #onNotificationPosted(StatusBarNotification)}, will be intact.
     *
     * @param sbn A data structure encapsulating at least the original information (tag and id)
     *            and source (package name) used to post the {@link android.app.Notification} that
     *            was just removed.
     */
    public void onNotificationRemoved(StatusBarNotification sbn) {
        // optional
    }


    /**
    /**
     * Implement this method to learn when notifications are removed.
     * Implement this method to learn when notifications are removed.
@@ -93,8 +130,13 @@ public abstract class NotificationListenerService extends Service {
     * @param sbn A data structure encapsulating at least the original information (tag and id)
     * @param sbn A data structure encapsulating at least the original information (tag and id)
     *            and source (package name) used to post the {@link android.app.Notification} that
     *            and source (package name) used to post the {@link android.app.Notification} that
     *            was just removed.
     *            was just removed.
     * @param rankingMap The current ranking map that can be used to retrieve ranking information
     *                   for active notifications.
     *
     */
     */
    public abstract void onNotificationRemoved(StatusBarNotification sbn);
    public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
        onNotificationRemoved(sbn);
    }


    /**
    /**
     * Implement this method to learn about when the listener is enabled and connected to
     * Implement this method to learn about when the listener is enabled and connected to
@@ -107,10 +149,11 @@ public abstract class NotificationListenerService extends Service {


    /**
    /**
     * Implement this method to be notified when the notification ranking changes.
     * Implement this method to be notified when the notification ranking changes.
     * <P>
     *
     * Call {@link #getCurrentRanking()} to retrieve the new ranking.
     * @param rankingMap The current ranking map that can be used to retrieve ranking information
     *                   for active notifications.
     */
     */
    public void onNotificationRankingUpdate() {
    public void onNotificationRankingUpdate(RankingMap rankingMap) {
        // optional
        // optional
    }
    }


@@ -241,16 +284,19 @@ public abstract class NotificationListenerService extends Service {
     *
     *
     * <p>
     * <p>
     * The returned object represents the current ranking snapshot and only
     * The returned object represents the current ranking snapshot and only
     * applies for currently active notifications. Hence you must retrieve a
     * applies for currently active notifications.
     * new Ranking after each notification event such as
     * <p>
     * {@link #onNotificationPosted(StatusBarNotification)},
     * Generally you should use the RankingMap that is passed with events such
     * {@link #onNotificationRemoved(StatusBarNotification)}, etc.
     * as {@link #onNotificationPosted(StatusBarNotification, RankingMap)},
     * {@link #onNotificationRemoved(StatusBarNotification, RankingMap)}, and
     * so on. This method should only be used when needing access outside of
     * such events, for example to retrieve the RankingMap right after
     * initialization.
     *
     *
     * @return A {@link NotificationListenerService.Ranking} object providing
     * @return A {@link RankingMap} object providing access to ranking information
     *     access to ranking information
     */
     */
    public Ranking getCurrentRanking() {
    public RankingMap getCurrentRanking() {
        return mRanking;
        return mRankingMap;
    }
    }


    @Override
    @Override
@@ -313,7 +359,7 @@ public abstract class NotificationListenerService extends Service {
            synchronized (mWrapper) {
            synchronized (mWrapper) {
                applyUpdate(update);
                applyUpdate(update);
                try {
                try {
                    NotificationListenerService.this.onNotificationPosted(sbn);
                    NotificationListenerService.this.onNotificationPosted(sbn, mRankingMap);
                } catch (Throwable t) {
                } catch (Throwable t) {
                    Log.w(TAG, "Error running onNotificationPosted", t);
                    Log.w(TAG, "Error running onNotificationPosted", t);
                }
                }
@@ -326,7 +372,7 @@ public abstract class NotificationListenerService extends Service {
            synchronized (mWrapper) {
            synchronized (mWrapper) {
                applyUpdate(update);
                applyUpdate(update);
                try {
                try {
                    NotificationListenerService.this.onNotificationRemoved(sbn);
                    NotificationListenerService.this.onNotificationRemoved(sbn, mRankingMap);
                } catch (Throwable t) {
                } catch (Throwable t) {
                    Log.w(TAG, "Error running onNotificationRemoved", t);
                    Log.w(TAG, "Error running onNotificationRemoved", t);
                }
                }
@@ -351,7 +397,7 @@ public abstract class NotificationListenerService extends Service {
            synchronized (mWrapper) {
            synchronized (mWrapper) {
                applyUpdate(update);
                applyUpdate(update);
                try {
                try {
                    NotificationListenerService.this.onNotificationRankingUpdate();
                    NotificationListenerService.this.onNotificationRankingUpdate(mRankingMap);
                } catch (Throwable t) {
                } catch (Throwable t) {
                    Log.w(TAG, "Error running onNotificationRankingUpdate", t);
                    Log.w(TAG, "Error running onNotificationRankingUpdate", t);
                }
                }
@@ -360,7 +406,65 @@ public abstract class NotificationListenerService extends Service {
    }
    }


    private void applyUpdate(NotificationRankingUpdate update) {
    private void applyUpdate(NotificationRankingUpdate update) {
        mRanking = new Ranking(update);
        mRankingMap = new RankingMap(update);
    }

    /**
     * Provides access to ranking information on a currently active
     * notification.
     *
     * <p>
     * Note that this object is not updated on notification events (such as
     * {@link #onNotificationPosted(StatusBarNotification, RankingMap)},
     * {@link #onNotificationRemoved(StatusBarNotification)}, etc.). Make sure
     * to retrieve a new Ranking from the current {@link RankingMap} whenever
     * a notification event occurs.
     */
    public static class Ranking {
        private final String mKey;
        private final int mRank;
        private final boolean mIsAmbient;
        private final boolean mIsInterceptedByDnd;

        private Ranking(String key, int rank, boolean isAmbient, boolean isInterceptedByDnd) {
            mKey = key;
            mRank = rank;
            mIsAmbient = isAmbient;
            mIsInterceptedByDnd = isInterceptedByDnd;
        }

        /**
         * Returns the key of the notification this Ranking applies to.
         */
        public String getKey() {
            return mKey;
        }

        /**
         * Returns the rank of the notification.
         *
         * @return the rank of the notification, that is the 0-based index in
         *     the list of active notifications.
         */
        public int getRank() {
            return mRank;
        }

        /**
         * Returns whether the notification is an ambient notification, that is
         * a notification that doesn't require the user's immediate attention.
         */
        public boolean isAmbient() {
            return mIsAmbient;
        }

        /**
         * Returns whether the notification was intercepted by
         * &quot;Do not disturb&quot;.
         */
        public boolean isInterceptedByDoNotDisturb() {
            return mIsInterceptedByDnd;
        }
    }
    }


    /**
    /**
@@ -371,11 +475,14 @@ public abstract class NotificationListenerService extends Service {
     * Note that this object represents a ranking snapshot that only applies to
     * Note that this object represents a ranking snapshot that only applies to
     * notifications active at the time of retrieval.
     * notifications active at the time of retrieval.
     */
     */
    public static class Ranking implements Parcelable {
    public static class RankingMap implements Parcelable {
        private final NotificationRankingUpdate mRankingUpdate;
        private final NotificationRankingUpdate mRankingUpdate;
        private final ArrayMap<String, Ranking> mRankingCache;
        private boolean mRankingCacheInitialized;


        private Ranking(NotificationRankingUpdate rankingUpdate) {
        private RankingMap(NotificationRankingUpdate rankingUpdate) {
            mRankingUpdate = rankingUpdate;
            mRankingUpdate = rankingUpdate;
            mRankingCache = new ArrayMap<>(rankingUpdate.getOrderedKeys().length);
        }
        }


        /**
        /**
@@ -389,56 +496,37 @@ public abstract class NotificationListenerService extends Service {
        }
        }


        /**
        /**
         * Returns the rank of the notification with the given key, that is the
         * Returns the Ranking for the notification with the given key.
         * index of <code>key</code> in the array of keys returned by
         * {@link #getOrderedKeys()}.
         *
         *
         * @return The rank of the notification with the given key; -1 when the
         * @return the Ranking of the notification with the given key;
         *      given key is unknown.
         *     <code>null</code> when the key is unknown.
         */
         */
        public int getRank(String key) {
        public Ranking getRanking(String key) {
            // TODO: Optimize.
            synchronized (mRankingCache) {
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
                if (!mRankingCacheInitialized) {
            for (int i = 0; i < orderedKeys.length; i++) {
                    initializeRankingCache();
                if (orderedKeys[i].equals(key)) {
                    mRankingCacheInitialized = true;
                    return i;
                }
            }
            return -1;
        }

        /**
         * Returns whether the notification with the given key was intercepted
         * by &quot;Do not disturb&quot;.
         */
        public boolean isInterceptedByDoNotDisturb(String key) {
            // TODO: Optimize.
            for (String interceptedKey : mRankingUpdate.getDndInterceptedKeys()) {
                if (interceptedKey.equals(key)) {
                    return true;
                }
                }
            }
            }
            return false;
            return mRankingCache.get(key);
        }
        }


        /**
        private void initializeRankingCache() {
         * Returns whether the notification with the given key is an ambient
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
         * notification, that is a notification that doesn't require the user's
         * immediate attention.
         */
        public boolean isAmbient(String key) {
            // TODO: Optimize.
            int firstAmbientIndex = mRankingUpdate.getFirstAmbientIndex();
            int firstAmbientIndex = mRankingUpdate.getFirstAmbientIndex();
            if (firstAmbientIndex < 0) {
            for (int i = 0; i < orderedKeys.length; i++) {
                return false;
                String key = orderedKeys[i];
                boolean isAmbient = firstAmbientIndex > -1 && firstAmbientIndex <= i;
                boolean isInterceptedByDnd = false;
                // TODO: Optimize.
                for (String s : mRankingUpdate.getDndInterceptedKeys()) {
                    if (s.equals(key)) {
                        isInterceptedByDnd = true;
                        break;
                    }
                    }
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
            for (int i = firstAmbientIndex; i < orderedKeys.length; i++) {
                if (orderedKeys[i].equals(key)) {
                    return true;
                }
                }
                mRankingCache.put(key, new Ranking(key, i, isAmbient, isInterceptedByDnd));
            }
            }
            return false;
        }
        }


        // ----------- Parcelable
        // ----------- Parcelable
@@ -453,16 +541,16 @@ public abstract class NotificationListenerService extends Service {
            dest.writeParcelable(mRankingUpdate, flags);
            dest.writeParcelable(mRankingUpdate, flags);
        }
        }


        public static final Creator<Ranking> CREATOR = new Creator<Ranking>() {
        public static final Creator<RankingMap> CREATOR = new Creator<RankingMap>() {
            @Override
            @Override
            public Ranking createFromParcel(Parcel source) {
            public RankingMap createFromParcel(Parcel source) {
                NotificationRankingUpdate rankingUpdate = source.readParcelable(null);
                NotificationRankingUpdate rankingUpdate = source.readParcelable(null);
                return new Ranking(rankingUpdate);
                return new RankingMap(rankingUpdate);
            }
            }


            @Override
            @Override
            public Ranking[] newArray(int size) {
            public RankingMap[] newArray(int size) {
                return new Ranking[size];
                return new RankingMap[size];
            }
            }
        };
        };
    }
    }
+18 −19
Original line number Original line Diff line number Diff line
@@ -48,7 +48,7 @@ import android.provider.Settings;
import android.service.dreams.DreamService;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.service.dreams.IDreamManager;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
@@ -293,7 +293,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        public void onListenerConnected() {
        public void onListenerConnected() {
            if (DEBUG) Log.d(TAG, "onListenerConnected");
            if (DEBUG) Log.d(TAG, "onListenerConnected");
            final StatusBarNotification[] notifications = getActiveNotifications();
            final StatusBarNotification[] notifications = getActiveNotifications();
            final Ranking currentRanking = getCurrentRanking();
            final RankingMap currentRanking = getCurrentRanking();
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                @Override
                @Override
                public void run() {
                public void run() {
@@ -305,41 +305,40 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
        }


        @Override
        @Override
        public void onNotificationPosted(final StatusBarNotification sbn) {
        public void onNotificationPosted(final StatusBarNotification sbn,
                final RankingMap rankingMap) {
            if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
            if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
            final Ranking currentRanking = getCurrentRanking();
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                @Override
                @Override
                public void run() {
                public void run() {
                    if (mNotificationData.findByKey(sbn.getKey()) != null) {
                    if (mNotificationData.findByKey(sbn.getKey()) != null) {
                        updateNotificationInternal(sbn, currentRanking);
                        updateNotificationInternal(sbn, rankingMap);
                    } else {
                    } else {
                        addNotificationInternal(sbn, currentRanking);
                        addNotificationInternal(sbn, rankingMap);
                    }
                    }
                }
                }
            });
            });
        }
        }


        @Override
        @Override
        public void onNotificationRemoved(final StatusBarNotification sbn) {
        public void onNotificationRemoved(final StatusBarNotification sbn,
                final RankingMap rankingMap) {
            if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn);
            if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn);
            final Ranking currentRanking = getCurrentRanking();
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                @Override
                @Override
                public void run() {
                public void run() {
                    removeNotificationInternal(sbn.getKey(), currentRanking);
                    removeNotificationInternal(sbn.getKey(), rankingMap);
                }
                }
            });
            });
        }
        }


        @Override
        @Override
        public void onNotificationRankingUpdate() {
        public void onNotificationRankingUpdate(final RankingMap rankingMap) {
            if (DEBUG) Log.d(TAG, "onRankingUpdate");
            if (DEBUG) Log.d(TAG, "onRankingUpdate");
            final Ranking currentRanking = getCurrentRanking();
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                @Override
                @Override
                public void run() {
                public void run() {
                    updateRankingInternal(currentRanking);
                    updateRankingInternal(rankingMap);
                }
                }
            });
            });
        }
        }
@@ -1177,7 +1176,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
        }
    }
    }


    protected StatusBarNotification removeNotificationViews(String key, Ranking ranking) {
    protected StatusBarNotification removeNotificationViews(String key, RankingMap ranking) {
        NotificationData.Entry entry = mNotificationData.remove(key, ranking);
        NotificationData.Entry entry = mNotificationData.remove(key, ranking);
        if (entry == null) {
        if (entry == null) {
            Log.w(TAG, "removeNotification for unknown key: " + key);
            Log.w(TAG, "removeNotification for unknown key: " + key);
@@ -1217,7 +1216,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        return entry;
        return entry;
    }
    }


    protected void addNotificationViews(Entry entry, Ranking ranking) {
    protected void addNotificationViews(Entry entry, RankingMap ranking) {
        if (entry == null) {
        if (entry == null) {
            return;
            return;
        }
        }
@@ -1226,7 +1225,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        updateNotifications();
        updateNotifications();
    }
    }


    private void addNotificationViews(StatusBarNotification notification, Ranking ranking) {
    private void addNotificationViews(StatusBarNotification notification, RankingMap ranking) {
        addNotificationViews(createNotificationViews(notification), ranking);
        addNotificationViews(createNotificationViews(notification), ranking);
    }
    }


@@ -1312,9 +1311,9 @@ public abstract class BaseStatusBar extends SystemUI implements
    }
    }


    public abstract void addNotificationInternal(StatusBarNotification notification,
    public abstract void addNotificationInternal(StatusBarNotification notification,
            Ranking ranking);
            RankingMap ranking);


    protected abstract void updateRankingInternal(Ranking ranking);
    protected abstract void updateRankingInternal(RankingMap ranking);


    @Override
    @Override
    public void removeNotification(String key) {
    public void removeNotification(String key) {
@@ -1323,7 +1322,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
        }
    }
    }


    public abstract void removeNotificationInternal(String key, Ranking ranking);
    public abstract void removeNotificationInternal(String key, RankingMap ranking);


    public void updateNotification(StatusBarNotification notification) {
    public void updateNotification(StatusBarNotification notification) {
        if (!USE_NOTIFICATION_LISTENER) {
        if (!USE_NOTIFICATION_LISTENER) {
@@ -1331,7 +1330,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
        }
    }
    }


    public void updateNotificationInternal(StatusBarNotification notification, Ranking ranking) {
    public void updateNotificationInternal(StatusBarNotification notification, RankingMap ranking) {
        if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")");
        if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")");


        final NotificationData.Entry oldEntry = mNotificationData.findByKey(notification.getKey());
        final NotificationData.Entry oldEntry = mNotificationData.findByKey(notification.getKey());
+6 −4
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.os.Process;
import android.os.Process;
import android.provider.Settings;
import android.provider.Settings;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
@@ -58,17 +59,18 @@ public class InterceptedNotifications {
        updateSyntheticNotification();
        updateSyntheticNotification();
    }
    }


    public boolean tryIntercept(StatusBarNotification notification, Ranking ranking) {
    public boolean tryIntercept(StatusBarNotification notification, RankingMap rankingMap) {
        if (ranking == null) return false;
        if (rankingMap == null) return false;
        if (shouldDisplayIntercepted()) return false;
        if (shouldDisplayIntercepted()) return false;
        if (mReleased.contains(notification.getKey())) return false;
        if (mReleased.contains(notification.getKey())) return false;
        if (!ranking.isInterceptedByDoNotDisturb(notification.getKey())) return false;
        Ranking ranking = rankingMap.getRanking(notification.getKey());
        if (!ranking.isInterceptedByDoNotDisturb()) return false;
        mIntercepted.put(notification.getKey(), notification);
        mIntercepted.put(notification.getKey(), notification);
        updateSyntheticNotification();
        updateSyntheticNotification();
        return true;
        return true;
    }
    }


    public void retryIntercepts(Ranking ranking) {
    public void retryIntercepts(RankingMap ranking) {
        if (ranking == null) return;
        if (ranking == null) return;


        final int N = mIntercepted.size();
        final int N = mIntercepted.size();
+13 −7
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar;


import android.app.Notification;
import android.app.Notification;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.view.View;
import android.view.View;


@@ -70,12 +71,16 @@ public class NotificationData {
    }
    }


    private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
    private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
    private Ranking mRanking;
    private RankingMap mRanking;
    private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() {
    private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() {
        @Override
        @Override
        public int compare(Entry a, Entry b) {
        public int compare(Entry a, Entry b) {
            if (mRanking != null) {
            if (mRanking != null) {
                return mRanking.getRank(a.key) - mRanking.getRank(b.key);
                Ranking aRanking = mRanking.getRanking(a.key);
                Ranking bRanking = mRanking.getRanking(b.key);
                int aRank = aRanking != null ? aRanking.getRank() : -1;
                int bRank = bRanking != null ? bRanking.getRank() : -1;
                return aRank - bRank;
            }
            }


            final StatusBarNotification na = a.notification;
            final StatusBarNotification na = a.notification;
@@ -108,12 +113,12 @@ public class NotificationData {
        return null;
        return null;
    }
    }


    public void add(Entry entry, Ranking ranking) {
    public void add(Entry entry, RankingMap ranking) {
        mEntries.add(entry);
        mEntries.add(entry);
        updateRankingAndSort(ranking);
        updateRankingAndSort(ranking);
    }
    }


    public Entry remove(String key, Ranking ranking) {
    public Entry remove(String key, RankingMap ranking) {
        Entry e = findByKey(key);
        Entry e = findByKey(key);
        if (e == null) {
        if (e == null) {
            return null;
            return null;
@@ -123,7 +128,7 @@ public class NotificationData {
        return e;
        return e;
    }
    }


    public void updateRanking(Ranking ranking) {
    public void updateRanking(RankingMap ranking) {
        updateRankingAndSort(ranking);
        updateRankingAndSort(ranking);
    }
    }


@@ -137,12 +142,13 @@ public class NotificationData {
                }
                }
            }
            }
        } else {
        } else {
            return mRanking.isAmbient(key);
            Ranking ranking = mRanking.getRanking(key);
            return ranking != null && ranking.isAmbient();
        }
        }
        return false;
        return false;
    }
    }


    private void updateRankingAndSort(Ranking ranking) {
    private void updateRankingAndSort(RankingMap ranking) {
        if (ranking != null) {
        if (ranking != null) {
            mRanking = ranking;
            mRanking = ranking;
        }
        }
Loading