Add streamlined config-based path for no volume key sounds
This lets us avoid a Binder roundtrip to the system process during volume changes. Previously volume change would be staged at key-down, then applied at key up in tandem with playback of the sonic feedback about volume key presses. The reason for this two-stage handling was to defer playback of the sound [at the target volume] while the volume key was being held for repeat. On some devices volume is always sent as key down/up pairs rather than down-repeat-up sequences. On these devices it is more efficient to apply the new volume immediately during down handling, and have the up handling be a no-op. This CL adds a configuration resource item selecting this new fast path. Bug 6433943 Change-Id: Icffa56e958243b841d514e2fe4609ba3a7b20f14
This commit is contained in:
@@ -65,6 +65,11 @@
|
||||
master volume stream and nothing else . -->
|
||||
<bool name="config_useMasterVolume">false</bool>
|
||||
|
||||
<!-- Flag indicating that the media framework should support playing of sounds on volume
|
||||
key usage. This adds noticeable additional overhead to volume key processing, so
|
||||
is disableable for products for which it is irrelevant. -->
|
||||
<bool name="config_useVolumeKeySounds">true</bool>
|
||||
|
||||
<!-- Array of integer pairs controlling the rate at which the master volume changes
|
||||
in response to volume up and down key events.
|
||||
The first integer of each pair is compared against the current master volume
|
||||
|
||||
@@ -53,6 +53,7 @@ public class AudioManager {
|
||||
private long mVolumeKeyUpTime;
|
||||
private int mVolumeControlStream = -1;
|
||||
private final boolean mUseMasterVolume;
|
||||
private final boolean mUseVolumeKeySounds;
|
||||
private static String TAG = "AudioManager";
|
||||
private static boolean localLOGV = false;
|
||||
|
||||
@@ -406,6 +407,8 @@ public class AudioManager {
|
||||
mHandler = new Handler(context.getMainLooper());
|
||||
mUseMasterVolume = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_useMasterVolume);
|
||||
mUseVolumeKeySounds = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_useVolumeKeySounds);
|
||||
}
|
||||
|
||||
private static IAudioService getService()
|
||||
@@ -457,6 +460,9 @@ public class AudioManager {
|
||||
* responsive to the user.
|
||||
*/
|
||||
int flags = FLAG_SHOW_UI | FLAG_VIBRATE;
|
||||
// if there is no volume key-up sound, apply the new volume immediately
|
||||
if (!mUseVolumeKeySounds) flags |= FLAG_PLAY_SOUND;
|
||||
|
||||
if (mUseMasterVolume) {
|
||||
adjustMasterVolume(
|
||||
keyCode == KeyEvent.KEYCODE_VOLUME_UP
|
||||
@@ -500,22 +506,23 @@ public class AudioManager {
|
||||
* Play a sound. This is done on key up since we don't want the
|
||||
* sound to play when a user holds down volume down to mute.
|
||||
*/
|
||||
if (mUseMasterVolume) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
|
||||
if (mUseVolumeKeySounds) {
|
||||
if (mUseMasterVolume) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
|
||||
}
|
||||
} else {
|
||||
int flags = FLAG_PLAY_SOUND;
|
||||
if (mVolumeControlStream != -1) {
|
||||
stream = mVolumeControlStream;
|
||||
flags |= FLAG_FORCE_STREAM;
|
||||
}
|
||||
adjustSuggestedStreamVolume(
|
||||
ADJUST_SAME,
|
||||
stream,
|
||||
flags);
|
||||
}
|
||||
} else {
|
||||
int flags = FLAG_PLAY_SOUND;
|
||||
if (mVolumeControlStream != -1) {
|
||||
stream = mVolumeControlStream;
|
||||
flags |= FLAG_FORCE_STREAM;
|
||||
}
|
||||
adjustSuggestedStreamVolume(
|
||||
ADJUST_SAME,
|
||||
stream,
|
||||
flags);
|
||||
}
|
||||
|
||||
mVolumeKeyUpTime = SystemClock.uptimeMillis();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user