summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Wren <cwren@android.com> 2014-05-14 19:30:12 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2014-05-14 19:30:13 +0000
commit154f8283656d6c879a568fe4be19286dbb2c7121 (patch)
treebe96730a78f74f5e7f324b592c8d09e9304510cc
parent9e317da9364bae6a7d40c94cd46748b2255c7e1e (diff)
parent5190c0fefac9923931b5c1c02cab2d00c2d6b82b (diff)
Merge "Add intrusiveness signal extractor."
-rw-r--r--core/res/res/values/config.xml3
-rw-r--r--services/core/java/com/android/server/notification/NotificationComparator.java3
-rw-r--r--services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java64
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java12
-rw-r--r--services/core/java/com/android/server/notification/RankingFuture.java4
5 files changed, 83 insertions, 3 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 83cbb74a0ebf..f5117b2576ad 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1394,9 +1394,10 @@
</string-array>
<!-- The list of classes that should be added to the notification ranking pipline.
- See {@link com.android.server.notification.NotificationSignalExtractortor} -->
+ See {@link com.android.server.notification.NotificationSignalExtractor} -->
<string-array name="config_notificationSignalExtractors">
<item>com.android.server.notification.ValidateNotificationPeople</item>
+ <item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
</string-array>
<!-- Flag indicating that this device does not rotate and will always remain in its default
diff --git a/services/core/java/com/android/server/notification/NotificationComparator.java b/services/core/java/com/android/server/notification/NotificationComparator.java
index c8b1ba06d7b0..49293d325810 100644
--- a/services/core/java/com/android/server/notification/NotificationComparator.java
+++ b/services/core/java/com/android/server/notification/NotificationComparator.java
@@ -26,6 +26,9 @@ public class NotificationComparator
@Override
public int compare(NotificationManagerService.NotificationRecord lhs,
NotificationManagerService.NotificationRecord rhs) {
+ if (lhs.isRecentlyIntrusive() != rhs.isRecentlyIntrusive()) {
+ return lhs.isRecentlyIntrusive() ? -1 : 1;
+ }
final int leftScore = lhs.sbn.getScore();
final int rightScore = rhs.sbn.getScore();
if (leftScore != rightScore) {
diff --git a/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java b/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java
new file mode 100644
index 000000000000..125158fd1098
--- /dev/null
+++ b/services/core/java/com/android/server/notification/NotificationIntrusivenessExtractor.java
@@ -0,0 +1,64 @@
+/*
+* 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.util.Slog;
+
+import com.android.internal.R;
+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.
+ */
+public class NotificationIntrusivenessExtractor implements NotificationSignalExtractor {
+ private static final String TAG = "NotificationNoiseExtractor";
+ private static final boolean DBG = false;
+
+ /** Length of time (in milliseconds) that an intrusive or noisy notification will stay at
+ the top of the ranking order, before it falls back to its natural position. */
+ private static final long HANG_TIME_MS = 10000;
+
+ public void initialize(Context ctx) {
+ if (DBG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + ".");
+ }
+
+ public RankingFuture process(NotificationRecord record) {
+ if (record == null || record.getNotification() == null) {
+ if (DBG) Slog.d(TAG, "skipping empty notification");
+ return null;
+ }
+
+ final Notification notification = record.getNotification();
+ if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 ||
+ notification.vibrate != null ||
+ (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
+ notification.sound != null ||
+ notification.fullScreenIntent != null) {
+ record.setRecentlyIntusive(true);
+ }
+
+ return new RankingFuture(record, HANG_TIME_MS) {
+ @Override
+ public void work() {
+ mRecord.setRecentlyIntusive(false);
+ }
+ };
+ }
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index f1c05ace8430..2f1d29196692 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -457,7 +457,11 @@ public class NotificationManagerService extends SystemService {
final StatusBarNotification sbn;
SingleNotificationStats stats;
IBinder statusBarKey;
+
+ // These members are used by NotificationSignalExtractors
+ // to communicate with the ranking module.
private float mContactAffinity;
+ private boolean mRecentlyIntrusive;
NotificationRecord(StatusBarNotification sbn)
{
@@ -548,6 +552,14 @@ public class NotificationManagerService extends SystemService {
public float getContactAffinity() {
return mContactAffinity;
}
+
+ public boolean isRecentlyIntrusive() {
+ return mRecentlyIntrusive;
+ }
+
+ public void setRecentlyIntusive(boolean recentlyIntrusive) {
+ mRecentlyIntrusive = recentlyIntrusive;
+ }
}
private static final class ToastRecord
diff --git a/services/core/java/com/android/server/notification/RankingFuture.java b/services/core/java/com/android/server/notification/RankingFuture.java
index 33aad8d88227..d711d0270444 100644
--- a/services/core/java/com/android/server/notification/RankingFuture.java
+++ b/services/core/java/com/android/server/notification/RankingFuture.java
@@ -64,8 +64,8 @@ public abstract class RankingFuture
@Override
public int compareTo(Delayed another) {
- return Long.compare(getDelay(TimeUnit.MICROSECONDS),
- another.getDelay(TimeUnit.MICROSECONDS));
+ return Long.compare(getDelay(TimeUnit.MILLISECONDS),
+ another.getDelay(TimeUnit.MILLISECONDS));
}
@Override