diff options
| author | 2023-11-16 02:14:06 -0800 | |
|---|---|---|
| committer | 2023-12-18 23:33:15 +0000 | |
| commit | 142f0a608fa22cbc5eb30ccac3970a19ba2f66a1 (patch) | |
| tree | 1084bf169110fb97484119d6589cb06e3c7bd533 | |
| parent | 42f9b0d574f41c8bf76a762aeeba66bef41b367b (diff) | |
Support for ringer mode to affect alarm stream
Bug: 315521463
Test: Enable "Mute alarm" and "Mute ring" settings, Alarm volume should
be muted.
Change-Id: I55abc7df42e221b9f011dd166591395e770b2fb0
7 files changed, 38 insertions, 1 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 9c27f19b349a..a47db363e470 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -14308,6 +14308,14 @@ public final class Settings { public static final String MODE_RINGER = "mode_ringer"; /** + * Whether or not Alarm stream should always be muted with Ringer. + * + * @hide + */ + public static final String MUTE_ALARM_STREAM_WITH_RINGER_MODE = + "mute_alarm_stream_with_ringer_mode"; + + /** * Overlay display devices setting. * The associated value is a specially formatted string that describes the * size and density of simulated secondary display devices. diff --git a/core/proto/android/providers/settings/global.proto b/core/proto/android/providers/settings/global.proto index 052e2f20a313..d3f3af738273 100644 --- a/core/proto/android/providers/settings/global.proto +++ b/core/proto/android/providers/settings/global.proto @@ -610,6 +610,9 @@ message GlobalSettingsProto { // ringer mode. optional SettingProto mode_ringer = 75 [ (android.privacy).dest = DEST_AUTOMATIC ]; + // This is an optional feature where ringer mode affects alarm stream as well + optional SettingProto mute_alarm_stream_with_ringer_mode = 160 [ (android.privacy).dest = DEST_AUTOMATIC ]; + reserved 147; // Used to be apply_ramping_ringer message MultiSim { @@ -1086,5 +1089,5 @@ message GlobalSettingsProto { // Please insert fields in alphabetical order and group them into messages // if possible (to avoid reaching the method limit). - // Next tag = 160; + // Next tag = 161; } diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 387a1083c6d6..2ffd5c6ce925 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2262,6 +2262,9 @@ <!-- The default min volume for the alarm stream --> <integer name="config_audio_alarm_min_vol">1</integer> + <!-- Flag indicating if ringer mode affects alarm stream --> + <bool name="config_audio_ringer_mode_affects_alarm_stream">false</bool> + <!-- The default value for whether head tracking for spatial audio is enabled for a newly connected audio device --> <bool name="config_spatial_audio_head_tracking_enabled_default">false</bool> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index a5b102836816..8f346a17f5df 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -288,6 +288,7 @@ <java-symbol type="integer" name="config_audio_ring_vol_default" /> <java-symbol type="integer" name="config_audio_ring_vol_steps" /> <java-symbol type="integer" name="config_audio_alarm_min_vol" /> + <java-symbol type="bool" name="config_audio_ringer_mode_affects_alarm_stream" /> <java-symbol type="bool" name="config_spatial_audio_head_tracking_enabled_default" /> <java-symbol type="bool" name="config_avoidGfxAccel" /> <java-symbol type="bool" name="config_bluetooth_address_validation" /> diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java index d9fe7335dbcb..3027c5f91db5 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/GlobalSettingsValidators.java @@ -209,6 +209,7 @@ public class GlobalSettingsValidators { VALIDATORS.put(Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, NONE_NEGATIVE_LONG_VALIDATOR); VALIDATORS.put(Global.STYLUS_EVER_USED, BOOLEAN_VALIDATOR); + VALIDATORS.put(Global.MUTE_ALARM_STREAM_WITH_RINGER_MODE, BOOLEAN_VALIDATOR); VALIDATORS.put(Global.Wearable.HAS_PAY_TOKENS, BOOLEAN_VALIDATOR); VALIDATORS.put(Global.Wearable.GMS_CHECKIN_TIMEOUT_MIN, ANY_INTEGER_VALIDATOR); diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index 85e87691ac85..6ad10cc8cc5b 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -350,6 +350,7 @@ public class SettingsBackupTest { Settings.Global.DSRM_DURATION_MILLIS, Settings.Global.DSRM_ENABLED_ACTIONS, Settings.Global.MODE_RINGER, + Settings.Global.MUTE_ALARM_STREAM_WITH_RINGER_MODE, Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, Settings.Global.MULTI_SIM_SMS_PROMPT, Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION, diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 44cb1367928d..06435979ba91 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -43,6 +43,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK import static com.android.media.audio.Flags.alarmMinVolumeZero; import static com.android.media.audio.Flags.bluetoothMacAddressAnonymization; import static com.android.media.audio.Flags.disablePrescaleAbsoluteVolume; +import static com.android.media.audio.Flags.ringerModeAffectsAlarm; import static com.android.server.audio.SoundDoseHelper.ACTION_CHECK_MUSIC_ACTIVE; import static com.android.server.utils.EventLogger.Event.ALOGE; import static com.android.server.utils.EventLogger.Event.ALOGI; @@ -605,6 +606,7 @@ public class AudioService extends IAudioService.Stub }; private final boolean mUseFixedVolume; + private final boolean mRingerModeAffectsAlarm; private final boolean mUseVolumeGroupAliases; // If absolute volume is supported in AVRCP device @@ -1298,6 +1300,9 @@ public class AudioService extends IAudioService.Stub mUseFixedVolume = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useFixedVolume); + mRingerModeAffectsAlarm = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_audio_ringer_mode_affects_alarm_stream); + mRecordMonitor = new RecordingActivityMonitor(mContext); mRecordMonitor.registerRecordingCallback(mVoiceRecordingActivityMonitor, true); @@ -7015,6 +7020,19 @@ public class AudioService extends IAudioService.Stub ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_DTMF); } + if (ringerModeAffectsAlarm()) { + if (mRingerModeAffectsAlarm) { + boolean muteAlarmWithRinger = + mSettings.getGlobalInt(mContentResolver, + Settings.Global.MUTE_ALARM_STREAM_WITH_RINGER_MODE, + /* def= */ 0) != 0; + if (muteAlarmWithRinger) { + ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_ALARM); + } else { + ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_ALARM); + } + } + } if (ringerModeAffectedStreams != mRingerModeAffectedStreams) { mSettings.putSystemIntForUser(mContentResolver, Settings.System.MODE_RINGER_STREAMS_AFFECTED, @@ -9674,6 +9692,8 @@ public class AudioService extends IAudioService.Stub Settings.Global.ZEN_MODE), false, this); mContentResolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.ZEN_MODE_CONFIG_ETAG), false, this); + mContentResolver.registerContentObserver(Settings.Global.getUriFor( + Settings.Global.MUTE_ALARM_STREAM_WITH_RINGER_MODE), false, this); mContentResolver.registerContentObserver(Settings.System.getUriFor( Settings.System.MODE_RINGER_STREAMS_AFFECTED), false, this); mContentResolver.registerContentObserver(Settings.Global.getUriFor( |