Use NotificationListenerService instead of raw INotificationListener.

Bug: 14846846
Depends-On: Ic308b2f78c86393304d446c57fd677294e01717c
Change-Id: If1d38d6d82466c4a69249dc7d76a9cb215c81e8f
This commit is contained in:
Chris Wren
2014-05-14 15:29:11 -04:00
parent 3f7e0571d3
commit 5001834d03

View File

@@ -35,8 +35,7 @@ import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.service.notification.INotificationListener;
import android.service.notification.NotificationOrderUpdate;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.LayoutInflater;
@@ -73,14 +72,13 @@ public class NotificationStation extends SettingsPreferenceFragment {
}
};
private INotificationListener.Stub mListener = new INotificationListener.Stub() {
private NotificationListenerService mListener = new NotificationListenerService() {
@Override
public void onListenerConnected(NotificationOrderUpdate update) throws RemoteException {
public void onListenerConnected(String[] notificationKeys) {
// noop
}
@Override
public void onNotificationPosted(StatusBarNotification notification,
NotificationOrderUpdate update) throws RemoteException {
public void onNotificationPosted(StatusBarNotification notification) {
Log.v(TAG, "onNotificationPosted: " + notification);
final Handler h = getListView().getHandler();
h.removeCallbacks(mRefreshListRunnable);
@@ -88,17 +86,11 @@ public class NotificationStation extends SettingsPreferenceFragment {
}
@Override
public void onNotificationRemoved(StatusBarNotification notification,
NotificationOrderUpdate update) throws RemoteException {
public void onNotificationRemoved(StatusBarNotification notification) {
final Handler h = getListView().getHandler();
h.removeCallbacks(mRefreshListRunnable);
h.postDelayed(mRefreshListRunnable, 100);
}
@Override
public void onNotificationOrderUpdate(NotificationOrderUpdate update)
throws RemoteException {
}
};
private NotificationHistoryAdapter mAdapter;
@@ -122,15 +114,23 @@ public class NotificationStation extends SettingsPreferenceFragment {
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
try {
mNoMan.registerListener(mListener,
new ComponentName(mContext.getPackageName(),
this.getClass().getCanonicalName()),
ActivityManager.getCurrentUser());
mListener.registerAsSystemService(new ComponentName(mContext.getPackageName(),
this.getClass().getCanonicalName()), ActivityManager.getCurrentUser());
} catch (RemoteException e) {
// well, that didn't work out
}
}
@Override
public void onDetach() {
try {
mListener.unregisterAsSystemService();
} catch (RemoteException e) {
// well, that didn't work out
}
super.onDetach();
}
@Override
public void onCreate(Bundle icicle) {
logd("onCreate(%s)", icicle);