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

Commit 8e9eac9e authored by Aritra Sen's avatar Aritra Sen
Browse files

Remove dependency of BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED from AvrcpTargetService.

Bug: 296932947
Test: atest BluetoothInstrumentationTests
Tag: #refactor
Change-Id: I8dcc07a7f7f497f37569554b871cf980405e4890
parent fcf34698
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1069,7 +1069,7 @@ public class A2dpService extends ProfileService {

        // Make sure volume has been store before device been remove from active.
        if (mFactory.getAvrcpTargetService() != null) {
            mFactory.getAvrcpTargetService().volumeDeviceSwitched(device);
            mFactory.getAvrcpTargetService().handleA2dpActiveDeviceChanged(device);
        }
        synchronized (mStateMachines) {
            mActiveDevice = device;
+16 −19
Original line number Diff line number Diff line
@@ -140,12 +140,7 @@ public class AvrcpTargetService extends ProfileService {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
                if (mNativeInterface == null) return;

                // 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 (action.equals(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
                if (mNativeInterface == null) return;

                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@@ -252,7 +247,6 @@ public class AvrcpTargetService extends ProfileService {
        mReceiver = new AvrcpBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(AudioManager.ACTION_VOLUME_CHANGED);
        registerReceiver(mReceiver, filter);
@@ -337,18 +331,6 @@ public class AvrcpTargetService extends ProfileService {
        mVolumeManager.deviceDisconnected(device);
    }

    /**
     * Signal to the service that the current audio out device has changed and to inform
     * the audio service whether the new device supports absolute volume. If it does, also
     * set the absolute volume level on the remote device.
     */
    public void volumeDeviceSwitched(BluetoothDevice device) {
        if (DEBUG) {
            Log.d(TAG, "volumeDeviceSwitched: device=" + device);
        }
        mVolumeManager.volumeDeviceSwitched(device);
    }

    /**
     * Remove the stored volume for a device.
     */
@@ -368,6 +350,21 @@ public class AvrcpTargetService extends ProfileService {
        return mVolumeManager.getVolume(device, mVolumeManager.getNewDeviceVolume());
    }

    /**
     * Handle when Active Device changes in A2DP.
     *
     * <p>Signal to the service that the current audio out device has changed and to inform the
     * audio service whether the new device supports absolute volume. If it does, also set the
     * absolute volume level on the remote device.
     */
    public void handleA2dpActiveDeviceChanged(BluetoothDevice device) {
        mVolumeManager.volumeDeviceSwitched(device);
        if (mNativeInterface != null) {
            // Update all the playback status info for each connected device
            mNativeInterface.sendMediaUpdate(false, true, false);
        }
    }

    // TODO (apanicke): Add checks to rejectlist Absolute Volume devices if they behave poorly.
    void setVolume(int avrcpVolume) {
        BluetoothDevice activeDevice = getA2dpActiveDevice();