Fix for When Hf is rejected the device should initiate A2dp if a2dp is enabled
Change-Id: I0716782a5308cc45297a30d0a7371286c75bfa52
This commit is contained in:
committed by
Matthew Xie
parent
802956ec9b
commit
b45e3c8fe9
11
src/com/android/settings/bluetooth/BluetoothEventManager.java
Normal file → Executable file
11
src/com/android/settings/bluetooth/BluetoothEventManager.java
Normal file → Executable file
@@ -21,6 +21,7 @@ import com.android.settings.R;
|
|||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -99,6 +100,10 @@ final class BluetoothEventManager {
|
|||||||
|
|
||||||
// Dock event broadcasts
|
// Dock event broadcasts
|
||||||
addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler());
|
addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler());
|
||||||
|
|
||||||
|
// Connect other profiles broadcast
|
||||||
|
addHandler(BluetoothProfile.ACTION_CONNECT_OTHER_PROFILES, new ConnectOtherProfilesHandler());
|
||||||
|
|
||||||
mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter);
|
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() {
|
boolean readPairedDevices() {
|
||||||
Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
|
Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
|
||||||
if (bondedDevices == null) {
|
if (bondedDevices == null) {
|
||||||
|
@@ -44,6 +44,7 @@ import java.util.List;
|
|||||||
final class LocalBluetoothProfileManager {
|
final class LocalBluetoothProfileManager {
|
||||||
private static final String TAG = "LocalBluetoothProfileManager";
|
private static final String TAG = "LocalBluetoothProfileManager";
|
||||||
private static final int CONNECT_HF_OR_A2DP = 1;
|
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
|
// 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.
|
// 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.
|
// 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<BluetoothDevice> 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<BluetoothDevice> 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.
|
* Mapping from profile name, e.g. "HEADSET" to profile object.
|
||||||
*/
|
*/
|
||||||
@@ -353,6 +378,19 @@ final class LocalBluetoothProfileManager {
|
|||||||
mA2dpProfile.enableAutoConnect(device,enable);
|
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.
|
// This is called by DockService, so check Headset and A2DP.
|
||||||
public synchronized boolean isManagerReady() {
|
public synchronized boolean isManagerReady() {
|
||||||
// Getting just the headset profile is fine for now. Will need to deal with A2DP
|
// Getting just the headset profile is fine for now. Will need to deal with A2DP
|
||||||
|
Reference in New Issue
Block a user