Merge "Update connect() api"
This commit is contained in:
@@ -184,13 +184,28 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect this device.
|
||||||
|
*
|
||||||
|
* @param connectAllProfiles {@code true} to connect all profile, {@code false} otherwise.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #connect()} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public void connect(boolean connectAllProfiles) {
|
public void connect(boolean connectAllProfiles) {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect this device.
|
||||||
|
*/
|
||||||
|
public void connect() {
|
||||||
if (!ensurePaired()) {
|
if (!ensurePaired()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mConnectAttempted = SystemClock.elapsedRealtime();
|
mConnectAttempted = SystemClock.elapsedRealtime();
|
||||||
connectWithoutResettingTimer(connectAllProfiles);
|
connectAllEnabledProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getHiSyncId() {
|
public long getHiSyncId() {
|
||||||
@@ -211,10 +226,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
void onBondingDockConnect() {
|
void onBondingDockConnect() {
|
||||||
// Attempt to connect if UUIDs are available. Otherwise,
|
// Attempt to connect if UUIDs are available. Otherwise,
|
||||||
// we will connect when the ACTION_UUID intent arrives.
|
// we will connect when the ACTION_UUID intent arrives.
|
||||||
connect(false);
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connectWithoutResettingTimer(boolean connectAllProfiles) {
|
private void connectAllEnabledProfiles() {
|
||||||
synchronized (mProfileLock) {
|
synchronized (mProfileLock) {
|
||||||
// Try to initialize the profiles if they were not.
|
// Try to initialize the profiles if they were not.
|
||||||
if (mProfiles.isEmpty()) {
|
if (mProfiles.isEmpty()) {
|
||||||
@@ -229,36 +244,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int preferredProfiles = 0;
|
mLocalAdapter.connectAllEnabledProfiles(mDevice);
|
||||||
for (LocalBluetoothProfile profile : mProfiles) {
|
|
||||||
if (connectAllProfiles ? profile.accessProfileEnabled()
|
|
||||||
: profile.isAutoConnectable()) {
|
|
||||||
if (profile.isPreferred(mDevice)) {
|
|
||||||
++preferredProfiles;
|
|
||||||
connectInt(profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (BluetoothUtils.D) Log.d(TAG, "Preferred profiles = " + preferredProfiles);
|
|
||||||
|
|
||||||
if (preferredProfiles == 0) {
|
|
||||||
connectAutoConnectableProfiles();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void connectAutoConnectableProfiles() {
|
|
||||||
if (!ensurePaired()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mProfileLock) {
|
|
||||||
for (LocalBluetoothProfile profile : mProfiles) {
|
|
||||||
if (profile.isAutoConnectable()) {
|
|
||||||
profile.setPreferred(mDevice, true);
|
|
||||||
connectInt(profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,7 +611,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
*/
|
*/
|
||||||
if (!mProfiles.isEmpty()
|
if (!mProfiles.isEmpty()
|
||||||
&& ((mConnectAttempted + timeout) > SystemClock.elapsedRealtime())) {
|
&& ((mConnectAttempted + timeout) > SystemClock.elapsedRealtime())) {
|
||||||
connectWithoutResettingTimer(false);
|
connectAllEnabledProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatchAttributesChanged();
|
dispatchAttributesChanged();
|
||||||
@@ -644,7 +630,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
if (bondState == BluetoothDevice.BOND_BONDED && mDevice.isBondingInitiatedLocally()) {
|
if (bondState == BluetoothDevice.BOND_BONDED && mDevice.isBondingInitiatedLocally()) {
|
||||||
connect(false);
|
connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
final CachedBluetoothDevice cachedDevice =
|
final CachedBluetoothDevice cachedDevice =
|
||||||
((BluetoothMediaDevice) device).getCachedDevice();
|
((BluetoothMediaDevice) device).getCachedDevice();
|
||||||
if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) {
|
if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) {
|
||||||
cachedDevice.connect(true);
|
cachedDevice.connect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class LocalMediaManagerTest {
|
|||||||
mLocalMediaManager.registerCallback(mCallback);
|
mLocalMediaManager.registerCallback(mCallback);
|
||||||
mLocalMediaManager.connectDevice(device);
|
mLocalMediaManager.connectDevice(device);
|
||||||
|
|
||||||
verify(cachedDevice).connect(true);
|
verify(cachedDevice).connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user