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

Commit d67000f0 authored by Aritra Sen's avatar Aritra Sen Committed by Automerger Merge Worker
Browse files

Merge changes Ie3dda9ba,I8dcc07a7 into main am: c5d7951c

parents 9851c8d1 c5d7951c
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line 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.
        // Make sure volume has been store before device been remove from active.
        if (mFactory.getAvrcpTargetService() != null) {
        if (mFactory.getAvrcpTargetService() != null) {
            mFactory.getAvrcpTargetService().volumeDeviceSwitched(device);
            mFactory.getAvrcpTargetService().handleA2dpActiveDeviceChanged(device);
        }
        }
        synchronized (mStateMachines) {
        synchronized (mStateMachines) {
            mActiveDevice = device;
            mActiveDevice = device;
@@ -1270,6 +1270,9 @@ public class A2dpService extends ProfileService {
                removeStateMachine(device);
                removeStateMachine(device);
            }
            }
        }
        }
        if (mFactory.getAvrcpTargetService() != null) {
            mFactory.getAvrcpTargetService().handleA2dpConnectionStateChanged(device, toState);
        }
        mAdapterService
        mAdapterService
                .getActiveDeviceManager()
                .getActiveDeviceManager()
                .a2dpConnectionStateChanged(device, fromState, toState);
                .a2dpConnectionStateChanged(device, fromState, toState);
+30 −34
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.bluetooth.avrcp;
package com.android.bluetooth.avrcp;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUtils;
import android.bluetooth.BluetoothUtils;
@@ -140,25 +139,7 @@ public class AvrcpTargetService extends ProfileService {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String action = intent.getAction();
            if (action.equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
            if (action.equals(AudioManager.ACTION_VOLUME_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 (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);
                    }
                }
            } else if (action.equals(AudioManager.ACTION_VOLUME_CHANGED)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                if (streamType == AudioManager.STREAM_MUSIC) {
                if (streamType == AudioManager.STREAM_MUSIC) {
                    int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
                    int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
@@ -252,8 +233,6 @@ public class AvrcpTargetService extends ProfileService {
        mReceiver = new AvrcpBroadcastReceiver();
        mReceiver = new AvrcpBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        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);
        filter.addAction(AudioManager.ACTION_VOLUME_CHANGED);
        registerReceiver(mReceiver, filter);
        registerReceiver(mReceiver, filter);


@@ -337,18 +316,6 @@ public class AvrcpTargetService extends ProfileService {
        mVolumeManager.deviceDisconnected(device);
        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.
     * Remove the stored volume for a device.
     */
     */
@@ -368,6 +335,35 @@ public class AvrcpTargetService extends ProfileService {
        return mVolumeManager.getVolume(device, mVolumeManager.getNewDeviceVolume());
        return mVolumeManager.getVolume(device, mVolumeManager.getNewDeviceVolume());
    }
    }


    /**
     * Handle when A2DP connection state changes.
     *
     * <p>If the A2DP connection disconnects, we request AVRCP to disconnect device as well.
     */
    public void handleA2dpConnectionStateChanged(BluetoothDevice device, int newState) {
        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())) {
                Log.d(TAG, "request to disconnect device " + device);
            }
        }
    }
    /**
     * 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.
    // TODO (apanicke): Add checks to rejectlist Absolute Volume devices if they behave poorly.
    void setVolume(int avrcpVolume) {
    void setVolume(int avrcpVolume) {
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        BluetoothDevice activeDevice = getA2dpActiveDevice();