summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/audio/AudioService.java
diff options
context:
space:
mode:
authorGaurav Asati <gasati@codeaurora.org>2015-07-28 20:57:29 +0530
committerLinux Build Service Account <lnxbuild@localhost>2015-10-06 03:27:02 -0600
commit71d6acbfd1a726e8722e4e0f32f20b7bb21b6656 (patch)
tree5dc8883e45ec29617848813d2eb67ef327d31a3f /services/core/java/com/android/server/audio/AudioService.java
parent620c100fe78ccfd67d3ea1aa230c772d32d96e60 (diff)
downloadframeworks_base-71d6acbfd1a726e8722e4e0f32f20b7bb21b6656.zip
frameworks_base-71d6acbfd1a726e8722e4e0f32f20b7bb21b6656.tar.gz
frameworks_base-71d6acbfd1a726e8722e4e0f32f20b7bb21b6656.tar.bz2
BT: Multi A2dp support in Settings App.
1. The connected sinks are not disconnected from A2dpProfile when new sink is connecting. 2. Also return correct connection status for specific HS. 3. Sets priority for specific HS while disconnecting. Change-Id: I56142d1527aa86d2bb47fb7166b2f3ab451d9b17 Bluetooth: Add support of two A2dp connections. Audio Service will now manage two a2dp connections and makes sure that BT a2dp connections are consistently seen by other applications. The change removes the BD address usage in BT names, and uses a new Strin "BluetoothA2dp" in order to show A2dp connected devices. Change-Id: I59b8f8eff7bbc8033fcd46d0ac21d94ee338ca36
Diffstat (limited to 'services/core/java/com/android/server/audio/AudioService.java')
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java74
1 files changed, 65 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 4b618bb..cde2d7c 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -445,6 +445,11 @@ public class AudioService extends IAudioService.Stub {
private final ArrayMap<String, DeviceListSpec> mConnectedDevices = new ArrayMap<>();
+ private String mA2dpConnectedDevice = ""; //Used for BT a2dp connection
+ //Add connected A2dp devices in this list
+ private ArrayList<BluetoothDevice> mConnectedBTDevicesList =
+ new ArrayList<BluetoothDevice>();
+
// Forced device usage for communications
private int mForcedUseForComm;
@@ -3078,9 +3083,13 @@ public class AudioService extends IAudioService.Stub {
synchronized (mConnectedDevices) {
synchronized (mA2dpAvrcpLock) {
mA2dp = (BluetoothA2dp) proxy;
+ //In Dual A2dp, we can have two devices connected
deviceList = mA2dp.getConnectedDevices();
- if (deviceList.size() > 0) {
- btDevice = deviceList.get(0);
+ Log.d(TAG, "onServiceConnected: A2dp Service connected: " +
+ deviceList.size());
+ for (int i = 0; i < deviceList.size(); i++) {
+ //Add the device in Connected list
+ btDevice = deviceList.get(i);
int state = mA2dp.getConnectionState(btDevice);
int delay = checkSendBecomingNoisyIntent(
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
@@ -3178,6 +3187,10 @@ public class AudioService extends IAudioService.Stub {
case BluetoothProfile.A2DP:
synchronized (mConnectedDevices) {
synchronized (mA2dpAvrcpLock) {
+ Log.d(TAG,"mConnectedBTDevicesList size " + mConnectedBTDevicesList.size());
+ if (mConnectedBTDevicesList.size() > 0) {
+ mConnectedBTDevicesList.clear();
+ }
// Disconnect ALL DEVICE_OUT_BLUETOOTH_A2DP devices
for (int i = 0; i < mConnectedDevices.size(); i++) {
DeviceListSpec deviceSpec = mConnectedDevices.valueAt(i);
@@ -3733,10 +3746,42 @@ public class AudioService extends IAudioService.Stub {
public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state, int profile)
{
- int delay;
+ int delay = 0;
if (profile != BluetoothProfile.A2DP && profile != BluetoothProfile.A2DP_SINK) {
throw new IllegalArgumentException("invalid profile " + profile);
}
+ /*check the state of the currnt device*/
+ if (state == BluetoothA2dp.STATE_CONNECTING) {
+ Log.d(TAG, "Device is still connecting ");
+ return delay;
+ }
+ if ((mConnectedBTDevicesList.contains(device) &&
+ (state == BluetoothA2dp.STATE_CONNECTED))) {
+ Log.d(TAG, "Device conn is updated again, ignore ");
+ return delay;
+ }
+ if (!mConnectedBTDevicesList.contains(device) &&
+ (state == BluetoothA2dp.STATE_CONNECTED)) {
+ /*add the device in the list*/
+ Log.d(TAG, "Add new connected device in the list: " + device);
+ mConnectedBTDevicesList.add(device);
+ if (mConnectedBTDevicesList.size() > 1) {
+ Log.d(TAG, "Second device connected, add new device ");
+ }
+ } else if ((state == BluetoothA2dp.STATE_DISCONNECTED) ||
+ (state == BluetoothA2dp.STATE_DISCONNECTING)) {
+ Log.d(TAG, "Device is getting disconnected: " + device);
+ if (mConnectedBTDevicesList.contains(device)) {
+ Log.d(TAG, "Remove the BT device ");
+ mConnectedBTDevicesList.remove(device);
+ }
+ if (mConnectedBTDevicesList.size() > 0) {
+ Log.d(TAG, "device removed " + device.getAddress() );
+ mConnectedDevices.remove(makeDeviceListKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
+ device.getAddress()));
+ return delay;
+ }
+ }
synchronized (mConnectedDevices) {
if (profile == BluetoothProfile.A2DP) {
delay = checkSendBecomingNoisyIntent(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
@@ -4750,11 +4795,12 @@ public class AudioService extends IAudioService.Stub {
// introduction of a delay for transient disconnections of docks when
// power is rapidly turned off/on, this message will be canceled if
// we reconnect the dock under a preset delay
- makeA2dpDeviceUnavailableLater(address, BTA2DP_DOCK_TIMEOUT_MILLIS);
+ makeA2dpDeviceUnavailableLater(btDevice.getAddress(), BTA2DP_DOCK_TIMEOUT_MILLIS);
// the next time isConnected is evaluated, it will be false for the dock
}
} else {
- makeA2dpDeviceUnavailableNow(address);
+ Log.d(TAG, "All devices are disconneted, update Policymanager ");
+ makeA2dpDeviceUnavailableNow(btDevice.getAddress());
}
synchronized (mCurAudioRoutes) {
if (mCurAudioRoutes.bluetoothName != null) {
@@ -4764,21 +4810,24 @@ public class AudioService extends IAudioService.Stub {
}
}
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
+ //This function is not implemented
+ mA2dpConnectedDevice = "BluetoothA2dp"; // Add this String
if (btDevice.isBluetoothDock()) {
// this could be a reconnection after a transient disconnection
cancelA2dpDeviceTimeout();
- mDockAddress = address;
+ mDockAddress = mA2dpConnectedDevice;
} else {
// this could be a connection of another A2DP device before the timeout of
// a dock: cancel the dock timeout, and make the dock unavailable now
if(hasScheduledA2dpDockTimeout()) {
cancelA2dpDeviceTimeout();
- makeA2dpDeviceUnavailableNow(mDockAddress);
+ makeA2dpDeviceUnavailableNow(btDevice.getAddress());
}
}
- makeA2dpDeviceAvailable(address, btDevice.getName());
+ makeA2dpDeviceAvailable(btDevice.getAddress(), btDevice.getName());
+ //Updated the Router for a2dp device
synchronized (mCurAudioRoutes) {
- String name = btDevice.getAliasName();
+ String name = mA2dpConnectedDevice;
if (!TextUtils.equals(mCurAudioRoutes.bluetoothName, name)) {
mCurAudioRoutes.bluetoothName = name;
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
@@ -4795,6 +4844,7 @@ public class AudioService extends IAudioService.Stub {
Log.d(TAG, "onSetA2dpSourceConnectionState btDevice="+btDevice+" state="+state);
}
if (btDevice == null) {
+ Log.d(TAG, "onSetA2dpSourceConnectionState device is null"); //gasati
return;
}
String address = btDevice.getAddress();
@@ -4878,8 +4928,14 @@ public class AudioService extends IAudioService.Stub {
// Called synchronized on mConnectedDevices
private int checkSendBecomingNoisyIntent(int device, int state) {
int delay = 0;
+ if (mConnectedBTDevicesList.size() > 1) {
+ Log.d(TAG, "checkSendBecomingNoisyIntent on state: " + state);
+ return delay;
+ }
+
if ((state == 0) && ((device & mBecomingNoisyIntentDevices) != 0)) {
int devices = 0;
+ Log.d(TAG, "checkSendBecomingNoisyIntent update the noise");
for (int i = 0; i < mConnectedDevices.size(); i++) {
int dev = mConnectedDevices.valueAt(i).mDeviceType;
if (((dev & AudioSystem.DEVICE_BIT_IN) == 0)