From 99f963ea04d7a86219ece00c356f3f6bce33b6d6 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Wed, 28 May 2014 16:52:42 -0400 Subject: Add people signals to Zen mode. Depends-On: I51fcf689ddbee7715e3387b865f18a715887c943 Change-Id: I7c91dec1afeb54505426c4da59ec4d072a60c240 --- .../notification/ValidateNotificationPeople.java | 17 ++++++++++++--- .../android/server/notification/ZenModeHelper.java | 24 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'services') diff --git a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java index 14be9b2..02f95e9 100644 --- a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java +++ b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java @@ -47,9 +47,20 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { private static final int MAX_PEOPLE = 10; private static final int PEOPLE_CACHE_SIZE = 200; - private static final float NONE = 0f; - private static final float VALID_CONTACT = 0.5f; - private static final float STARRED_CONTACT = 1f; + /** Indicates that the notification does not reference any valid contacts. */ + static final float NONE = 0f; + + /** + * Affinity will be equal to or greater than this value on notifications + * that reference a valid contact. + */ + static final float VALID_CONTACT = 0.5f; + + /** + * Affinity will be equal to or greater than this value on notifications + * that reference a starred contact. + */ + static final float STARRED_CONTACT = 1f; protected boolean mEnabled; private Context mContext; diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index a52b706..50a32c4 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -77,11 +77,13 @@ public class ZenModeHelper { // temporary, until we update apps to provide metadata private static final Set CALL_PACKAGES = new HashSet(Arrays.asList( "com.google.android.dialer", - "com.android.phone" + "com.android.phone", + "com.android.example.notificationshowcase" )); private static final Set MESSAGE_PACKAGES = new HashSet(Arrays.asList( "com.google.android.talk", - "com.android.mms" + "com.android.mms", + "com.android.example.notificationshowcase" )); private static final Set ALARM_PACKAGES = new HashSet(Arrays.asList( "com.google.android.deskclock" @@ -131,6 +133,10 @@ public class ZenModeHelper { if (isAlarm(record)) { return false; } + // audience has veto power over all following rules + if (!audienceMatches(record)) { + return true; + } if (isCall(record)) { return !mConfig.allowCalls; } @@ -245,6 +251,20 @@ public class ZenModeHelper { return MESSAGE_PACKAGES.contains(record.sbn.getPackageName()); } + private boolean audienceMatches(NotificationRecord record) { + switch (mConfig.allowFrom) { + case ZenModeConfig.SOURCE_ANYONE: + return true; + case ZenModeConfig.SOURCE_CONTACT: + return record.getContactAffinity() >= ValidateNotificationPeople.VALID_CONTACT; + case ZenModeConfig.SOURCE_STAR: + return record.getContactAffinity() >= ValidateNotificationPeople.STARRED_CONTACT; + default: + Slog.w(TAG, "Encountered unknown source: " + mConfig.allowFrom); + return true; + } + } + private void updateAlarms() { updateAlarm(ACTION_ENTER_ZEN, REQUEST_CODE_ENTER, mConfig.sleepStartHour, mConfig.sleepStartMinute); -- cgit v1.1