summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-05-30 20:15:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-30 20:15:38 +0000
commit4f0e39a929f2043c46ada9f34b23654616f93227 (patch)
tree150088db28725a782460396fc240c9a9e9ad67a4 /services
parentda44532b615b1a965c94cc43d68eca92fd2ef79d (diff)
parent333a61c3a5a83fe9c50ebeb5c947317f61385b7b (diff)
downloadframeworks_base-4f0e39a929f2043c46ada9f34b23654616f93227.zip
frameworks_base-4f0e39a929f2043c46ada9f34b23654616f93227.tar.gz
frameworks_base-4f0e39a929f2043c46ada9f34b23654616f93227.tar.bz2
Merge "Track Zen Mode status in the NotificationRecord" into lmp-preview-dev
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/notification/NotificationComparator.java5
-rw-r--r--services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java2
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java253
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java204
-rw-r--r--services/core/java/com/android/server/notification/NotificationSignalExtractor.java4
-rw-r--r--services/core/java/com/android/server/notification/NotificationUsageStats.java2
-rw-r--r--services/core/java/com/android/server/notification/RankingReconsideration.java2
-rw-r--r--services/core/java/com/android/server/notification/ValidateNotificationPeople.java2
-rw-r--r--services/core/java/com/android/server/notification/ZenModeHelper.java28
9 files changed, 278 insertions, 224 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationComparator.java b/services/core/java/com/android/server/notification/NotificationComparator.java
index 49293d3..b30baea 100644
--- a/services/core/java/com/android/server/notification/NotificationComparator.java
+++ b/services/core/java/com/android/server/notification/NotificationComparator.java
@@ -21,11 +21,10 @@ import java.util.Comparator;
* Sorts notificaitons into attention-relelvant order.
*/
public class NotificationComparator
- implements Comparator<NotificationManagerService.NotificationRecord> {
+ implements Comparator<NotificationRecord> {
@Override
- public int compare(NotificationManagerService.NotificationRecord lhs,
- NotificationManagerService.NotificationRecord rhs) {
+ public int compare(NotificationRecord lhs, NotificationRecord rhs) {
if (lhs.isRecentlyIntrusive() != rhs.isRecentlyIntrusive()) {
return lhs.isRecentlyIntrusive() ? -1 : 1;
}
diff --git a/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java b/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java
index db17f3a..d8ab9d7 100644
--- a/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java
+++ b/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java
@@ -20,8 +20,6 @@ import android.app.Notification;
import android.content.Context;
import android.util.Slog;
-import com.android.server.notification.NotificationManagerService.NotificationRecord;
-
/**
* This {@link com.android.server.notification.NotificationSignalExtractor} noticies noisy
* notifications and marks them to get a temporary ranking bump.
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index bbc3091..cb78a45 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -43,7 +43,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
import android.content.res.Resources;
import android.database.ContentObserver;
-import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.IRingtonePlayer;
import android.net.Uri;
@@ -60,13 +59,13 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.Vibrator;
import android.provider.Settings;
-import android.service.notification.INotificationListener;
+import android.service.notification.Condition;
import android.service.notification.IConditionListener;
import android.service.notification.IConditionProvider;
+import android.service.notification.INotificationListener;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationRankingUpdate;
import android.service.notification.StatusBarNotification;
-import android.service.notification.Condition;
import android.service.notification.ZenModeConfig;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -87,7 +86,6 @@ import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.notification.ManagedServices.ManagedServiceInfo;
import com.android.server.notification.ManagedServices.UserProfiles;
-import com.android.server.notification.NotificationUsageStats.SingleNotificationStats;
import com.android.server.statusbar.StatusBarManagerInternal;
import libcore.io.IoUtils;
@@ -103,10 +101,8 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
-import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@@ -211,8 +207,6 @@ public class NotificationManagerService extends SystemService {
private ConditionProviders mConditionProviders;
private NotificationUsageStats mUsageStats;
- private static final String EXTRA_INTERCEPT = "android.intercept";
-
private static final int MY_UID = Process.myUid();
private static final int MY_PID = Process.myPid();
private static final int REASON_DELEGATE_CLICK = 1;
@@ -425,144 +419,6 @@ public class NotificationManagerService extends SystemService {
return true;
}
- private static String idDebugString(Context baseContext, String packageName, int id) {
- Context c = null;
-
- if (packageName != null) {
- try {
- c = baseContext.createPackageContext(packageName, 0);
- } catch (NameNotFoundException e) {
- c = baseContext;
- }
- } else {
- c = baseContext;
- }
-
- String pkg;
- String type;
- String name;
-
- Resources r = c.getResources();
- try {
- return r.getResourceName(id);
- } catch (Resources.NotFoundException e) {
- return "<name unknown>";
- }
- }
-
-
-
- public static final class NotificationRecord {
- final StatusBarNotification sbn;
- SingleNotificationStats stats;
- boolean isCanceled;
-
- // These members are used by NotificationSignalExtractors
- // to communicate with the ranking module.
- private float mContactAffinity;
- private boolean mRecentlyIntrusive;
-
- NotificationRecord(StatusBarNotification sbn)
- {
- this.sbn = sbn;
- }
-
- public Notification getNotification() { return sbn.getNotification(); }
- public int getFlags() { return sbn.getNotification().flags; }
- public int getUserId() { return sbn.getUserId(); }
- public String getKey() { return sbn.getKey(); }
-
- void dump(PrintWriter pw, String prefix, Context baseContext) {
- final Notification notification = sbn.getNotification();
- pw.println(prefix + this);
- pw.println(prefix + " uid=" + sbn.getUid() + " userId=" + sbn.getUserId());
- pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
- + " / " + idDebugString(baseContext, sbn.getPackageName(), notification.icon));
- pw.println(prefix + " pri=" + notification.priority + " score=" + sbn.getScore());
- pw.println(prefix + " key=" + sbn.getKey());
- pw.println(prefix + " contentIntent=" + notification.contentIntent);
- pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
- pw.println(prefix + " tickerText=" + notification.tickerText);
- pw.println(prefix + " contentView=" + notification.contentView);
- pw.println(prefix + String.format(" defaults=0x%08x flags=0x%08x",
- notification.defaults, notification.flags));
- pw.println(prefix + " sound=" + notification.sound);
- pw.println(prefix + String.format(" color=0x%08x", notification.color));
- pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
- pw.println(prefix + String.format(" led=0x%08x onMs=%d offMs=%d",
- notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
- if (notification.actions != null && notification.actions.length > 0) {
- pw.println(prefix + " actions={");
- final int N = notification.actions.length;
- for (int i=0; i<N; i++) {
- final Notification.Action action = notification.actions[i];
- pw.println(String.format("%s [%d] \"%s\" -> %s",
- prefix,
- i,
- action.title,
- action.actionIntent.toString()
- ));
- }
- pw.println(prefix + " }");
- }
- if (notification.extras != null && notification.extras.size() > 0) {
- pw.println(prefix + " extras={");
- for (String key : notification.extras.keySet()) {
- pw.print(prefix + " " + key + "=");
- Object val = notification.extras.get(key);
- if (val == null) {
- pw.println("null");
- } else {
- pw.print(val.getClass().getSimpleName());
- if (val instanceof CharSequence || val instanceof String) {
- // redact contents from bugreports
- } else if (val instanceof Bitmap) {
- pw.print(String.format(" (%dx%d)",
- ((Bitmap) val).getWidth(),
- ((Bitmap) val).getHeight()));
- } else if (val.getClass().isArray()) {
- final int N = Array.getLength(val);
- pw.println(" (" + N + ")");
- } else {
- pw.print(" (" + String.valueOf(val) + ")");
- }
- pw.println();
- }
- }
- pw.println(prefix + " }");
- }
- pw.println(prefix + " stats=" + stats.toString());
- pw.println(prefix + " mContactAffinity=" + mContactAffinity);
- pw.println(prefix + " mRecentlyIntrusive=" + mRecentlyIntrusive);
- }
-
- @Override
- public final String toString() {
- return String.format(
- "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d key=%s: %s)",
- System.identityHashCode(this),
- this.sbn.getPackageName(), this.sbn.getUser(), this.sbn.getId(),
- this.sbn.getTag(), this.sbn.getScore(), this.sbn.getKey(),
- this.sbn.getNotification());
- }
-
- public void setContactAffinity(float contactAffinity) {
- mContactAffinity = contactAffinity;
- }
-
- public float getContactAffinity() {
- return mContactAffinity;
- }
-
- public void setRecentlyIntusive(boolean recentlyIntrusive) {
- mRecentlyIntrusive = recentlyIntrusive;
- }
-
- public boolean isRecentlyIntrusive() {
- return mRecentlyIntrusive;
- }
- }
-
private static final class ToastRecord
{
final int pid;
@@ -1657,15 +1513,15 @@ public class NotificationManagerService extends SystemService {
return;
}
- // Is this notification intercepted by zen mode?
- final boolean intercept = mZenModeHelper.shouldIntercept(pkg, notification);
- notification.extras.putBoolean(EXTRA_INTERCEPT, intercept);
-
- // Should this notification make noise, vibe, or use the LED?
- final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD) && !intercept;
- if (DBG || intercept) Slog.v(TAG,
- "pkg=" + pkg + " canInterrupt=" + canInterrupt + " intercept=" + intercept);
synchronized (mNotificationList) {
+ applyZenModeLocked(r);
+
+ // Should this notification make noise, vibe, or use the LED?
+ final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD) &&
+ !r.isIntercepted();
+ if (DBG || r.isIntercepted()) Slog.v(TAG,
+ "pkg=" + pkg + " canInterrupt=" + canInterrupt +
+ " intercept=" + r.isIntercepted());
NotificationRecord old = null;
int index = indexOfNotificationLocked(n.getKey());
if (index < 0) {
@@ -1678,6 +1534,8 @@ public class NotificationManagerService extends SystemService {
// Make sure we don't lose the foreground service state.
notification.flags |=
old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
+ // Retain ranking information from previous record
+ r.copyRankingInformation(old);
mNotificationsByKey.remove(old.sbn.getKey());
}
mNotificationsByKey.put(n.getKey(), r);
@@ -1724,7 +1582,7 @@ public class NotificationManagerService extends SystemService {
sendAccessibilityEvent(notification, pkg);
}
- mListeners.notifyPostedLocked(r.sbn, cloneNotificationListLocked());
+ mListeners.notifyPostedLocked(r.sbn);
} else {
Slog.e(TAG, "Not posting notification with icon==0: " + notification);
if (old != null && !old.isCanceled) {
@@ -1735,7 +1593,7 @@ public class NotificationManagerService extends SystemService {
Binder.restoreCallingIdentity(identity);
}
- mListeners.notifyRemovedLocked(r.sbn, cloneNotificationListLocked());
+ mListeners.notifyRemovedLocked(r.sbn);
}
// ATTENTION: in a future release we will bail out here
// so that we do not play sounds, show lights, etc. for invalid
@@ -1992,23 +1850,32 @@ public class NotificationManagerService extends SystemService {
if (!(message.obj instanceof RankingReconsideration)) return;
RankingReconsideration recon = (RankingReconsideration) message.obj;
recon.run();
- boolean orderChanged;
+ boolean changed;
synchronized (mNotificationList) {
final NotificationRecord record = mNotificationsByKey.get(recon.getKey());
if (record == null) {
return;
}
- int before = findNotificationRecordIndexLocked(record);
+ int indexBefore = findNotificationRecordIndexLocked(record);
+ boolean interceptBefore = record.isIntercepted();
recon.applyChangesLocked(record);
+ applyZenModeLocked(record);
Collections.sort(mNotificationList, mRankingComparator);
- int after = findNotificationRecordIndexLocked(record);
- orderChanged = before != after;
+ int indexAfter = findNotificationRecordIndexLocked(record);
+ boolean interceptAfter = record.isIntercepted();
+ changed = indexBefore != indexAfter || interceptBefore != interceptAfter;
}
- if (orderChanged) {
+ if (changed) {
scheduleSendRankingUpdate();
}
}
+ // let zen mode evaluate this record and then make note of that for the future
+ private void applyZenModeLocked(NotificationRecord record) {
+ record.setIntercepted(mZenModeHelper.shouldIntercept(record, record.wasTouchedByZen()));
+ record.setTouchedByZen();
+ }
+
// lock on mNotificationList
private int findNotificationRecordIndexLocked(NotificationRecord target) {
return Collections.binarySearch(mNotificationList, target, mRankingComparator);
@@ -2022,19 +1889,10 @@ public class NotificationManagerService extends SystemService {
private void handleSendRankingUpdate() {
synchronized (mNotificationList) {
- mListeners.notifyRankingUpdateLocked(cloneNotificationListLocked());
+ mListeners.notifyRankingUpdateLocked();
}
}
- private ArrayList<StatusBarNotification> cloneNotificationListLocked() {
- final int N = mNotificationList.size();
- ArrayList<StatusBarNotification> sbns = new ArrayList<StatusBarNotification>(N);
- for (int i = 0; i < N; i++) {
- sbns.add(mNotificationList.get(i).sbn);
- }
- return sbns;
- }
-
private final class WorkerHandler extends Handler
{
@Override
@@ -2120,7 +1978,7 @@ public class NotificationManagerService extends SystemService {
Binder.restoreCallingIdentity(identity);
}
r.isCanceled = true;
- mListeners.notifyRemovedLocked(r.sbn, cloneNotificationListLocked());
+ mListeners.notifyRemovedLocked(r.sbn);
}
// sound
@@ -2441,22 +2299,25 @@ public class NotificationManagerService extends SystemService {
/**
* Generates a NotificationRankingUpdate from 'sbns', considering only
* notifications visible to the given listener.
+ *
+ * <p>Caller must hold a lock on mNotificationList.</p>
*/
- private static NotificationRankingUpdate makeRankingUpdateForListener(ManagedServiceInfo info,
- ArrayList<StatusBarNotification> sbns) {
+ private NotificationRankingUpdate makeRankingUpdateLocked(ManagedServiceInfo info) {
int speedBumpIndex = -1;
- ArrayList<String> keys = new ArrayList<String>(sbns.size());
- ArrayList<String> dndKeys = new ArrayList<String>(sbns.size());
- for (StatusBarNotification sbn: sbns) {
- if (!info.enabledAndUserMatches(sbn.getUserId())) {
+ final int N = mNotificationList.size();
+ ArrayList<String> keys = new ArrayList<String>(N);
+ ArrayList<String> dndKeys = new ArrayList<String>(N);
+ for (int i = 0; i < N; i++) {
+ NotificationRecord record = mNotificationList.get(i);
+ if (!info.enabledAndUserMatches(record.sbn.getUserId())) {
continue;
}
- keys.add(sbn.getKey());
- if (sbn.getNotification().extras.getBoolean(EXTRA_INTERCEPT)) {
- dndKeys.add(sbn.getKey());
+ keys.add(record.sbn.getKey());
+ if (record.isIntercepted()) {
+ dndKeys.add(record.sbn.getKey());
}
if (speedBumpIndex == -1 &&
- sbn.getNotification().priority == Notification.PRIORITY_MIN) {
+ record.sbn.getNotification().priority == Notification.PRIORITY_MIN) {
speedBumpIndex = keys.size() - 1;
}
}
@@ -2491,12 +2352,12 @@ public class NotificationManagerService extends SystemService {
@Override
public void onServiceAdded(ManagedServiceInfo info) {
final INotificationListener listener = (INotificationListener) info.service;
- final ArrayList<StatusBarNotification> sbns;
+ final NotificationRankingUpdate update;
synchronized (mNotificationList) {
- sbns = cloneNotificationListLocked();
+ update = makeRankingUpdateLocked(info);
}
try {
- listener.onListenerConnected(makeRankingUpdateForListener(info, sbns));
+ listener.onListenerConnected(update);
} catch (RemoteException e) {
// we tried
}
@@ -2505,15 +2366,14 @@ public class NotificationManagerService extends SystemService {
/**
* asynchronously notify all listeners about a new notification
*/
- public void notifyPostedLocked(StatusBarNotification sbn,
- final ArrayList<StatusBarNotification> sbns) {
+ public void notifyPostedLocked(StatusBarNotification sbn) {
// make a copy in case changes are made to the underlying Notification object
final StatusBarNotification sbnClone = sbn.clone();
for (final ManagedServiceInfo info : mServices) {
if (!info.isEnabledForCurrentProfiles()) {
continue;
}
- final NotificationRankingUpdate update = makeRankingUpdateForListener(info, sbns);
+ final NotificationRankingUpdate update = makeRankingUpdateLocked(info);
if (update.getOrderedKeys().length == 0) {
continue;
}
@@ -2529,8 +2389,7 @@ public class NotificationManagerService extends SystemService {
/**
* asynchronously notify all listeners about a removed notification
*/
- public void notifyRemovedLocked(StatusBarNotification sbn,
- final ArrayList<StatusBarNotification> sbns) {
+ public void notifyRemovedLocked(StatusBarNotification sbn) {
// make a copy in case changes are made to the underlying Notification object
// NOTE: this copy is lightweight: it doesn't include heavyweight parts of the
// notification
@@ -2539,11 +2398,11 @@ public class NotificationManagerService extends SystemService {
if (!info.isEnabledForCurrentProfiles()) {
continue;
}
+ final NotificationRankingUpdate update = makeRankingUpdateLocked(info);
mHandler.post(new Runnable() {
@Override
public void run() {
- notifyRemovedIfUserMatch(info, sbnLight,
- makeRankingUpdateForListener(info, sbns));
+ notifyRemovedIfUserMatch(info, sbnLight, update);
}
});
}
@@ -2551,20 +2410,18 @@ public class NotificationManagerService extends SystemService {
/**
* asynchronously notify all listeners about a reordering of notifications
- * @param sbns an array of {@link StatusBarNotification}s to consider. This code
- * must not rely on mutable members of these objects, such as the
- * {@link Notification}.
*/
- public void notifyRankingUpdateLocked(final ArrayList<StatusBarNotification> sbns) {
+ public void notifyRankingUpdateLocked() {
for (final ManagedServiceInfo serviceInfo : mServices) {
if (!serviceInfo.isEnabledForCurrentProfiles()) {
continue;
}
+ final NotificationRankingUpdate update =
+ makeRankingUpdateLocked(serviceInfo);
mHandler.post(new Runnable() {
@Override
public void run() {
- notifyRankingUpdate(serviceInfo,
- makeRankingUpdateForListener(serviceInfo, sbns));
+ notifyRankingUpdate(serviceInfo, update);
}
});
}
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
new file mode 100644
index 0000000..08f8eb4
--- /dev/null
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -0,0 +1,204 @@
+/*
+ * 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 com.android.server.notification;
+
+import android.app.Notification;
+import android.content.Context;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.service.notification.StatusBarNotification;
+
+import java.io.PrintWriter;
+import java.lang.reflect.Array;
+import java.util.Arrays;
+
+/**
+ * Holds data about notifications that should not be shared with the
+ * {@link android.service.notification.NotificationListenerService}s.
+ *
+ * <p>These objects should not be mutated unless the code is synchronized
+ * on {@link NotificationManagerService#mNotificationList}, and any
+ * modification should be followed by a sorting of that list.</p>
+ *
+ * <p>Is sortable by {@link NotificationComparator}.</p>
+ *
+ * {@hide}
+ */
+public final class NotificationRecord {
+ final StatusBarNotification sbn;
+ NotificationUsageStats.SingleNotificationStats stats;
+ boolean isCanceled;
+
+ // These members are used by NotificationSignalExtractors
+ // to communicate with the ranking module.
+ private float mContactAffinity;
+ private boolean mRecentlyIntrusive;
+
+ // is this notification currently being intercepted by Zen Mode?
+ private boolean mIntercept;
+ // InterceptedNotifications needs to know if this has been previously evaluated.
+ private boolean mTouchedByZen;
+
+ NotificationRecord(StatusBarNotification sbn)
+ {
+ this.sbn = sbn;
+ }
+
+ // copy any notes that the ranking system may have made before the update
+ public void copyRankingInformation(NotificationRecord previous) {
+ mContactAffinity = previous.mContactAffinity;
+ mRecentlyIntrusive = previous.mRecentlyIntrusive;
+ mTouchedByZen = previous.mTouchedByZen;
+ mIntercept = previous.mIntercept;
+ }
+
+ public Notification getNotification() { return sbn.getNotification(); }
+ public int getFlags() { return sbn.getNotification().flags; }
+ public int getUserId() { return sbn.getUserId(); }
+ public String getKey() { return sbn.getKey(); }
+
+ void dump(PrintWriter pw, String prefix, Context baseContext) {
+ final Notification notification = sbn.getNotification();
+ pw.println(prefix + this);
+ pw.println(prefix + " uid=" + sbn.getUid() + " userId=" + sbn.getUserId());
+ pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
+ + " / " + idDebugString(baseContext, sbn.getPackageName(), notification.icon));
+ pw.println(prefix + " pri=" + notification.priority + " score=" + sbn.getScore());
+ pw.println(prefix + " key=" + sbn.getKey());
+ pw.println(prefix + " contentIntent=" + notification.contentIntent);
+ pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
+ pw.println(prefix + " tickerText=" + notification.tickerText);
+ pw.println(prefix + " contentView=" + notification.contentView);
+ pw.println(prefix + String.format(" defaults=0x%08x flags=0x%08x",
+ notification.defaults, notification.flags));
+ pw.println(prefix + " sound=" + notification.sound);
+ pw.println(prefix + String.format(" color=0x%08x", notification.color));
+ pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
+ pw.println(prefix + String.format(" led=0x%08x onMs=%d offMs=%d",
+ notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
+ if (notification.actions != null && notification.actions.length > 0) {
+ pw.println(prefix + " actions={");
+ final int N = notification.actions.length;
+ for (int i=0; i<N; i++) {
+ final Notification.Action action = notification.actions[i];
+ pw.println(String.format("%s [%d] \"%s\" -> %s",
+ prefix,
+ i,
+ action.title,
+ action.actionIntent.toString()
+ ));
+ }
+ pw.println(prefix + " }");
+ }
+ if (notification.extras != null && notification.extras.size() > 0) {
+ pw.println(prefix + " extras={");
+ for (String key : notification.extras.keySet()) {
+ pw.print(prefix + " " + key + "=");
+ Object val = notification.extras.get(key);
+ if (val == null) {
+ pw.println("null");
+ } else {
+ pw.print(val.getClass().getSimpleName());
+ if (val instanceof CharSequence || val instanceof String) {
+ // redact contents from bugreports
+ } else if (val instanceof Bitmap) {
+ pw.print(String.format(" (%dx%d)",
+ ((Bitmap) val).getWidth(),
+ ((Bitmap) val).getHeight()));
+ } else if (val.getClass().isArray()) {
+ final int N = Array.getLength(val);
+ pw.println(" (" + N + ")");
+ } else {
+ pw.print(" (" + String.valueOf(val) + ")");
+ }
+ pw.println();
+ }
+ }
+ pw.println(prefix + " }");
+ }
+ pw.println(prefix + " stats=" + stats.toString());
+ pw.println(prefix + " mContactAffinity=" + mContactAffinity);
+ pw.println(prefix + " mRecentlyIntrusive=" + mRecentlyIntrusive);
+ pw.println(prefix + " mIntercept=" + mIntercept);
+ }
+
+
+ static String idDebugString(Context baseContext, String packageName, int id) {
+ Context c;
+
+ if (packageName != null) {
+ try {
+ c = baseContext.createPackageContext(packageName, 0);
+ } catch (NameNotFoundException e) {
+ c = baseContext;
+ }
+ } else {
+ c = baseContext;
+ }
+
+ Resources r = c.getResources();
+ try {
+ return r.getResourceName(id);
+ } catch (Resources.NotFoundException e) {
+ return "<name unknown>";
+ }
+ }
+
+ @Override
+ public final String toString() {
+ return String.format(
+ "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d key=%s: %s)",
+ System.identityHashCode(this),
+ this.sbn.getPackageName(), this.sbn.getUser(), this.sbn.getId(),
+ this.sbn.getTag(), this.sbn.getScore(), this.sbn.getKey(),
+ this.sbn.getNotification());
+ }
+
+ public void setContactAffinity(float contactAffinity) {
+ mContactAffinity = contactAffinity;
+ }
+
+ public float getContactAffinity() {
+ return mContactAffinity;
+ }
+
+ public void setRecentlyIntusive(boolean recentlyIntrusive) {
+ mRecentlyIntrusive = recentlyIntrusive;
+ }
+
+ public boolean isRecentlyIntrusive() {
+ return mRecentlyIntrusive;
+ }
+
+ public boolean setIntercepted(boolean intercept) {
+ mIntercept = intercept;
+ return mIntercept;
+ }
+
+ public boolean isIntercepted() {
+ return mIntercept;
+ }
+
+ public boolean wasTouchedByZen() {
+ return mTouchedByZen;
+ }
+
+ public void setTouchedByZen() {
+ mTouchedByZen = true;
+ }
+
+}
diff --git a/services/core/java/com/android/server/notification/NotificationSignalExtractor.java b/services/core/java/com/android/server/notification/NotificationSignalExtractor.java
index 71c819e..1537ea9 100644
--- a/services/core/java/com/android/server/notification/NotificationSignalExtractor.java
+++ b/services/core/java/com/android/server/notification/NotificationSignalExtractor.java
@@ -18,11 +18,9 @@ package com.android.server.notification;
import android.content.Context;
-import com.android.server.notification.NotificationManagerService.NotificationRecord;
-
/**
* Extracts signals that will be useful to the {@link NotificationComparator} and caches them
- * on the {@link NotificationManagerService.NotificationRecord} object. These annotations will
+ * on the {@link NotificationRecord} object. These annotations will
* not be passed on to {@link android.service.notification.NotificationListenerService}s.
*/
public interface NotificationSignalExtractor {
diff --git a/services/core/java/com/android/server/notification/NotificationUsageStats.java b/services/core/java/com/android/server/notification/NotificationUsageStats.java
index 66cc532..bab4895 100644
--- a/services/core/java/com/android/server/notification/NotificationUsageStats.java
+++ b/services/core/java/com/android/server/notification/NotificationUsageStats.java
@@ -16,8 +16,6 @@
package com.android.server.notification;
-import com.android.server.notification.NotificationManagerService.NotificationRecord;
-
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
diff --git a/services/core/java/com/android/server/notification/RankingReconsideration.java b/services/core/java/com/android/server/notification/RankingReconsideration.java
index cf5e210..057f0f1 100644
--- a/services/core/java/com/android/server/notification/RankingReconsideration.java
+++ b/services/core/java/com/android/server/notification/RankingReconsideration.java
@@ -15,8 +15,6 @@
*/
package com.android.server.notification;
-import com.android.server.notification.NotificationManagerService.NotificationRecord;
-
import java.util.concurrent.TimeUnit;
/**
diff --git a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
index a629a5f..14be9b2 100644
--- a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
+++ b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
@@ -28,8 +28,6 @@ import android.text.TextUtils;
import android.util.LruCache;
import android.util.Slog;
-import com.android.server.notification.NotificationManagerService.NotificationRecord;
-
import java.util.ArrayList;
import java.util.LinkedList;
diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java
index 154ac96..a52b706 100644
--- a/services/core/java/com/android/server/notification/ZenModeHelper.java
+++ b/services/core/java/com/android/server/notification/ZenModeHelper.java
@@ -18,7 +18,6 @@ package com.android.server.notification;
import android.app.AlarmManager;
import android.app.AppOpsManager;
-import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -123,15 +122,19 @@ public class ZenModeHelper {
mCallbacks.add(callback);
}
- public boolean shouldIntercept(String pkg, Notification n) {
+ public boolean shouldIntercept(NotificationRecord record, boolean previouslySeen) {
if (mZenMode != Global.ZEN_MODE_OFF) {
- if (isAlarm(pkg, n)) {
+ if (previouslySeen && !record.isIntercepted()) {
+ // notifications never transition from not intercepted to intercepted
return false;
}
- if (isCall(pkg, n)) {
+ if (isAlarm(record)) {
+ return false;
+ }
+ if (isCall(record)) {
return !mConfig.allowCalls;
}
- if (isMessage(pkg, n)) {
+ if (isMessage(record)) {
return !mConfig.allowMessages;
}
return true;
@@ -176,7 +179,8 @@ public class ZenModeHelper {
}
public boolean allowDisable(int what, IBinder token, String pkg) {
- if (isCall(pkg, null)) {
+ // TODO(cwren): delete this API before the next release. Bug:15344099
+ if (CALL_PACKAGES.contains(pkg)) {
return mZenMode == Global.ZEN_MODE_OFF || mConfig.allowCalls;
}
return true;
@@ -229,16 +233,16 @@ public class ZenModeHelper {
}
}
- private boolean isAlarm(String pkg, Notification n) {
- return ALARM_PACKAGES.contains(pkg);
+ private boolean isAlarm(NotificationRecord record) {
+ return ALARM_PACKAGES.contains(record.sbn.getPackageName());
}
- private boolean isCall(String pkg, Notification n) {
- return CALL_PACKAGES.contains(pkg);
+ private boolean isCall(NotificationRecord record) {
+ return CALL_PACKAGES.contains(record.sbn.getPackageName());
}
- private boolean isMessage(String pkg, Notification n) {
- return MESSAGE_PACKAGES.contains(pkg);
+ private boolean isMessage(NotificationRecord record) {
+ return MESSAGE_PACKAGES.contains(record.sbn.getPackageName());
}
private void updateAlarms() {