From 721361f1a74b876c42cc0533c9c19320e8c09927 Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Fri, 20 Nov 2009 15:21:47 -0800 Subject: [PATCH] Add a new priority for Auto Connection of A2DP. DO NOT MERGE. 1. PRIORITY_OFF is when user unchecks A2DP connection profile box. 2. By default, when you bond, it will be PRIORITY_ON. 3. When the profile gets connected, the priority gets set to PRIORITY_AUTO_CONNECT. This means that we will connect automatically to this profile. 4. When the user disconnects, we downgrade the priority to PRIORITY_ON, which means we won't reconnect automatically. a) We need to make a similar change to Handsfree profile. b) We need to rework the profile management design and code which will fix the 6 second timer that we have for A2DP reconnection. Add AUTO_CONNECT priority for Headset profile. Also, don't set priority to ON while disconnecting. This logic has been pushed up to the Settings app. Dr No: Eastham Bug: 2133530 --- core/java/android/bluetooth/BluetoothA2dp.java | 7 +++++-- core/java/android/bluetooth/BluetoothHeadset.java | 11 ++++++++--- core/java/android/server/BluetoothA2dpService.java | 14 +++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index e8a69d8c1f766..7df3637f31892 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -42,7 +42,7 @@ import java.util.HashSet; * * Currently the BluetoothA2dp service runs in the system server and this * proxy object will be immediately bound to the service on construction. - * + * * Currently this class provides methods to connect to A2DP audio sinks. * * @hide @@ -74,9 +74,12 @@ public final class BluetoothA2dp { /** Playing implies connected */ public static final int STATE_PLAYING = 4; + /** Default priority for a2dp devices that we try to auto-connect + * and allow incoming connections */ + public static final int PRIORITY_AUTO_CONNECT = 1000; /** Default priority for a2dp devices that should allow incoming * connections */ - public static final int PRIORITY_AUTO = 100; + public static final int PRIORITY_ON = 100; /** Default priority for a2dp devices that should not allow incoming * connections */ public static final int PRIORITY_OFF = 0; diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java index 90cff6b8c9026..5eb655a27937b 100644 --- a/core/java/android/bluetooth/BluetoothHeadset.java +++ b/core/java/android/bluetooth/BluetoothHeadset.java @@ -100,9 +100,14 @@ public final class BluetoothHeadset { /** Connection canceled before completetion. */ public static final int RESULT_CANCELED = 2; - /** Default priority for headsets that should be auto-connected */ - public static final int PRIORITY_AUTO = 100; - /** Default priority for headsets that should not be auto-connected */ + /** Default priority for headsets that for which we will accept + * inconing connections and auto-connect */ + public static final int PRIORITY_AUTO_CONNECT = 1000; + /** Default priority for headsets that for which we will accept + * inconing connections but not auto-connect */ + public static final int PRIORITY_ON = 100; + /** Default priority for headsets that should not be auto-connected + * and not allow incoming connections. */ public static final int PRIORITY_OFF = 0; /** The voice dialer 'works' but the user experience is poor. The voice diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index ec3b2ff7b2c8a..46de708aabcff 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -96,7 +96,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { BluetoothDevice.ERROR); switch(bondState) { case BluetoothDevice.BOND_BONDED: - setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO); + setSinkPriority(device, BluetoothA2dp.PRIORITY_ON); break; case BluetoothDevice.BOND_BONDING: case BluetoothDevice.BOND_NONE: @@ -104,7 +104,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { break; } } else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) { - if (getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF && + if (getSinkPriority(device) == BluetoothA2dp.PRIORITY_AUTO_CONNECT && isSinkDevice(device)) { // This device is a preferred sink. Make an A2DP connection // after a delay. We delay to avoid connection collisions, @@ -171,7 +171,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { // check bluetooth is still on, device is still preferred, and // nothing is currently connected if (mBluetoothService.isEnabled() && - getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF && + getSinkPriority(device) == BluetoothA2dp.PRIORITY_AUTO_CONNECT && lookupSinksMatchingStates(new int[] { BluetoothA2dp.STATE_CONNECTING, BluetoothA2dp.STATE_CONNECTED, @@ -450,6 +450,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { if (state == BluetoothA2dp.STATE_CONNECTING) { mAudioManager.setParameters("A2dpSuspended=false"); } + + if (state == BluetoothA2dp.STATE_CONNECTING || + state == BluetoothA2dp.STATE_CONNECTED) { + // We have connected or attempting to connect. + // Bump priority + setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT); + } + Intent intent = new Intent(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothA2dp.EXTRA_PREVIOUS_SINK_STATE, prevState);