am 596ce060: Merge "SysUI: Implement NotificationListenerService in StatusBar" into lmp-preview-dev
* commit '596ce060988d869ed5d6ac0f25cad79d9ab4fba6': SysUI: Implement NotificationListenerService in StatusBar
This commit is contained in:
@@ -22,6 +22,7 @@ import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.TaskStackBuilder;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@@ -46,6 +47,7 @@ import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.dreams.DreamService;
|
||||
import android.service.dreams.IDreamManager;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -79,6 +81,7 @@ import com.android.systemui.statusbar.phone.KeyguardTouchDelegate;
|
||||
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.android.keyguard.KeyguardHostView.OnDismissAction;
|
||||
@@ -88,6 +91,7 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
public static final String TAG = "StatusBar";
|
||||
public static final boolean DEBUG = false;
|
||||
public static final boolean MULTIUSER_DEBUG = false;
|
||||
private static final boolean USE_NOTIFICATION_LISTENER = false;
|
||||
|
||||
protected static final int MSG_SHOW_RECENT_APPS = 1019;
|
||||
protected static final int MSG_HIDE_RECENT_APPS = 1020;
|
||||
@@ -160,6 +164,7 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
|
||||
protected WindowManager mWindowManager;
|
||||
protected IWindowManager mWindowManagerService;
|
||||
|
||||
protected abstract void refreshLayout(int layoutDirection);
|
||||
|
||||
protected Display mDisplay;
|
||||
@@ -273,6 +278,49 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
}
|
||||
};
|
||||
|
||||
private final NotificationListenerService mNotificationListener =
|
||||
new NotificationListenerService() {
|
||||
@Override
|
||||
public void onListenerConnected() {
|
||||
if (DEBUG) Log.d(TAG, "onListenerConnected");
|
||||
final StatusBarNotification[] notifications = getActiveNotifications();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (StatusBarNotification sbn : notifications) {
|
||||
addNotificationInternal(sbn);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationPosted(final StatusBarNotification sbn) {
|
||||
if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mNotificationData.findByKey(sbn.getKey()) != null) {
|
||||
updateNotificationInternal(sbn);
|
||||
} else {
|
||||
addNotificationInternal(sbn);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationRemoved(final StatusBarNotification sbn) {
|
||||
if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeNotificationInternal(sbn.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private void updateCurrentProfilesCache() {
|
||||
synchronized (mCurrentProfiles) {
|
||||
mCurrentProfiles.clear();
|
||||
@@ -355,11 +403,22 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
}
|
||||
|
||||
// Set up the initial notification state.
|
||||
N = notifications.size();
|
||||
for (int i=0; i<N; i++) {
|
||||
addNotification(notifications.get(i));
|
||||
if (USE_NOTIFICATION_LISTENER) {
|
||||
try {
|
||||
mNotificationListener.registerAsSystemService(
|
||||
new ComponentName(mContext.getPackageName(), getClass().getCanonicalName()),
|
||||
UserHandle.USER_ALL);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Unable to register notification listener", e);
|
||||
}
|
||||
} else {
|
||||
N = notifications.size();
|
||||
for (int i=0; i<N; i++) {
|
||||
addNotification(notifications.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, String.format(
|
||||
"init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x",
|
||||
@@ -1204,7 +1263,32 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
return parent != null && parent.indexOfChild(entry.row) == 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addNotification(StatusBarNotification notification) {
|
||||
if (!USE_NOTIFICATION_LISTENER) {
|
||||
addNotificationInternal(notification);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void addNotificationInternal(StatusBarNotification notification);
|
||||
|
||||
@Override
|
||||
public void removeNotification(String key) {
|
||||
if (!USE_NOTIFICATION_LISTENER) {
|
||||
removeNotificationInternal(key);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void removeNotificationInternal(String key);
|
||||
|
||||
public void updateNotification(StatusBarNotification notification) {
|
||||
if (!USE_NOTIFICATION_LISTENER) {
|
||||
updateNotificationInternal(notification);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNotificationInternal(StatusBarNotification notification) {
|
||||
if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")");
|
||||
|
||||
final NotificationData.Entry oldEntry = mNotificationData.findByKey(notification.getKey());
|
||||
@@ -1280,11 +1364,11 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
boolean orderUnchanged =
|
||||
notification.getNotification().when == oldNotification.getNotification().when
|
||||
&& notification.getScore() == oldNotification.getScore();
|
||||
// score now encompasses/supersedes isOngoing()
|
||||
// score now encompasses/supersedes isOngoing()
|
||||
|
||||
boolean updateTicker = notification.getNotification().tickerText != null
|
||||
&& !TextUtils.equals(notification.getNotification().tickerText,
|
||||
oldEntry.notification.getNotification().tickerText);
|
||||
oldEntry.notification.getNotification().tickerText);
|
||||
boolean isTopAnyway = isTopNotification(rowParent, oldEntry);
|
||||
if (contentsUnchanged && bigContentsUnchanged && headsUpContentsUnchanged && publicUnchanged
|
||||
&& (orderUnchanged || isTopAnyway)) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class InterceptedNotifications {
|
||||
for (int i = 0; i < n; i++) {
|
||||
final StatusBarNotification sbn = mIntercepted.valueAt(i);
|
||||
sbn.getNotification().extras.putBoolean(EXTRA_INTERCEPT, false);
|
||||
mBar.addNotification(sbn);
|
||||
mBar.addNotificationInternal(sbn);
|
||||
}
|
||||
mIntercepted.clear();
|
||||
updateSyntheticNotification();
|
||||
@@ -88,7 +88,7 @@ public class InterceptedNotifications {
|
||||
private void updateSyntheticNotification() {
|
||||
if (mIntercepted.isEmpty()) {
|
||||
if (mSynKey != null) {
|
||||
mBar.removeNotification(mSynKey);
|
||||
mBar.removeNotificationInternal(mSynKey);
|
||||
mSynKey = null;
|
||||
}
|
||||
return;
|
||||
@@ -107,9 +107,9 @@ public class InterceptedNotifications {
|
||||
mBar.getCurrentUserHandle());
|
||||
if (mSynKey == null) {
|
||||
mSynKey = sbn.getKey();
|
||||
mBar.addNotification(sbn);
|
||||
mBar.addNotificationInternal(sbn);
|
||||
} else {
|
||||
mBar.updateNotification(sbn);
|
||||
mBar.updateNotificationInternal(sbn);
|
||||
}
|
||||
final NotificationData.Entry entry = mBar.mNotificationData.findByKey(mSynKey);
|
||||
entry.row.setOnClickListener(mSynClickListener);
|
||||
|
||||
@@ -1035,7 +1035,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotification(StatusBarNotification notification) {
|
||||
public void addNotificationInternal(StatusBarNotification notification) {
|
||||
if (DEBUG) Log.d(TAG, "addNotification score=" + notification.getScore());
|
||||
Entry shadeEntry = createNotificationViews(notification);
|
||||
if (shadeEntry == null) {
|
||||
@@ -1103,7 +1103,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNotification(String key) {
|
||||
public void removeNotificationInternal(String key) {
|
||||
StatusBarNotification old = removeNotificationViews(key);
|
||||
if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old);
|
||||
|
||||
|
||||
@@ -49,10 +49,18 @@ public class TvStatusBar extends BaseStatusBar {
|
||||
public void addNotification(StatusBarNotification notification) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotificationInternal(StatusBarNotification notification) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(StatusBarNotification notification) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeNotificationInternal(String key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNotification(String key) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user