Skip to content
Snippets Groups Projects
Commit c5d7951c authored by Aritra Sen's avatar Aritra Sen Committed by Gerrit Code Review
Browse files

Merge changes Ie3dda9ba,I8dcc07a7 into main

* changes:
  Remove dependency on A2DP Connection State change broadcast in AVRCP Target Service.
  Remove dependency of BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED from AvrcpTargetService.
parents 51297cf5 4e23adc4
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......@@ -1270,6 +1270,9 @@ public class A2dpService extends ProfileService {
removeStateMachine(device);
}
}
if (mFactory.getAvrcpTargetService() != null) {
mFactory.getAvrcpTargetService().handleA2dpConnectionStateChanged(device, toState);
}
mAdapterService
.getActiveDeviceManager()
.a2dpConnectionStateChanged(device, fromState, toState);
......
......@@ -17,7 +17,6 @@
package com.android.bluetooth.avrcp;
import android.annotation.NonNull;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUtils;
......@@ -140,25 +139,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 (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)) {
if (action.equals(AudioManager.ACTION_VOLUME_CHANGED)) {
int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
if (streamType == AudioManager.STREAM_MUSIC) {
int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
......@@ -252,8 +233,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 +316,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 +335,35 @@ public class AvrcpTargetService extends ProfileService {
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.
void setVolume(int avrcpVolume) {
BluetoothDevice activeDevice = getA2dpActiveDevice();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment