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

Commit 00f534d2 authored by Kihong Seong's avatar Kihong Seong
Browse files

Handle null identity address in AvrcpNativeInterface

Change AvrcpNativeInterface functions to take in
BluetoothDevice object and use a Util method to accommodate the behavior
correction where identity address can be null.

Bug: 317120534
Bug: 295907764
Test: m com.android.btservices
Change-Id: Id8695fb1f057b50ad09c2cf9b7803b343cce733e
parent 8cf69e75
Loading
Loading
Loading
Loading
+17 −14
Original line number Diff line number Diff line
@@ -195,13 +195,16 @@ public class AvrcpCoverArtService {
            if (mClients.containsKey(device)) return false;

            // Create a BIP OBEX Server session for the client and connect
            AvrcpBipObexServer s = new AvrcpBipObexServer(this, new AvrcpBipObexServer.Callback() {
            AvrcpBipObexServer s =
                    new AvrcpBipObexServer(
                            this,
                            new AvrcpBipObexServer.Callback() {
                                public void onConnected() {
                    mNativeInterface.setBipClientStatus(device.getAddress(), true);
                                    mNativeInterface.setBipClientStatus(device, true);
                                }

                                public void onDisconnected() {
                    mNativeInterface.setBipClientStatus(device.getAddress(), false);
                                    mNativeInterface.setBipClientStatus(device, false);
                                }

                                public void onClose() {
@@ -232,7 +235,7 @@ public class AvrcpCoverArtService {
        // socket as well. No need to maintain and close anything else.
        synchronized (mClientsLock) {
            if (mClients.containsKey(device)) {
                mNativeInterface.setBipClientStatus(device.getAddress(), false);
                mNativeInterface.setBipClientStatus(device, false);
                ServerSession session = mClients.get(device);
                mClients.remove(device);
                session.close();
+16 −12
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.bluetooth.audio_util.PlayStatus;
import com.android.bluetooth.audio_util.PlayerInfo;
import com.android.bluetooth.audio_util.PlayerSettingsManager.PlayerSettingsValues;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

@@ -93,8 +94,11 @@ public class AvrcpNativeInterface {
        unregisterBipServerNative();
    }

    void setBipClientStatus(String bdaddr, boolean connected) {
        String identityAddress = mAdapterService.getIdentityAddress(bdaddr);
    void setBipClientStatus(BluetoothDevice device, boolean connected) {
        String identityAddress =
                Flags.identityAddressNullIfUnknown()
                        ? Utils.getBrEdrAddress(device)
                        : mAdapterService.getIdentityAddress(device.getAddress());
        setBipClientStatusNative(identityAddress, connected);
    }

@@ -218,14 +222,11 @@ public class AvrcpNativeInterface {
        mAvrcpService.playItem(playerId, nowPlaying, mediaId);
    }

    boolean connectDevice(String bdaddr) {
        String identityAddress = mAdapterService.getIdentityAddress(bdaddr);
        d("connectDevice: identityAddress=" + identityAddress);
        return connectDeviceNative(identityAddress);
    }

    boolean disconnectDevice(String bdaddr) {
        String identityAddress = mAdapterService.getIdentityAddress(bdaddr);
    boolean disconnectDevice(BluetoothDevice device) {
        String identityAddress =
                Flags.identityAddressNullIfUnknown()
                        ? Utils.getBrEdrAddress(device)
                        : mAdapterService.getIdentityAddress(device.getAddress());
        d("disconnectDevice: identityAddress=" + identityAddress);
        return disconnectDeviceNative(identityAddress);
    }
@@ -258,9 +259,12 @@ public class AvrcpNativeInterface {
        mAvrcpService.deviceDisconnected(device);
    }

    void sendVolumeChanged(String bdaddr, int volume) {
    void sendVolumeChanged(BluetoothDevice device, int volume) {
        d("sendVolumeChanged: volume=" + volume);
        String identityAddress = mAdapterService.getIdentityAddress(bdaddr);
        String identityAddress =
                Flags.identityAddressNullIfUnknown()
                        ? Utils.getBrEdrAddress(device)
                        : mAdapterService.getIdentityAddress(device.getAddress());
        sendVolumeChangedNative(identityAddress, volume);
    }

+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ public class AvrcpTargetService extends ProfileService {
        if (device == null || mNativeInterface == null) return;
        if (newState == BluetoothProfile.STATE_DISCONNECTED) {
            // If there is no connection, disconnectDevice() will do nothing
            if (mNativeInterface.disconnectDevice(device.getAddress())) {
            if (mNativeInterface.disconnectDevice(device)) {
                Log.d(TAG, "request to disconnect device " + device);
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
            int avrcpVolume = systemToAvrcpVolume(savedVolume);
            mVolumeEventLogger.logd(TAG,
                    "switchVolumeDevice: Updating device volume: avrcpVolume=" + avrcpVolume);
            mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume);
            mNativeInterface.sendVolumeChanged(device, avrcpVolume);
        }
    }

@@ -200,7 +200,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
                        + " avrcpVolume=" + avrcpVolume
                        + " deviceVolume=" + deviceVolume
                        + " sDeviceMaxVolume=" + sDeviceMaxVolume);
        mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume);
        mNativeInterface.sendVolumeChanged(device, avrcpVolume);
        storeVolumeForDevice(device);
    }

+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class AvrcpVolumeManagerTest {
    public void sendVolumeChanged() {
        mAvrcpVolumeManager.sendVolumeChanged(mRemoteDevice, TEST_DEVICE_MAX_VOUME);

        verify(mNativeInterface).sendVolumeChanged(REMOTE_DEVICE_ADDRESS, AVRCP_MAX_VOL);
        verify(mNativeInterface).sendVolumeChanged(mRemoteDevice, AVRCP_MAX_VOL);
    }

    @Test