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

Commit 324db978 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add flag for audio focus to facilitate overlays"

parents 38609374 977ad222
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@

    <!-- For A2DP sink ducking volume feature. -->
    <integer name="a2dp_sink_duck_percent">25</integer>
    <!-- If true, device requests audio focus and start avrcp updates on source start or play -->
    <bool name="a2dp_sink_automatically_request_audio_focus">false</bool>

    <!-- For enabling the hfp client connection service -->
    <bool name="hfp_client_connection_service_enabled">false</bool>
+17 −16
Original line number Diff line number Diff line
@@ -112,11 +112,8 @@ public class A2dpSinkStreamHandler extends Handler {
        }
        switch (message.what) {
            case SRC_STR_START:
                // Always request audio focus if on TV.
                if (isTvDevice()) {
                    if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                        requestAudioFocus();
                    }
                if (isTvDevice() || shouldRequestFocus()) {
                    requestAudioFocusIfNone();
                }
                // Audio stream has started, stop it if we don't have focus.
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
@@ -130,9 +127,7 @@ public class A2dpSinkStreamHandler extends Handler {

            case SNK_PLAY:
                // Local play command, gain focus and start avrcp updates.
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                    requestAudioFocus();
                }
                requestAudioFocusIfNone();
                break;

            case SNK_PAUSE:
@@ -143,11 +138,8 @@ public class A2dpSinkStreamHandler extends Handler {
            case SRC_PLAY:
                mStreamAvailable = true;
                // Remote play command.
                // If is an iot device gain focus and start avrcp updates.
                if (isIotDevice() || isTvDevice()) {
                    if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                        requestAudioFocus();
                    }
                if (isIotDevice() || isTvDevice() || shouldRequestFocus()) {
                    requestAudioFocusIfNone();
                    break;
                }
                // Otherwise, pause if we don't have focus
@@ -162,9 +154,7 @@ public class A2dpSinkStreamHandler extends Handler {
                break;

            case REQUEST_FOCUS:
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                    requestAudioFocus();
                }
                requestAudioFocusIfNone();
                break;

            case DISCONNECT:
@@ -232,6 +222,12 @@ public class A2dpSinkStreamHandler extends Handler {
    /**
     * Utility functions.
     */
    private void requestAudioFocusIfNone() {
        if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
            requestAudioFocus();
        }
    }

    private synchronized int requestAudioFocus() {
        // Bluetooth A2DP may carry Music, Audio Books, Navigation, or other sounds so mark content
        // type unknown.
@@ -356,4 +352,9 @@ public class A2dpSinkStreamHandler extends Handler {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    }

    private boolean shouldRequestFocus() {
        return mContext.getResources()
            .getBoolean(R.bool.a2dp_sink_automatically_request_audio_focus);
    }

}