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

Commit bd2db3c7 authored by Chris Wren's avatar Chris Wren Committed by Android Git Automerger
Browse files

am 9fca9ecb: Merge "notification ranking infrastructure"

* commit '9fca9ecbf966372d42210f229005de43bf2d3159':
  notification ranking infrastructure
parents 745e3471 9bbc0ca0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -25222,16 +25222,24 @@ package android.service.notification {
    method public final deprecated void cancelNotification(java.lang.String, java.lang.String, int);
    method public final void cancelNotification(java.lang.String);
    method public final void cancelNotifications(java.lang.String[]);
    method public java.lang.String[] getActiveNotificationKeys();
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.service.notification.StatusBarNotification[] getActiveNotifications(java.lang.String[]);
    method public java.lang.String[] getOrderedNotificationKeys();
    method public android.os.IBinder onBind(android.content.Intent);
    method public void onListenerConnected(java.lang.String[]);
    method public void onNotificationOrderUpdate();
    method public abstract void onNotificationPosted(android.service.notification.StatusBarNotification);
    method public abstract void onNotificationRemoved(android.service.notification.StatusBarNotification);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
  }
  public class NotificationOrderUpdate implements android.os.Parcelable {
    ctor public NotificationOrderUpdate(android.os.Parcel);
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public class StatusBarNotification implements android.os.Parcelable {
    ctor public StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
    ctor public StatusBarNotification(android.os.Parcel);
+2 −2
Original line number Diff line number Diff line
@@ -659,8 +659,8 @@ public class Notification implements Parcelable

    /**
     * @hide
     * Extra added by NotificationManagerService to indicate whether a NotificationScorer
     * modified the Notifications's score.
     * Extra added by NotificationManagerService to indicate whether
     * the Notifications's score has been modified.
     */
    public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified";

+7 −3
Original line number Diff line number Diff line
@@ -17,11 +17,15 @@
package android.service.notification;

import android.service.notification.StatusBarNotification;
import android.service.notification.NotificationOrderUpdate;

/** @hide */
oneway interface INotificationListener
{
    void onListenerConnected(in String[] notificationKeys);
    void onNotificationPosted(in StatusBarNotification notification);
    void onNotificationRemoved(in StatusBarNotification notification);
    void onListenerConnected(in NotificationOrderUpdate update);
    void onNotificationPosted(in StatusBarNotification notification,
            in NotificationOrderUpdate update);
    void onNotificationRemoved(in StatusBarNotification notification,
            in NotificationOrderUpdate update);
    void onNotificationOrderUpdate(in NotificationOrderUpdate update);
}
 No newline at end of file
+61 −21
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;

import java.util.Comparator;
import java.util.HashMap;

/**
 * A service that receives calls from the system when new notifications are posted or removed.
 * <p>To extend this class, you must declare the service in your manifest file with
@@ -46,6 +49,7 @@ public abstract class NotificationListenerService extends Service {
            + "[" + getClass().getSimpleName() + "]";

    private INotificationListenerWrapper mWrapper = null;
    private String[] mNotificationKeys;

    private INotificationManager mNoMan;

@@ -95,6 +99,15 @@ public abstract class NotificationListenerService extends Service {
        // optional
    }

    /**
     * Implement this method to be notified when the notification order cahnges.
     *
     * Call {@link #getOrderedNotificationKeys()} to retrieve the new order.
     */
    public void onNotificationOrderUpdate() {
        // optional
    }

    private final INotificationManager getNotificationInterface() {
        if (mNoMan == null) {
            mNoMan = INotificationManager.Stub.asInterface(
@@ -202,7 +215,7 @@ public abstract class NotificationListenerService extends Service {
     * Request the list of outstanding notifications (that is, those that are visible to the
     * current user). Useful when you don't know what's already been posted.
     *
     * @return An array of active notifications.
     * @return An array of active notifications, sorted in natural order.
     */
    public StatusBarNotification[] getActiveNotifications() {
        return getActiveNotifications(null /*all*/);
@@ -213,7 +226,8 @@ public abstract class NotificationListenerService extends Service {
     * current user). Useful when you don't know what's already been posted.
     *
     * @param keys A specific list of notification keys, or {@code null} for all.
     * @return An array of active notifications.
     * @return An array of active notifications, sorted in natural order
     *   if {@code keys} is {@code null}.
     */
    public StatusBarNotification[] getActiveNotifications(String[] keys) {
        if (!isBound()) return null;
@@ -226,21 +240,15 @@ public abstract class NotificationListenerService extends Service {
    }

    /**
     * Request the list of outstanding notification keys(that is, those that are visible to the
     * current user).  You can use the notification keys for subsequent retrieval via
     * Request the list of notification keys in their current natural order.
     * You can use the notification keys for subsequent retrieval via
     * {@link #getActiveNotifications(String[]) or dismissal via
     * {@link #cancelNotifications(String[]).
     *
     * @return An array of active notification keys.
     * @return An array of active notification keys, in their natural order.
     */
    public String[] getActiveNotificationKeys() {
        if (!isBound()) return null;
        try {
            return getNotificationInterface().getActiveNotificationKeysFromListener(mWrapper);
        } catch (android.os.RemoteException ex) {
            Log.v(TAG, "Unable to contact notification manager", ex);
        }
        return null;
    public String[] getOrderedNotificationKeys() {
        return mNotificationKeys;
    }

    @Override
@@ -261,28 +269,60 @@ public abstract class NotificationListenerService extends Service {

    private class INotificationListenerWrapper extends INotificationListener.Stub {
        @Override
        public void onNotificationPosted(StatusBarNotification sbn) {
        public void onNotificationPosted(StatusBarNotification sbn,
                NotificationOrderUpdate update) {
            try {
                // protect subclass from concurrent modifications of (@link mNotificationKeys}.
                synchronized (mWrapper) {
                    updateNotificationKeys(update);
                    NotificationListenerService.this.onNotificationPosted(sbn);
                }
            } catch (Throwable t) {
                Log.w(TAG, "Error running onNotificationPosted", t);
                Log.w(TAG, "Error running onOrderedNotificationPosted", t);
            }
        }
        @Override
        public void onNotificationRemoved(StatusBarNotification sbn) {
        public void onNotificationRemoved(StatusBarNotification sbn,
                NotificationOrderUpdate update) {
            try {
                // protect subclass from concurrent modifications of (@link mNotificationKeys}.
                synchronized (mWrapper) {
                    updateNotificationKeys(update);
                    NotificationListenerService.this.onNotificationRemoved(sbn);
                }
            } catch (Throwable t) {
                Log.w(TAG, "Error running onNotificationRemoved", t);
            }
        }
        @Override
        public void onListenerConnected(String[] notificationKeys) {
        public void onListenerConnected(NotificationOrderUpdate update) {
            try {
                NotificationListenerService.this.onListenerConnected(notificationKeys);
                // protect subclass from concurrent modifications of (@link mNotificationKeys}.
                synchronized (mWrapper) {
                    updateNotificationKeys(update);
                    NotificationListenerService.this.onListenerConnected(mNotificationKeys);
                }
            } catch (Throwable t) {
                Log.w(TAG, "Error running onListenerConnected", t);
            }
        }
        @Override
        public void onNotificationOrderUpdate(NotificationOrderUpdate update)
                throws RemoteException {
            try {
                // protect subclass from concurrent modifications of (@link mNotificationKeys}.
                synchronized (mWrapper) {
                    updateNotificationKeys(update);
                    NotificationListenerService.this.onNotificationOrderUpdate();
                }
            } catch (Throwable t) {
                Log.w(TAG, "Error running onNotificationOrderUpdate", t);
            }
        }
    }

    private void updateNotificationKeys(NotificationOrderUpdate update) {
        // TODO: avoid garbage by comparing the lists
        mNotificationKeys = update.getOrderedKeys();
    }
}
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2014, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.notification;

parcelable NotificationOrderUpdate;
Loading