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

Commit 60eef938 authored by Joonghong Park's avatar Joonghong Park Committed by Ted Wang
Browse files

Fix missing avrcp disconnect request



When user tries to disconnect a2dp profile connection to remote
device, there is an unexpected case that a remote node is not
disconnected neatly and the remote node tries to re-connect after a while.
The reason of this issue is from alive avrcp connection
that is established during a2dp connecting phase.

We need to consider missing avrcp disconnection after a2dp disconnection.
So this tries to disconnect avrcp channel followed by a2dp disconnection.
But if the channel is already disconnected by such a remote node,
disconnection procedure will do nothing in bt stack.

Bug: 128352535
Bug: 137776758
Test: Test on phone and airpod as a remote a2dp(avrcp) node
Change-Id: I1e18ffb354d7f9d1aef7ebdd8b582febd479794f
Merged-In: I1e18ffb354d7f9d1aef7ebdd8b582febd479794f
Signed-off-by: default avatarJoonghong Park <joonghong.park@samsung.com>
parent 6a3a2223
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.avrcp;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothAvrcpTarget;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -96,6 +97,19 @@ public class AvrcpTargetService extends ProfileService {

                // Update all the playback status info for each connected device
                mNativeInterface.sendMediaUpdate(false, true, false);
            } else if (action.equals(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
                if (mNativeInterface == null) return;

                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (device == null) return;

                int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
                if (state == BluetoothProfile.STATE_DISCONNECTED) {
                    // If there is no connection, disconnectDevice() will do nothing
                    if (mNativeInterface.disconnectDevice(device.getAddress())) {
                        Log.d(TAG, "request to disconnect device " + device);
                    }
                }
            }
        }
    }
@@ -166,6 +180,7 @@ public class AvrcpTargetService extends ProfileService {
        mReceiver = new AvrcpBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        registerReceiver(mReceiver, filter);

        // Only allow the service to be used once it is initialized