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

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

Merge changes If113db4b,I7b7ccb44,I0eff67d8 into main

* changes:
  Signal "Connecting" state when receiving audio focus
  flag: signal_connecting_on_focus_gain
  Return null instead of empty list when AVRCP CT service isn't ready
parents 137ee761 a1721f59
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -503,6 +503,7 @@ class AvrcpControllerStateMachine extends StateMachine {
                case AUDIO_FOCUS_STATE_CHANGE:
                    int newState = msg.arg1;
                    debug("Connected: Audio focus changed -> " + newState);
                    BluetoothMediaBrowserService.onAudioFocusStateChanged(newState);
                    switch (newState) {
                        case AudioManager.AUDIOFOCUS_GAIN:
                            // Begin playing audio again if we paused the remote
+62 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaMetadataCompat;
@@ -33,6 +34,7 @@ import androidx.media.MediaBrowserServiceCompat;

import com.android.bluetooth.BluetoothPrefs;
import com.android.bluetooth.R;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

@@ -229,7 +231,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
                AvrcpControllerService.getAvrcpControllerService();
        if (avrcpControllerService == null) {
            Log.w(TAG, "getContents(id=" + parentMediaId + "): AVRCP Controller Service not ready");
            return new BrowseResult(new ArrayList(0), BrowseResult.ERROR_NO_AVRCP_SERVICE);
            return new BrowseResult(null, BrowseResult.ERROR_NO_AVRCP_SERVICE);
        } else {
            return avrcpControllerService.getContents(parentMediaId);
        }
@@ -399,6 +401,65 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        service.mSession.setPlaybackState(state);
    }

    /**
     * Notify this MediaBrowserService of changes to audio focus state
     *
     * <p>Temporarily set state to "Connecting" to better interoperate with media center
     * applications.
     *
     * <p>The "Connecting" state is considered an "active" playback state, which will cause clients
     * that don't listen to the media framework's callback for media key events (whoever most
     * recently requested focus + had playback) to think we're the application who most recently
     * updated to an "active" playback state, which in turn will have them show us as the active app
     * in the UI while we wait on the remote device to accept our playback command.
     */
    static synchronized void onAudioFocusStateChanged(int state) {
        if (!Flags.signalConnectingOnFocusGain()) {
            Log.w(TAG, "Feature 'signal_connecting_on_focus_gain' not enabled. Skip");
            return;
        }

        if (state != AudioManager.AUDIOFOCUS_GAIN) {
            return;
        }

        BluetoothMediaBrowserService service = BluetoothMediaBrowserService.getInstance();
        if (service == null) {
            Log.w(TAG, "onAudioFocusStateChanged(state=" + state + "): Service not available");
            return;
        }

        Log.i(
                TAG,
                "onAudioFocusStateChanged(state="
                        + state
                        + "): Focus gained, briefly signal connecting");

        MediaSessionCompat session = service.getSession();
        MediaControllerCompat controller = session.getController();
        PlaybackStateCompat currentState =
                controller == null ? null : controller.getPlaybackState();

        PlaybackStateCompat connectingState = null;
        if (currentState != null) {
            connectingState =
                    new PlaybackStateCompat.Builder(currentState)
                            .setState(
                                    PlaybackStateCompat.STATE_CONNECTING,
                                    currentState.getPosition(),
                                    currentState.getPlaybackSpeed())
                            .build();
            service.mSession.setPlaybackState(connectingState);
            service.mSession.setPlaybackState(currentState);
        } else {
            Log.w(
                    TAG,
                    "onAudioFocusStateChanged(state="
                            + state
                            + "): current playback state is null");
        }
    }

    /** Get playback state */
    public static synchronized PlaybackStateCompat getPlaybackState() {
        BluetoothMediaBrowserService service = BluetoothMediaBrowserService.getInstance();
+10 −0
Original line number Diff line number Diff line
@@ -20,3 +20,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "signal_connecting_on_focus_gain"
    namespace: "bluetooth"
    description: " Briefly signal a connecting playback state when we get focus so browser clients see us having an active playback state and switch to us as the source"
    bug: "350510879"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}