From b45e3c8fe9c08851800a6afa362d975944c0cd46 Mon Sep 17 00:00:00 2001 From: Swaminatha Balaji Date: Mon, 25 Jun 2012 04:04:41 -0700 Subject: [PATCH] Fix for When Hf is rejected the device should initiate A2dp if a2dp is enabled Change-Id: I0716782a5308cc45297a30d0a7371286c75bfa52 --- .../bluetooth/BluetoothEventManager.java | 11 ++++++ .../LocalBluetoothProfileManager.java | 38 +++++++++++++++++++ 2 files changed, 49 insertions(+) mode change 100644 => 100755 src/com/android/settings/bluetooth/BluetoothEventManager.java diff --git a/src/com/android/settings/bluetooth/BluetoothEventManager.java b/src/com/android/settings/bluetooth/BluetoothEventManager.java old mode 100644 new mode 100755 index a23e0aa973a..bc4bfcac6e0 --- a/src/com/android/settings/bluetooth/BluetoothEventManager.java +++ b/src/com/android/settings/bluetooth/BluetoothEventManager.java @@ -21,6 +21,7 @@ import com.android.settings.R; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -99,6 +100,10 @@ final class BluetoothEventManager { // Dock event broadcasts addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler()); + + // Connect other profiles broadcast + addHandler(BluetoothProfile.ACTION_CONNECT_OTHER_PROFILES, new ConnectOtherProfilesHandler()); + mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter); } @@ -368,6 +373,12 @@ final class BluetoothEventManager { } } + private class ConnectOtherProfilesHandler implements Handler { + public void onReceive(Context context, Intent intent, BluetoothDevice device) { + mProfileManager.handleConnectOtherProfiles(device); + } + } + boolean readPairedDevices() { Set bondedDevices = mLocalAdapter.getBondedDevices(); if (bondedDevices == null) { diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 191cf70bc50..12955a2c6a9 100755 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -44,6 +44,7 @@ import java.util.List; final class LocalBluetoothProfileManager { private static final String TAG = "LocalBluetoothProfileManager"; private static final int CONNECT_HF_OR_A2DP = 1; + private static final int CONNECT_OTHER_PROFILES = 2; // If either a2dp or hf is connected and if the other profile conneciton is not // happening with the timeout , the other profile(a2dp or hf) will be inititate connection. // Give reasonable timeout for the device to initiate the other profile connection. @@ -105,6 +106,30 @@ final class LocalBluetoothProfileManager { } }; + private final Handler connectOtherProfilesHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + synchronized (this) { + // Connect all the profiles which are enabled + // Right now hf/a2dp profiles connect is handled here + List hfConnDevList= mHeadsetProfile.getConnectedDevices(); + + if (hfConnDevList.isEmpty() && mHeadsetProfile.isPreferred((BluetoothDevice)msg.obj)) + mHeadsetProfile.connect((BluetoothDevice)msg.obj); + else + Log.d(TAG,"Hf device is not preferred or already Hf connected device exist"); + + List a2dpConnDevList= mA2dpProfile.getConnectedDevices(); + + if (a2dpConnDevList.isEmpty() && mA2dpProfile.isPreferred((BluetoothDevice)msg.obj)) + mA2dpProfile.connect((BluetoothDevice)msg.obj); + else + Log.d(TAG,"A2dp device is not preferred or already a2dp connected device exist"); + + } + } + }; + /** * Mapping from profile name, e.g. "HEADSET" to profile object. */ @@ -353,6 +378,19 @@ final class LocalBluetoothProfileManager { mA2dpProfile.enableAutoConnect(device,enable); } + public void handleConnectOtherProfiles(BluetoothDevice device) { + if (device != null){ + // Remove previous messages if any + connectOtherProfilesHandler.removeMessages(CONNECT_OTHER_PROFILES); + Message mes = connectOtherProfilesHandler.obtainMessage(CONNECT_OTHER_PROFILES); + mes.obj = device; + connectOtherProfilesHandler.sendMessageDelayed(mes,CONNECT_HF_OR_A2DP_TIMEOUT); + Log.i(TAG,"Message posted for connection other Profiles "); + } else { + Log.e(TAG,"Device = Null received in handleConnectOtherProfiles "); + } + } + // This is called by DockService, so check Headset and A2DP. public synchronized boolean isManagerReady() { // Getting just the headset profile is fine for now. Will need to deal with A2DP