diff options
author | John Spurlock <jspurlock@google.com> | 2014-06-01 11:52:23 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2014-06-01 11:52:23 -0400 |
commit | a11b4affcad3d255aa723a89b768ea222506f2e8 (patch) | |
tree | 44b0ebdd49385b80937ce006cf7435e08c258bb6 /media | |
parent | d1c86e2cb272f8b8be5b9b47aa4ec7084fe61c22 (diff) | |
download | frameworks_base-a11b4affcad3d255aa723a89b768ea222506f2e8.zip frameworks_base-a11b4affcad3d255aa723a89b768ea222506f2e8.tar.gz frameworks_base-a11b4affcad3d255aa723a89b768ea222506f2e8.tar.bz2 |
VolumeZen: Prevent raising ringer volume in silent mode.
Instead of breaking out of silent mode when raising the volume
using the keys, prevent the change and display a visual hint up
in the user interface.
Bug:15330217
Change-Id: I74aae44319aadcd6db9841c7799967607f5a1617
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioManager.java | 6 | ||||
-rw-r--r-- | media/java/android/media/AudioService.java | 35 |
2 files changed, 32 insertions, 9 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 2f8a17b..249b116 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -339,6 +339,12 @@ public class AudioManager { public static final int FLAG_BLUETOOTH_ABS_VOLUME = 1 << 6; /** + * Adjusting the volume was prevented due to silent mode, display a hint in the UI. + * @hide + */ + public static final int FLAG_SHOW_SILENT_HINT = 1 << 7; + + /** * Ringer mode that will be silent and will not vibrate. (This overrides the * vibrate setting.) * diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 5b620fd..fd346d5 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -115,6 +115,9 @@ public class AudioService extends IAudioService.Stub { /** Allow volume changes to set ringer mode to silent? */ private static final boolean VOLUME_SETS_RINGER_MODE_SILENT = false; + /** In silent mode, are volume adjustments (raises) prevented? */ + private static final boolean PREVENT_VOLUME_ADJUSTMENT_IF_SILENT = true; + /** How long to delay before persisting a change in volume/ringer mode. */ private static final int PERSIST_DELAY = 500; @@ -126,6 +129,11 @@ public class AudioService extends IAudioService.Stub { */ public static final int PLAY_SOUND_DELAY = 300; + /** + * Only used in the result from {@link #checkForRingerModeChange(int, int, int)} + */ + private static final int FLAG_ADJUST_VOLUME = 1; + private final Context mContext; private final ContentResolver mContentResolver; private final AppOpsManager mAppOps; @@ -941,7 +949,12 @@ public class AudioService extends IAudioService.Stub { } // Check if the ringer mode changes with this volume adjustment. If // it does, it will handle adjusting the volume, so we won't below - adjustVolume = checkForRingerModeChange(aliasIndex, direction, step); + final int result = checkForRingerModeChange(aliasIndex, direction, step); + adjustVolume = (result & FLAG_ADJUST_VOLUME) != 0; + // If suppressing a volume adjustment in silent mode, display the UI hint + if ((result & AudioManager.FLAG_SHOW_SILENT_HINT) != 0) { + flags |= AudioManager.FLAG_SHOW_SILENT_HINT; + } } int oldIndex = mStreamStates[streamType].getIndex(device); @@ -2538,8 +2551,8 @@ public class AudioService extends IAudioService.Stub { * adjusting volume. If so, this will set the proper ringer mode and volume * indices on the stream states. */ - private boolean checkForRingerModeChange(int oldIndex, int direction, int step) { - boolean adjustVolumeIndex = true; + private int checkForRingerModeChange(int oldIndex, int direction, int step) { + int result = FLAG_ADJUST_VOLUME; int ringerMode = getRingerMode(); switch (ringerMode) { @@ -2578,17 +2591,21 @@ public class AudioService extends IAudioService.Stub { } else if (direction == AudioManager.ADJUST_RAISE) { ringerMode = RINGER_MODE_NORMAL; } - adjustVolumeIndex = false; + result &= ~FLAG_ADJUST_VOLUME; break; case RINGER_MODE_SILENT: if (direction == AudioManager.ADJUST_RAISE) { - if (mHasVibrator) { - ringerMode = RINGER_MODE_VIBRATE; + if (PREVENT_VOLUME_ADJUSTMENT_IF_SILENT) { + result |= AudioManager.FLAG_SHOW_SILENT_HINT; } else { - ringerMode = RINGER_MODE_NORMAL; + if (mHasVibrator) { + ringerMode = RINGER_MODE_VIBRATE; + } else { + ringerMode = RINGER_MODE_NORMAL; + } } } - adjustVolumeIndex = false; + result &= ~FLAG_ADJUST_VOLUME; break; default: Log.e(TAG, "checkForRingerModeChange() wrong ringer mode: "+ringerMode); @@ -2599,7 +2616,7 @@ public class AudioService extends IAudioService.Stub { mPrevVolDirection = direction; - return adjustVolumeIndex; + return result; } @Override |