}
for (BluetoothDevice device : bondedDevices) {
- debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " +
- device.toString());
- headsetClientService.connect(device);
+ if (headsetClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT){
+ debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " +
+ device.toString());
+ headsetClientService.connect(device);
+ }
}
}
}
for (BluetoothDevice device : bondedDevices) {
- debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString());
- a2dpSinkService.connect(device);
+ if (a2dpSinkService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) {
+ debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString());
+ a2dpSinkService.connect(device);
+ }
}
}
return;
}
for (BluetoothDevice device : bondedDevices) {
- if (pbapClientService.getPriority(device) >= BluetoothProfile.PRIORITY_ON ){
- debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString());
+ if (pbapClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) {
+ debugLog("autoConnectPbapClient() - Connecting PBAP Client with " +
+ device.toString());
pbapClientService.connect(device);
}
}
}
private void adjustOtherHeadsetPriorities(HeadsetService hsService,
- List<BluetoothDevice> connectedDeviceList) {
+ List<BluetoothDevice> connectedDeviceList) {
for (BluetoothDevice device : getBondedDevices()) {
if (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
!connectedDeviceList.contains(device)) {
}
}
- void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){
- if (profileId == BluetoothProfile.HEADSET) {
- HeadsetService hsService = HeadsetService.getHeadsetService();
- List<BluetoothDevice> deviceList = hsService.getConnectedDevices();
- if ((hsService != null) &&
- (BluetoothProfile.PRIORITY_AUTO_CONNECT != hsService.getPriority(device))){
- adjustOtherHeadsetPriorities(hsService, deviceList);
- hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ private void adjustOtherSinkPriorities(A2dpService a2dpService,
+ BluetoothDevice connectedDevice) {
+ for (BluetoothDevice device : getBondedDevices()) {
+ if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+ !device.equals(connectedDevice)) {
+ a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON);
}
}
+ }
+
+ private void adjustOtherHeadsetClientPriorities(HeadsetClientService hsService,
+ BluetoothDevice connectedDevice) {
+ for (BluetoothDevice device : getBondedDevices()) {
+ if (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+ !device.equals(connectedDevice)) {
+ hsService.setPriority(device, BluetoothProfile.PRIORITY_ON);
+ }
+ }
+ }
+
+ private void adjustOtherA2dpSinkPriorities(A2dpSinkService a2dpService,
+ BluetoothDevice connectedDevice) {
+ for (BluetoothDevice device : getBondedDevices()) {
+ if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+ !device.equals(connectedDevice)) {
+ a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON);
+ }
+ }
+ }
+
+ private void adjustOtherPbapClientPriorities(PbapClientService pbapService,
+ BluetoothDevice connectedDevice) {
+ for (BluetoothDevice device : getBondedDevices()) {
+ if (pbapService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+ !device.equals(connectedDevice)) {
+ pbapService.setPriority(device, BluetoothProfile.PRIORITY_ON);
+ }
+ }
+ }
+
+ void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){
+ switch (profileId) {
+ case BluetoothProfile.HEADSET:
+ HeadsetService hsService = HeadsetService.getHeadsetService();
+ List<BluetoothDevice> deviceList = hsService.getConnectedDevices();
+ if ((hsService != null) &&
+ (BluetoothProfile.PRIORITY_AUTO_CONNECT != hsService.getPriority(device))) {
+ adjustOtherHeadsetPriorities(hsService, deviceList);
+ hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ }
+ break;
+
+ case BluetoothProfile.A2DP:
+ A2dpService a2dpService = A2dpService.getA2dpService();
+ if ((a2dpService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT !=
+ a2dpService.getPriority(device))) {
+ adjustOtherSinkPriorities(a2dpService, device);
+ a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ }
+ break;
+
+ case BluetoothProfile.A2DP_SINK:
+ A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService();
+ if ((a2dpSinkService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT !=
+ a2dpSinkService.getPriority(device))) {
+ adjustOtherA2dpSinkPriorities(a2dpSinkService, device);
+ a2dpSinkService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ }
+ break;
+
+ case BluetoothProfile.HEADSET_CLIENT:
+ HeadsetClientService headsetClientService =
+ HeadsetClientService.getHeadsetClientService();
+ if ((headsetClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT !=
+ headsetClientService.getPriority(device))) {
+ adjustOtherHeadsetClientPriorities(headsetClientService, device);
+ headsetClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ }
+ break;
+
+ case BluetoothProfile.PBAP_CLIENT:
+ PbapClientService pbapClientService = PbapClientService.getPbapClientService();
+ if ((pbapClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT !=
+ pbapClientService.getPriority(device))) {
+ adjustOtherPbapClientPriorities(pbapClientService, device);
+ pbapClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
+ }
+ break;
+
+ default:
+ Log.w(TAG, "Attempting to set Auto Connect priority on invalid profile");
+ break;
+ }
}
boolean cancelBondProcess(BluetoothDevice device) {
return true;
}
- int getBondState(BluetoothDevice device) {
+ int getBondState(BluetoothDevice device) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
if (deviceProp == null) {
*/
public class PbapPCEClient implements PbapHandler.PbapListener {
private static final String TAG = "PbapPCEClient";
- private static final boolean DBG = true;
+ private static final boolean DBG = false;
private final Queue<PullRequest> mPendingRequests = new ArrayDeque<PullRequest>();
private BluetoothDevice mDevice;
private BluetoothPbapClient mClient;
if (oldState != BluetoothProfile.STATE_DISCONNECTED) {
return;
}
- onConnectionStateChanged(device, oldState,
- BluetoothProfile.STATE_CONNECTING);
handleConnect(device);
} else {
Log.e(TAG, "Invalid instance in Connection Handler:Connect");
}
private void handleConnect(BluetoothDevice device) {
+ Log.d(TAG,"HANDLECONNECT" + device);
if (device == null) {
throw new IllegalStateException(TAG + ":Connect with null device!");
} else if (mDevice != null && !mDevice.equals(device)) {
}
// Update the device.
mDevice = device;
- mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler);
+ onConnectionStateChanged(mDevice,BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
// Add the account. This should give us a place to stash the data.
- mAccount = new Account(device.getAddress(), mContext.getString(R.string.pbap_account_type));
- mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT,mAccount).sendToTarget();
+ mAccount = new Account(device.getAddress(),
+ mContext.getString(R.string.pbap_account_type));
+ mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT, mAccount)
+ .sendToTarget();
+ mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler);
downloadPhoneBook();
downloadCallLogs();
mClient.connect();
}
return true;
}
- throw new IllegalStateException(TAG + ":Failed to add account!");
+ return false;
}
private boolean removeAccount(Account acc) {