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

Commit b89ce434 authored by Christopher Tate's avatar Christopher Tate
Browse files

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
parent e7d85994
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+21 −14
Original line number Diff line number Diff line
@@ -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,6 +506,7 @@ 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 (mUseVolumeKeySounds) {
                    if (mUseMasterVolume) {
                        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                            adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
@@ -515,7 +522,7 @@ public class AudioManager {
                                stream,
                                flags);
                    }

                }
                mVolumeKeyUpTime = SystemClock.uptimeMillis();
                break;
        }