Use NotificationListenerService instead of raw INotificationListener.
Bug: 14846846 Depends-On: Ic308b2f78c86393304d446c57fd677294e01717c Change-Id: If1d38d6d82466c4a69249dc7d76a9cb215c81e8f
This commit is contained in:
@@ -35,8 +35,7 @@ import android.os.Handler;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.service.notification.INotificationListener;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.NotificationOrderUpdate;
|
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
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
|
@Override
|
||||||
public void onListenerConnected(NotificationOrderUpdate update) throws RemoteException {
|
public void onListenerConnected(String[] notificationKeys) {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationPosted(StatusBarNotification notification,
|
public void onNotificationPosted(StatusBarNotification notification) {
|
||||||
NotificationOrderUpdate update) throws RemoteException {
|
|
||||||
Log.v(TAG, "onNotificationPosted: " + notification);
|
Log.v(TAG, "onNotificationPosted: " + notification);
|
||||||
final Handler h = getListView().getHandler();
|
final Handler h = getListView().getHandler();
|
||||||
h.removeCallbacks(mRefreshListRunnable);
|
h.removeCallbacks(mRefreshListRunnable);
|
||||||
@@ -88,17 +86,11 @@ public class NotificationStation extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationRemoved(StatusBarNotification notification,
|
public void onNotificationRemoved(StatusBarNotification notification) {
|
||||||
NotificationOrderUpdate update) throws RemoteException {
|
|
||||||
final Handler h = getListView().getHandler();
|
final Handler h = getListView().getHandler();
|
||||||
h.removeCallbacks(mRefreshListRunnable);
|
h.removeCallbacks(mRefreshListRunnable);
|
||||||
h.postDelayed(mRefreshListRunnable, 100);
|
h.postDelayed(mRefreshListRunnable, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNotificationOrderUpdate(NotificationOrderUpdate update)
|
|
||||||
throws RemoteException {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private NotificationHistoryAdapter mAdapter;
|
private NotificationHistoryAdapter mAdapter;
|
||||||
@@ -122,15 +114,23 @@ public class NotificationStation extends SettingsPreferenceFragment {
|
|||||||
mNoMan = INotificationManager.Stub.asInterface(
|
mNoMan = INotificationManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||||
try {
|
try {
|
||||||
mNoMan.registerListener(mListener,
|
mListener.registerAsSystemService(new ComponentName(mContext.getPackageName(),
|
||||||
new ComponentName(mContext.getPackageName(),
|
this.getClass().getCanonicalName()), ActivityManager.getCurrentUser());
|
||||||
this.getClass().getCanonicalName()),
|
|
||||||
ActivityManager.getCurrentUser());
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// well, that didn't work out
|
// 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
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
logd("onCreate(%s)", icicle);
|
logd("onCreate(%s)", icicle);
|
||||||
|
Reference in New Issue
Block a user