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

Commit 96f3ca59 authored by Gubbala Venugopal Rao's avatar Gubbala Venugopal Rao
Browse files

Bluetooth: A2dpSink change to handle Media Player Pause CMD

Camera Pauses the Playback before starting the Video recording
but it doesn't start the playback once recording is completed.
This change will Disconnect the A2dp and moves the A2dpSink
to proper state before starting the Video Recording.

Change-Id: I816edde2f5e3f7513dbe04961868a62b2e4f68a5
CRs-fixed: 591351
parent 658eeb26
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetooth;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
@@ -43,6 +44,7 @@ import android.os.ParcelUuid;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -140,6 +142,12 @@ final class A2dpStateMachine extends StateMachine {
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BluetoothA2dpService");

        mIntentBroadcastHandler = new IntentBroadcastHandler();
        IntentFilter filter = new IntentFilter("com.android.music.musicservicecommand");
        try {
            context.registerReceiver(mA2dpReceiver, filter);
        } catch (Exception e) {
            loge("Unable to register A2dp receiver: " + e);
        }

        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

@@ -153,6 +161,11 @@ final class A2dpStateMachine extends StateMachine {
    }

    public void doQuit() {
        try {
            mContext.unregisterReceiver(mA2dpReceiver);
        } catch (Exception e) {
            log("Unable to unregister A2dp receiver" + e);
        }
        if ((mTargetDevice != null) &&
            (getConnectionState(mTargetDevice) == BluetoothProfile.STATE_CONNECTING)) {
            log("doQuit()- Move A2DP State to DISCONNECTED");
@@ -856,6 +869,34 @@ final class A2dpStateMachine extends StateMachine {
        }
    }

    private final BroadcastReceiver mA2dpReceiver = new BroadcastReceiver() {
    @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            log("onReceive  " + action);
            if (action.equals("com.android.music.musicservicecommand")) {
                String cmd = intent.getStringExtra("command");
                log("Command Received  " + cmd);
                if (cmd.equals("pause")) {
                    if (mCurrentDevice != null) {
                        if (isSrcNative(getByteAddress(mCurrentDevice))) {
                            //Camera Pauses the Playback before starting the Video recording
                            //But it doesn't start the playback once recording is completed.
                            //Disconnecting the A2dp to move the A2dpSink to proper state.
                            disconnectA2dpNative(getByteAddress(mCurrentDevice));
                            // in case PEER DEVICE is A2DP SRC we need to manage audio focus
                            int status = mAudioManager.abandonAudioFocus(mAudioFocusListener);
                            log("abandonAudioFocus returned" + status);
                        }
                    } else {
                        int status = mAudioManager.abandonAudioFocus(mAudioFocusListener);
                        log("abandonAudioFocus returned" + status);
                    }
                }
            }
        }
    };

    private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener(){
        public void onAudioFocusChange(int focusChange){
            log("onAudioFocusChangeListener  focuschange" + focusChange);