Loading core/java/android/preference/SeekBarVolumizer.java +36 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.preference.VolumePreference.VolumeStore; import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.System; import android.service.notification.ZenModeConfig; import android.util.Log; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; Loading Loading @@ -87,10 +88,22 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private static final int MSG_INIT_SAMPLE = 3; private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000; private NotificationManager.Policy mNotificationPolicy; private boolean mAllowAlarms; private boolean mAllowMediaSystem; private boolean mAllowRinger; public SeekBarVolumizer(Context context, int streamType, Uri defaultUri, Callback callback) { mContext = context; mAudioManager = context.getSystemService(AudioManager.class); mNotificationManager = context.getSystemService(NotificationManager.class); mNotificationPolicy = mNotificationManager.getNotificationPolicy(); mAllowAlarms = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_ALARMS) != 0; mAllowMediaSystem = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) != 0; mAllowRinger = !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted( mNotificationPolicy); mStreamType = streamType; mAffectedByRingerMode = mAudioManager.isStreamAffectedByRingerMode(mStreamType); mNotificationOrRing = isNotificationOrRing(mStreamType); Loading Loading @@ -122,6 +135,14 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba return stream == AudioManager.STREAM_RING || stream == AudioManager.STREAM_NOTIFICATION; } private static boolean isAlarmsStream(int stream) { return stream == AudioManager.STREAM_ALARM; } private static boolean isMediaOrSystemStream(int stream) { return stream == AudioManager.STREAM_MUSIC || stream == AudioManager.STREAM_SYSTEM; } public void setSeekBar(SeekBar seekBar) { if (mSeekBar != null) { mSeekBar.setOnSeekBarChangeListener(null); Loading @@ -135,7 +156,11 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private boolean isZenMuted() { return mNotificationOrRing && mZenMode == Global.ZEN_MODE_ALARMS || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS && ((!mAllowAlarms && isAlarmsStream(mStreamType)) || (!mAllowMediaSystem && isMediaOrSystemStream(mStreamType)) || (!mAllowRinger && isNotificationOrRing(mStreamType)))); } protected void updateSeekBar() { Loading Loading @@ -396,6 +421,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba final IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION); filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED); filter.addAction(NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED); filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION); mContext.registerReceiver(this, filter); } else { Loading Loading @@ -424,6 +450,15 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba } else if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED.equals(action)) { mZenMode = mNotificationManager.getZenMode(); updateSlider(); } else if (NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED.equals(action)) { mNotificationPolicy = mNotificationManager.getNotificationPolicy(); mAllowAlarms = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_ALARMS) != 0; mAllowMediaSystem = (mNotificationPolicy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) != 0; mAllowRinger = !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted( mNotificationPolicy); updateSlider(); } } Loading core/java/android/service/notification/ZenModeConfig.java +35 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.service.notification; import android.app.ActivityManager; import android.app.NotificationManager; import android.app.NotificationManager.Policy; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -1410,4 +1411,38 @@ public class ZenModeConfig implements Parcelable { } } /** * Determines whether dnd behavior should mute all notification sounds */ public static boolean areAllPriorityOnlyNotificationZenSoundsMuted(NotificationManager.Policy policy) { boolean allowReminders = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS) != 0; boolean allowCalls = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_CALLS) != 0; boolean allowMessages = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES) != 0; boolean allowEvents = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS) != 0; boolean allowRepeatCallers = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; return !allowReminders && !allowCalls && !allowMessages && !allowEvents && !allowRepeatCallers; } /** * Determines whether dnd behavior should mute all notification sounds */ public static boolean areAllPriorityOnlyNotificationZenSoundsMuted(ZenModeConfig config) { return !config.allowReminders && !config.allowCalls && !config.allowMessages && !config.allowEvents && !config.allowRepeatCallers; } /** * Determines whether all dnd mutes all sounds */ public static boolean areAllZenBehaviorSoundsMuted(ZenModeConfig config) { return !config.allowAlarms && !config.allowMediaSystemOther && areAllPriorityOnlyNotificationZenSoundsMuted(config); } } core/res/res/xml/default_zen_mode_config.xml +2 −1 Original line number Diff line number Diff line Loading @@ -19,5 +19,6 @@ <!-- Default configuration for zen mode. See android.service.notification.ZenModeConfig. --> <zen version="2"> <allow alarms="true" media_system_other="true" calls="false" messages="false" reminders="false" events="false" /> <allow alarms="true" media_system_other="true" calls="false" messages="false" reminders="false" events="false" /> </zen> packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java +9 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,9 @@ public interface VolumeDialogController { public ComponentName effectsSuppressor; public String effectsSuppressorName; public int activeStream = NO_ACTIVE_STREAM; public boolean disallowAlarms; public boolean disallowMedia; public boolean disallowRinger; public State copy() { final State rt = new State(); Loading @@ -113,6 +116,9 @@ public interface VolumeDialogController { } rt.effectsSuppressorName = effectsSuppressorName; rt.activeStream = activeStream; rt.disallowAlarms = disallowAlarms; rt.disallowMedia = disallowMedia; rt.disallowRinger = disallowRinger; return rt; } Loading Loading @@ -142,6 +148,9 @@ public interface VolumeDialogController { sep(sb, indent); sb.append("effectsSuppressor:").append(effectsSuppressor); sep(sb, indent); sb.append("effectsSuppressorName:").append(effectsSuppressorName); sep(sb, indent); sb.append("activeStream:").append(activeStream); sep(sb, indent); sb.append("disallowAlarms:").append(disallowAlarms); sep(sb, indent); sb.append("disallowMedia:").append(disallowMedia); sep(sb, indent); sb.append("disallowRinger:").append(disallowRinger); if (indent > 0) sep(sb, indent); return sb.append('}').toString(); } Loading packages/SystemUI/src/com/android/systemui/volume/Events.java +2 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class Events { public static final int EVENT_SUPPRESSOR_CHANGED = 14; // (component|string) (name|string) public static final int EVENT_MUTE_CHANGED = 15; // (stream|int) (muted|bool) public static final int EVENT_TOUCH_LEVEL_DONE = 16; // (stream|int) (level|bool) public static final int EVENT_ZEN_CONFIG_CHANGED = 17; // (allow/disallow|string) private static final String[] EVENT_TAGS = { "show_dialog", Loading @@ -70,6 +71,7 @@ public class Events { "suppressor_changed", "mute_changed", "touch_level_done", "zen_mode_config_changed", }; public static final int DISMISS_REASON_UNKNOWN = 0; Loading Loading
core/java/android/preference/SeekBarVolumizer.java +36 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.preference.VolumePreference.VolumeStore; import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.System; import android.service.notification.ZenModeConfig; import android.util.Log; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; Loading Loading @@ -87,10 +88,22 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private static final int MSG_INIT_SAMPLE = 3; private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000; private NotificationManager.Policy mNotificationPolicy; private boolean mAllowAlarms; private boolean mAllowMediaSystem; private boolean mAllowRinger; public SeekBarVolumizer(Context context, int streamType, Uri defaultUri, Callback callback) { mContext = context; mAudioManager = context.getSystemService(AudioManager.class); mNotificationManager = context.getSystemService(NotificationManager.class); mNotificationPolicy = mNotificationManager.getNotificationPolicy(); mAllowAlarms = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_ALARMS) != 0; mAllowMediaSystem = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) != 0; mAllowRinger = !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted( mNotificationPolicy); mStreamType = streamType; mAffectedByRingerMode = mAudioManager.isStreamAffectedByRingerMode(mStreamType); mNotificationOrRing = isNotificationOrRing(mStreamType); Loading Loading @@ -122,6 +135,14 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba return stream == AudioManager.STREAM_RING || stream == AudioManager.STREAM_NOTIFICATION; } private static boolean isAlarmsStream(int stream) { return stream == AudioManager.STREAM_ALARM; } private static boolean isMediaOrSystemStream(int stream) { return stream == AudioManager.STREAM_MUSIC || stream == AudioManager.STREAM_SYSTEM; } public void setSeekBar(SeekBar seekBar) { if (mSeekBar != null) { mSeekBar.setOnSeekBarChangeListener(null); Loading @@ -135,7 +156,11 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private boolean isZenMuted() { return mNotificationOrRing && mZenMode == Global.ZEN_MODE_ALARMS || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS && ((!mAllowAlarms && isAlarmsStream(mStreamType)) || (!mAllowMediaSystem && isMediaOrSystemStream(mStreamType)) || (!mAllowRinger && isNotificationOrRing(mStreamType)))); } protected void updateSeekBar() { Loading Loading @@ -396,6 +421,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba final IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION); filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED); filter.addAction(NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED); filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION); mContext.registerReceiver(this, filter); } else { Loading Loading @@ -424,6 +450,15 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba } else if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED.equals(action)) { mZenMode = mNotificationManager.getZenMode(); updateSlider(); } else if (NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED.equals(action)) { mNotificationPolicy = mNotificationManager.getNotificationPolicy(); mAllowAlarms = (mNotificationPolicy.priorityCategories & NotificationManager.Policy .PRIORITY_CATEGORY_ALARMS) != 0; mAllowMediaSystem = (mNotificationPolicy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) != 0; mAllowRinger = !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted( mNotificationPolicy); updateSlider(); } } Loading
core/java/android/service/notification/ZenModeConfig.java +35 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.service.notification; import android.app.ActivityManager; import android.app.NotificationManager; import android.app.NotificationManager.Policy; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -1410,4 +1411,38 @@ public class ZenModeConfig implements Parcelable { } } /** * Determines whether dnd behavior should mute all notification sounds */ public static boolean areAllPriorityOnlyNotificationZenSoundsMuted(NotificationManager.Policy policy) { boolean allowReminders = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS) != 0; boolean allowCalls = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_CALLS) != 0; boolean allowMessages = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES) != 0; boolean allowEvents = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS) != 0; boolean allowRepeatCallers = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; return !allowReminders && !allowCalls && !allowMessages && !allowEvents && !allowRepeatCallers; } /** * Determines whether dnd behavior should mute all notification sounds */ public static boolean areAllPriorityOnlyNotificationZenSoundsMuted(ZenModeConfig config) { return !config.allowReminders && !config.allowCalls && !config.allowMessages && !config.allowEvents && !config.allowRepeatCallers; } /** * Determines whether all dnd mutes all sounds */ public static boolean areAllZenBehaviorSoundsMuted(ZenModeConfig config) { return !config.allowAlarms && !config.allowMediaSystemOther && areAllPriorityOnlyNotificationZenSoundsMuted(config); } }
core/res/res/xml/default_zen_mode_config.xml +2 −1 Original line number Diff line number Diff line Loading @@ -19,5 +19,6 @@ <!-- Default configuration for zen mode. See android.service.notification.ZenModeConfig. --> <zen version="2"> <allow alarms="true" media_system_other="true" calls="false" messages="false" reminders="false" events="false" /> <allow alarms="true" media_system_other="true" calls="false" messages="false" reminders="false" events="false" /> </zen>
packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java +9 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,9 @@ public interface VolumeDialogController { public ComponentName effectsSuppressor; public String effectsSuppressorName; public int activeStream = NO_ACTIVE_STREAM; public boolean disallowAlarms; public boolean disallowMedia; public boolean disallowRinger; public State copy() { final State rt = new State(); Loading @@ -113,6 +116,9 @@ public interface VolumeDialogController { } rt.effectsSuppressorName = effectsSuppressorName; rt.activeStream = activeStream; rt.disallowAlarms = disallowAlarms; rt.disallowMedia = disallowMedia; rt.disallowRinger = disallowRinger; return rt; } Loading Loading @@ -142,6 +148,9 @@ public interface VolumeDialogController { sep(sb, indent); sb.append("effectsSuppressor:").append(effectsSuppressor); sep(sb, indent); sb.append("effectsSuppressorName:").append(effectsSuppressorName); sep(sb, indent); sb.append("activeStream:").append(activeStream); sep(sb, indent); sb.append("disallowAlarms:").append(disallowAlarms); sep(sb, indent); sb.append("disallowMedia:").append(disallowMedia); sep(sb, indent); sb.append("disallowRinger:").append(disallowRinger); if (indent > 0) sep(sb, indent); return sb.append('}').toString(); } Loading
packages/SystemUI/src/com/android/systemui/volume/Events.java +2 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class Events { public static final int EVENT_SUPPRESSOR_CHANGED = 14; // (component|string) (name|string) public static final int EVENT_MUTE_CHANGED = 15; // (stream|int) (muted|bool) public static final int EVENT_TOUCH_LEVEL_DONE = 16; // (stream|int) (level|bool) public static final int EVENT_ZEN_CONFIG_CHANGED = 17; // (allow/disallow|string) private static final String[] EVENT_TAGS = { "show_dialog", Loading @@ -70,6 +71,7 @@ public class Events { "suppressor_changed", "mute_changed", "touch_level_done", "zen_mode_config_changed", }; public static final int DISMISS_REASON_UNKNOWN = 0; Loading