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

Commit 2440ebad authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

MediaPlayer: Handle LeAudio play same as in AVRCP

When player is not available, which usually happens after phone restart,
use passthrogh command to send play to media session

Bug: 326528836
Bug: 337169240
Test: mmm packages/modules/Bluetooth
Test: manual use play on LE Headset just after phone restart
Change-Id: I58719fd4684e45cba4af96ef0727550f7094a391
parent 62a1a5f7
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -34,9 +34,11 @@ import android.os.Looper;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;

import com.android.bluetooth.BluetoothEventLogger;
import com.android.bluetooth.Utils;
import com.android.bluetooth.avrcp.AvrcpPassthrough;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.VisibleForTesting;

@@ -310,6 +312,17 @@ public class MediaPlayerList {
        return mMediaPlayers.get(mActivePlayerId);
    }

    /** This is used to send passthrough command to media session */
    public void sendMediaKeyEvent(int key, boolean pushed) {
        if (mMediaSessionManager == null) {
            Log.d(TAG, "Bluetooth is turning off, ignore it");
            return;
        }
        int action = pushed ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP;
        KeyEvent event = new KeyEvent(action, AvrcpPassthrough.toKeyCode(key));
        mMediaSessionManager.dispatchMediaKeyEvent(event, false);
    }

    /**
     * This is used by setBrowsedPlayer as the browsed player is always the Bluetooth player.
     *
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.bluetooth.avrcp;
import android.bluetooth.BluetoothAvrcp;
import android.view.KeyEvent;

class AvrcpPassthrough {
public class AvrcpPassthrough {
    public static int toKeyCode(int operation) {
        switch (operation) {
            case BluetoothAvrcp.PASSTHROUGH_ID_UP:
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.mcp;
import static java.util.Map.entry;

import android.annotation.NonNull;
import android.bluetooth.BluetoothAvrcp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothUuid;
@@ -36,6 +37,7 @@ import com.android.bluetooth.Utils;
import com.android.bluetooth.audio_util.MediaData;
import com.android.bluetooth.audio_util.MediaPlayerList;
import com.android.bluetooth.audio_util.MediaPlayerWrapper;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_audio.ContentControlIdKeeper;
import com.android.internal.annotations.VisibleForTesting;

@@ -402,6 +404,16 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
                        + Request.Opcodes.toString(request.getOpcode()));
        Request.Results status = Request.Results.COMMAND_CANNOT_BE_COMPLETED;

        if (Flags.mcpAllowPlayWithoutActivePlayer()
                && !Utils.isPtsTestMode()
                && mMediaPlayerList.getActivePlayer() == null
                && request.getOpcode() == Request.Opcodes.PLAY) {
            Log.d(TAG, "Player is not active. GMCS send media key for PLAY");
            mMediaPlayerList.sendMediaKeyEvent(BluetoothAvrcp.PASSTHROUGH_ID_PLAY, true);
            mMediaPlayerList.sendMediaKeyEvent(BluetoothAvrcp.PASSTHROUGH_ID_PLAY, false);
            return;
        }

        if (mMediaPlayerList.getActivePlayer() == null || mCurrentData.state == null) {
            Log.w(TAG, "no active MediaPlayer or mCurrentData is null");
            if (mGMcsService != null) {