OSDN Git Service

Fix for A2dp/hf connection happening even when profile is disabled in Settings
authorSwaminatha Balaji <swbalaji@broadcom.com>
Tue, 15 May 2012 09:59:35 +0000 (02:59 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:07:59 +0000 (22:07 -0700)
Change-Id: I32145db12e0107b858e2e25ad1ae6cba6eadb55d

src/com/android/bluetooth/a2dp/A2dpStateMachine.java
src/com/android/bluetooth/hfp/HeadsetStateMachine.java

index 59df757..c839d29 100755 (executable)
@@ -188,22 +188,37 @@ final class A2dpStateMachine extends StateMachine {
                 Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
                 break;
             case CONNECTION_STATE_CONNECTING:
-                // TODO(BT) Assume it's incoming connection
-                //     Do we need to check priority and accept/reject accordingly?
-                broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
-                                         BluetoothProfile.STATE_DISCONNECTED);
-                synchronized (A2dpStateMachine.this) {
-                    mIncomingDevice = device;
-                    transitionTo(mPending);
+                // check priority and accept or reject the connection
+                // Since the state changes to  Connecting or directly Connected in some cases.Have the check both in
+                // CONNECTION_STATE_CONNECTING and CONNECTION_STATE_CONNECTED.
+                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                    Log.i(TAG,"Incoming A2DP accepted");
+                    broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
+                                             BluetoothProfile.STATE_DISCONNECTED);
+                    synchronized (A2dpStateMachine.this) {
+                        mIncomingDevice = device;
+                        transitionTo(mPending);
+                    }
+                } else {
+                    //reject the connection and stay in Disconnected state itself
+                    Log.i(TAG,"Incoming A2DP rejected");
+                    disconnectA2dpNative(getByteAddress(device));
                 }
                 break;
             case CONNECTION_STATE_CONNECTED:
                 Log.w(TAG, "A2DP Connected from Disconnected state");
-                broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
-                                         BluetoothProfile.STATE_DISCONNECTED);
-                synchronized (A2dpStateMachine.this) {
-                    mCurrentDevice = device;
-                    transitionTo(mConnected);
+                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                    Log.i(TAG,"Incoming A2DP accepted");
+                    broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+                                             BluetoothProfile.STATE_DISCONNECTED);
+                    synchronized (A2dpStateMachine.this) {
+                        mCurrentDevice = device;
+                        transitionTo(mConnected);
+                    }
+                } else {
+                    //reject the connection and stay in Disconnected state itself
+                    Log.i(TAG,"Incoming A2DP rejected");
+                    disconnectA2dpNative(getByteAddress(device));
                 }
                 break;
             case CONNECTION_STATE_DISCONNECTING:
index 974808b..563c334 100755 (executable)
@@ -301,24 +301,42 @@ final class HeadsetStateMachine extends StateMachine {
                 Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
-                // TODO(BT) Assume it's incoming connection
-                //     Do we need to check priority and accept/reject accordingly?
-                broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
-                                         BluetoothProfile.STATE_DISCONNECTED);
-                synchronized (HeadsetStateMachine.this) {
-                    mIncomingDevice = device;
-                    transitionTo(mPending);
+                // check priority and accept or reject the connection
+                // Since the state changes to  Connecting or directly Connected in some cases.Have the check both in
+                // CONNECTION_STATE_CONNECTING and CONNECTION_STATE_CONNECTED.
+                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                    Log.i(TAG,"Incoming Hf accepted");
+                    // TODO(BT) Assume it's incoming connection
+                    //     Do we need to check priority and accept/reject accordingly?
+                    broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
+                                             BluetoothProfile.STATE_DISCONNECTED);
+                    synchronized (HeadsetStateMachine.this) {
+                        mIncomingDevice = device;
+                        transitionTo(mPending);
+                    }
+                } else {
+                    Log.i(TAG,"Incoming Hf rejected");
+                    //reject the connection and stay in Disconnected state itself
+                    disconnectHfpNative(getByteAddress(device));
                 }
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
                 Log.w(TAG, "HFP Connected from Disconnected state");
-                broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
-                                         BluetoothProfile.STATE_DISCONNECTED);
-                synchronized (HeadsetStateMachine.this) {
-                    mCurrentDevice = device;
-                    transitionTo(mConnected);
+                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                    Log.i(TAG,"Incoming Hf accepted");
+                    broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+                                             BluetoothProfile.STATE_DISCONNECTED);
+                    synchronized (HeadsetStateMachine.this) {
+                        mCurrentDevice = device;
+                        transitionTo(mConnected);
+                    }
+                    configAudioParameters();
+                } else {
+                    //reject the connection and stay in Disconnected state itself
+                    Log.d(TAG,"Incoming Hf rejected");
+                    disconnectHfpNative(getByteAddress(device));
                 }
-                configAudioParameters();
+
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
                 Log.w(TAG, "Ignore HF DISCONNECTING event, device: " + device);