am dd79a33b
: Auto-connect Bluetooth device only when user initiates pairing.
Merge commit 'dd79a33ba53fec530094f4d2fe37f0538530d9f8' into gingerbread-plus-aosp * commit 'dd79a33ba53fec530094f4d2fe37f0538530d9f8': Auto-connect Bluetooth device only when user initiates pairing.
This commit is contained in:
@@ -83,7 +83,7 @@ public class BluetoothEventRedirector {
|
|||||||
if (bondState == BluetoothDevice.BOND_NONE) {
|
if (bondState == BluetoothDevice.BOND_NONE) {
|
||||||
if (device.isBluetoothDock()) {
|
if (device.isBluetoothDock()) {
|
||||||
// After a dock is unpaired, we will forget the
|
// After a dock is unpaired, we will forget the
|
||||||
// setttings
|
// settings
|
||||||
mManager.removeDockAutoConnectSetting(device.getAddress());
|
mManager.removeDockAutoConnectSetting(device.getAddress());
|
||||||
|
|
||||||
// if the device is undocked, remove it from the list as
|
// if the device is undocked, remove it from the list as
|
||||||
|
@@ -88,6 +88,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
// See mConnectAttempted
|
// See mConnectAttempted
|
||||||
private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
|
private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
|
||||||
|
|
||||||
|
/** Auto-connect after pairing only if locally initiated. */
|
||||||
|
private boolean mConnectAfterPairing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the current device and profile for logging.
|
* Describes the current device and profile for logging.
|
||||||
@@ -362,7 +364,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
if (!mDevice.createBond()) {
|
if (!mDevice.createBond()) {
|
||||||
mLocalManager.showError(mDevice, R.string.bluetooth_error_title,
|
mLocalManager.showError(mDevice, R.string.bluetooth_error_title,
|
||||||
R.string.bluetooth_pairing_error_message);
|
R.string.bluetooth_pairing_error_message);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mConnectAfterPairing = true; // auto-connect after pairing
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unpair() {
|
public void unpair() {
|
||||||
@@ -608,9 +613,19 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
public void onBondingStateChanged(int bondState) {
|
public void onBondingStateChanged(int bondState) {
|
||||||
if (bondState == BluetoothDevice.BOND_NONE) {
|
if (bondState == BluetoothDevice.BOND_NONE) {
|
||||||
mProfiles.clear();
|
mProfiles.clear();
|
||||||
|
mConnectAfterPairing = false; // cancel auto-connect
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
|
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||||
|
if (mDevice.isBluetoothDock()) {
|
||||||
|
onBondingDockConnect();
|
||||||
|
} else if (mConnectAfterPairing) {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
mConnectAfterPairing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBtClass(BluetoothClass btClass) {
|
public void setBtClass(BluetoothClass btClass) {
|
||||||
|
@@ -182,15 +182,6 @@ public class CachedBluetoothDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cachedDevice.onBondingStateChanged(bondState);
|
cachedDevice.onBondingStateChanged(bondState);
|
||||||
|
|
||||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
|
||||||
// Auto-connect after pairing
|
|
||||||
if (!device.isBluetoothDock()) {
|
|
||||||
cachedDevice.connect();
|
|
||||||
} else {
|
|
||||||
cachedDevice.onBondingDockConnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -72,7 +72,7 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
Log.w(TAG, "Activity started without a remote blueototh device");
|
Log.w(TAG, "Activity started without a remote Bluetooth device");
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,9 +45,8 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
|
private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
|
||||||
|
|
||||||
|
/** Singleton instance. */
|
||||||
private static LocalBluetoothManager INSTANCE;
|
private static LocalBluetoothManager INSTANCE;
|
||||||
/** Used when obtaining a reference to the singleton instance. */
|
|
||||||
private static Object INSTANCE_LOCK = new Object();
|
|
||||||
private boolean mInitialized;
|
private boolean mInitialized;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -86,7 +85,7 @@ public class LocalBluetoothManager {
|
|||||||
private long mLastScan;
|
private long mLastScan;
|
||||||
|
|
||||||
public static LocalBluetoothManager getInstance(Context context) {
|
public static LocalBluetoothManager getInstance(Context context) {
|
||||||
synchronized (INSTANCE_LOCK) {
|
synchronized (LocalBluetoothManager.class) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
INSTANCE = new LocalBluetoothManager();
|
INSTANCE = new LocalBluetoothManager();
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ public class SettingsBtStatus {
|
|||||||
|
|
||||||
public static final int CONNECTION_STATUS_UNKNOWN = 0;
|
public static final int CONNECTION_STATUS_UNKNOWN = 0;
|
||||||
public static final int CONNECTION_STATUS_ACTIVE = 1;
|
public static final int CONNECTION_STATUS_ACTIVE = 1;
|
||||||
/** Use {@link #isConnected} to check for the connected state */
|
/** Use {@link #isConnectionStatusConnected} to check for the connected state */
|
||||||
public static final int CONNECTION_STATUS_CONNECTED = 2;
|
public static final int CONNECTION_STATUS_CONNECTED = 2;
|
||||||
public static final int CONNECTION_STATUS_CONNECTING = 3;
|
public static final int CONNECTION_STATUS_CONNECTING = 3;
|
||||||
public static final int CONNECTION_STATUS_DISCONNECTED = 4;
|
public static final int CONNECTION_STATUS_DISCONNECTED = 4;
|
||||||
|
Reference in New Issue
Block a user