diff options
| author | 2016-09-14 06:30:54 +0000 | |
|---|---|---|
| committer | 2016-09-14 06:30:54 +0000 | |
| commit | d987793bd6db1557d9db8c1ccd2f18c8cc55f584 (patch) | |
| tree | 91a7478ca52ec37654ba95613cf53b6516a389b0 | |
| parent | 4d325f565c0eef885d3953be95c55fc05c2a283f (diff) | |
| parent | 06a206456afa8b2a6b223d2d3ab67ef39b3a40da (diff) | |
Fix Zen mode for different notification usage types am: e743bda5de am: 4068a641e6
am: 06a206456a
Change-Id: I5a9723affc20cf7a22fcd1e45481d98427acf947
| -rw-r--r-- | media/java/android/media/AudioAttributes.java | 61 | ||||
| -rw-r--r-- | services/core/java/com/android/server/notification/ZenModeHelper.java | 14 |
2 files changed, 69 insertions, 6 deletions
diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index 5286f8fa5ad3..89709ee6b95a 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -24,6 +24,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; +import android.util.SparseIntArray; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -170,6 +171,66 @@ public final class AudioAttributes implements Parcelable { public final static int USAGE_VIRTUAL_SOURCE = 15; /** + * IMPORTANT: when adding new usage types, add them to SDK_USAGES and update SUPPRESSIBLE_USAGES + * if applicable. + */ + + /** + * @hide + * Denotes a usage for notifications that do not expect immediate intervention from the user, + * will be muted when the Zen mode disables notifications + * @see #SUPPRESSIBLE_USAGES + */ + public final static int SUPPRESSIBLE_NOTIFICATION = 1; + /** + * @hide + * Denotes a usage for notifications that do expect immediate intervention from the user, + * will be muted when the Zen mode disables calls + * @see #SUPPRESSIBLE_USAGES + */ + public final static int SUPPRESSIBLE_CALL = 2; + + /** + * @hide + * Array of all usage types for calls and notifications to assign the suppression behavior, + * used by the Zen mode restrictions. + * @see com.android.server.notification.ZenModeHelper + */ + public static final SparseIntArray SUPPRESSIBLE_USAGES; + + static { + SUPPRESSIBLE_USAGES = new SparseIntArray(); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION, SUPPRESSIBLE_NOTIFICATION); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION_RINGTONE, SUPPRESSIBLE_CALL); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION_COMMUNICATION_REQUEST,SUPPRESSIBLE_CALL); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION_COMMUNICATION_INSTANT,SUPPRESSIBLE_NOTIFICATION); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION_COMMUNICATION_DELAYED,SUPPRESSIBLE_NOTIFICATION); + SUPPRESSIBLE_USAGES.put(USAGE_NOTIFICATION_EVENT, SUPPRESSIBLE_NOTIFICATION); + } + + /** + * @hide + * Array of all usage types exposed in the SDK that applications can use. + */ + public final static int[] SDK_USAGES = { + USAGE_UNKNOWN, + USAGE_MEDIA, + USAGE_VOICE_COMMUNICATION, + USAGE_VOICE_COMMUNICATION_SIGNALLING, + USAGE_ALARM, + USAGE_NOTIFICATION, + USAGE_NOTIFICATION_RINGTONE, + USAGE_NOTIFICATION_COMMUNICATION_REQUEST, + USAGE_NOTIFICATION_COMMUNICATION_INSTANT, + USAGE_NOTIFICATION_COMMUNICATION_DELAYED, + USAGE_NOTIFICATION_EVENT, + USAGE_ASSISTANCE_ACCESSIBILITY, + USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, + USAGE_ASSISTANCE_SONIFICATION, + USAGE_GAME + }; + + /** * Flag defining a behavior where the audibility of the sound will be ensured by the system. */ public final static int FLAG_AUDIBILITY_ENFORCED = 0x1 << 0; diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 4393761f4774..629e838e614c 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -35,6 +35,7 @@ import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.database.ContentObserver; +import android.media.AudioAttributes; import android.media.AudioManager; import android.media.AudioManagerInternal; import android.media.AudioSystem; @@ -736,13 +737,14 @@ public class ZenModeHelper { // total silence restrictions final boolean muteEverything = mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; - for (int i = USAGE_UNKNOWN; i <= USAGE_VIRTUAL_SOURCE; i++) { - if (i == USAGE_NOTIFICATION) { - applyRestrictions(muteNotifications || muteEverything, i); - } else if (i == USAGE_NOTIFICATION_RINGTONE) { - applyRestrictions(muteCalls || muteEverything, i); + for (int usage : AudioAttributes.SDK_USAGES) { + final int suppressionBehavior = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage); + if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NOTIFICATION) { + applyRestrictions(muteNotifications || muteEverything, usage); + } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_CALL) { + applyRestrictions(muteCalls || muteEverything, usage); } else { - applyRestrictions(muteEverything, i); + applyRestrictions(muteEverything, usage); } } } |