Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 925cde8f authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Alarms and Media visibly muted in PriorityOnly dnd

- if alarms and/or media cannot pass dnd and the phone is currently
in priority only dnd, then the alarm and/or media volume stream
will appear muted in the volume dialog and sound settings
(Settings > Sound)
- if all behavior for priority only dnd is not allowed to bypass dnd
(discluding alarms and media), then ringer is muted when priority-only
dnd mode is on. If a user clicks this ringer in the volume dialog, then
dnd ends
- Updated default zen config to version 3 (added alarms and media)
Test: manually toggle alarms + media in Settings > Sound > DND >
Behavior, toggle on/off dnd and then look at volume dialog and
volume bars in Settings > Sound
Test: runtest --path cts/tests/tests/media/src/android/media/cts/AudioManagerTest.java
Fixes: 72052742

Change-Id: Ia9e809ec2be93cb5a9ba6518dce04bf3ce45110b
parent f8fc7235
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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);
@@ -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() {
@@ -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 {
@@ -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();
            }
        }

+35 −0
Original line number Diff line number Diff line
@@ -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;
@@ -1385,4 +1386,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);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -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>
+9 −0
Original line number Diff line number Diff line
@@ -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();
@@ -113,6 +116,9 @@ public interface VolumeDialogController {
            }
            rt.effectsSuppressorName = effectsSuppressorName;
            rt.activeStream = activeStream;
            rt.disallowAlarms = disallowAlarms;
            rt.disallowMedia = disallowMedia;
            rt.disallowRinger = disallowRinger;
            return rt;
        }

@@ -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();
        }
+2 −0
Original line number Diff line number Diff line
@@ -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",
@@ -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