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

Commit fccf3d39 authored by Sal Savage's avatar Sal Savage Committed by Joseph Pirozzo
Browse files

Allow subsequent requests for media keys to replay the silent audio sample

Bug: b/146010863
Test: Build, flash, interopt test with hard key events using automotive
hardware.

Change-Id: I4943c9f79011a1ee315fd3178af9171444dffa0b
(cherry picked from commit 5e4df96d)

Merged-In: I4943c9f79011a1ee315fd3178af9171444dffa0b
Change-Id: I8ef5ff15c3570fc98b80a1bfe8f750d7eaa5d32f
parent 462ed818
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -249,9 +249,6 @@ public class A2dpSinkStreamHandler extends Handler {
        if (mAudioFocus != AudioManager.AUDIOFOCUS_GAIN) {
            requestAudioFocus();
        }
        // On the off change mMediaPlayer errors out and dies, we want to make sure we retry this.
        // This function immediately exits if we have a MediaPlayer object.
        requestMediaKeyFocus();
    }

    private synchronized int requestAudioFocus() {
@@ -278,8 +275,11 @@ public class A2dpSinkStreamHandler extends Handler {
    }

    /**
     * Creates a MediaPlayer that plays a silent audio sample so that MediaSessionService will be
     * aware of the fact that Bluetooth is playing audio.
     * Plays a silent audio sample so that MediaSessionService will be aware of the fact that
     * Bluetooth is playing audio.
     *
     * Creates a new MediaPlayer if one does not already exist. Repeat calls to this function are
     * safe and will result in the silent audio sample again.
     *
     * This allows the MediaSession in AVRCP Controller to be routed media key events, if we've
     * chosen to use it.
@@ -287,8 +287,7 @@ public class A2dpSinkStreamHandler extends Handler {
    private synchronized void requestMediaKeyFocus() {
        if (DBG) Log.d(TAG, "requestMediaKeyFocus()");

        if (mMediaPlayer != null) return;

        if (mMediaPlayer == null) {
            AudioAttributes attrs = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_MEDIA)
                    .build();
@@ -306,6 +305,7 @@ public class A2dpSinkStreamHandler extends Handler {
                releaseMediaKeyFocus();
                return false;
            });
        }

        mMediaPlayer.start();
        BluetoothMediaBrowserService.setActive(true);
@@ -314,7 +314,6 @@ public class A2dpSinkStreamHandler extends Handler {
    private synchronized void abandonAudioFocus() {
        if (DBG) Log.d(TAG, "abandonAudioFocus()");
        stopFluorideStreaming();
        releaseMediaKeyFocus();
        mAudioManager.abandonAudioFocus(mAudioFocusListener);
        mAudioFocus = AudioManager.AUDIOFOCUS_NONE;
    }
@@ -337,9 +336,11 @@ public class A2dpSinkStreamHandler extends Handler {
    private void startFluorideStreaming() {
        mA2dpSinkService.informAudioFocusStateNative(STATE_FOCUS_GRANTED);
        mA2dpSinkService.informAudioTrackGainNative(1.0f);
        requestMediaKeyFocus();
    }

    private void stopFluorideStreaming() {
        releaseMediaKeyFocus();
        mA2dpSinkService.informAudioFocusStateNative(STATE_FOCUS_LOST);
    }