summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-05-16 15:31:23 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-16 15:31:23 +0000
commitc5a88944f005e9c9bd69eaf4c9ef17a1f6948005 (patch)
treebbec336c5df092a5e22959305e1959dcc3291481 /core
parent4ec3b0f9ab957960a8ce88a4fc41aa66817fd749 (diff)
parent1941fc718690d6b87db68b6a133c71fb470599d0 (diff)
downloadframeworks_base-c5a88944f005e9c9bd69eaf4c9ef17a1f6948005.zip
frameworks_base-c5a88944f005e9c9bd69eaf4c9ef17a1f6948005.tar.gz
frameworks_base-c5a88944f005e9c9bd69eaf4c9ef17a1f6948005.tar.bz2
Merge "Extend NotificationListenerService to support system use cases."
Diffstat (limited to 'core')
-rw-r--r--core/java/android/service/notification/NotificationListenerService.java44
1 files changed, 41 insertions, 3 deletions
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index a94f45a..e2e9ff4 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -16,9 +16,11 @@
package android.service.notification;
+import android.annotation.PrivateApi;
import android.annotation.SdkConstant;
import android.app.INotificationManager;
import android.app.Service;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
@@ -26,9 +28,6 @@ import android.os.RemoteException;
import android.os.ServiceManager;
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
@@ -53,6 +52,9 @@ public abstract class NotificationListenerService extends Service {
private INotificationManager mNoMan;
+ /** Only valid after a successful call to (@link registerAsService}. */
+ private int mCurrentUser;
+
/**
* The {@link Intent} that must be declared as handled by the service.
*/
@@ -267,6 +269,42 @@ public abstract class NotificationListenerService extends Service {
return true;
}
+ /**
+ * Directly register this service with the Notification Manager.
+ *
+ * <p>Only system services may use this call. It will fail for non-system callers.
+ * Apps should ask the user to add their listener in Settings.
+ *
+ * @param componentName the component that will consume the notification information
+ * @param currentUser the user to use as the stream filter
+ * @hide
+ */
+ @PrivateApi
+ public void registerAsSystemService(ComponentName componentName, int currentUser)
+ throws RemoteException {
+ if (mWrapper == null) {
+ mWrapper = new INotificationListenerWrapper();
+ }
+ INotificationManager noMan = getNotificationInterface();
+ noMan.registerListener(mWrapper, componentName, currentUser);
+ mCurrentUser = currentUser;
+ }
+
+ /**
+ * Directly unregister this service from the Notification Manager.
+ *
+ * <P>This method will fail for listeners that were not registered
+ * with (@link registerAsService).
+ * @hide
+ */
+ @PrivateApi
+ public void unregisterAsSystemService() throws RemoteException {
+ if (mWrapper != null) {
+ INotificationManager noMan = getNotificationInterface();
+ noMan.unregisterListener(mWrapper, mCurrentUser);
+ }
+ }
+
private class INotificationListenerWrapper extends INotificationListener.Stub {
@Override
public void onNotificationPosted(StatusBarNotification sbn,