summaryrefslogtreecommitdiffstats
path: root/core/java/android/server/BluetoothService.java
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-04-18 13:01:15 -0700
committerMartijn Coenen <maco@google.com>2012-04-23 16:25:30 -0700
commit6c614b7e596d2c7c410adec727bf787834cb258b (patch)
tree348d932bcffde5280bf087b9b8df3b0d7fd89ada /core/java/android/server/BluetoothService.java
parentf913d002a64b9d124ef54f3b71bcd13f4a6c2768 (diff)
downloadframeworks_base-6c614b7e596d2c7c410adec727bf787834cb258b.zip
frameworks_base-6c614b7e596d2c7c410adec727bf787834cb258b.tar.gz
frameworks_base-6c614b7e596d2c7c410adec727bf787834cb258b.tar.bz2
Allow enabling Bluetooth without auto-connecting.
This is a feature used for NFC-to-Bluetooth handover: we want to enable BT for file transfer, and disconnect it when we're done. During this period we don't want to auto-connect other devices - it should be transparent to the user that Bluetooth is used. Also, don't allow A2DP/HSP incoming connections. Change-Id: I0a03e8084c439b1271b6a80f4d9da5aacfe19c45
Diffstat (limited to 'core/java/android/server/BluetoothService.java')
-rwxr-xr-xcore/java/android/server/BluetoothService.java46
1 files changed, 44 insertions, 2 deletions
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 36c0189..7a97455 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -165,6 +165,8 @@ public class BluetoothService extends IBluetooth.Stub {
private static String mDockAddress;
private String mDockPin;
+ private boolean mAllowConnect = true;
+
private int mAdapterConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
private BluetoothPanProfileHandler mBluetoothPanProfileHandler;
private BluetoothInputProfileHandler mBluetoothInputProfileHandler;
@@ -472,7 +474,7 @@ public class BluetoothService extends IBluetooth.Stub {
/** Bring up BT and persist BT on in settings */
public boolean enable() {
- return enable(true);
+ return enable(true, true);
}
/**
@@ -480,9 +482,11 @@ public class BluetoothService extends IBluetooth.Stub {
* This turns on/off the underlying hardware.
*
* @param saveSetting If true, persist the new state of BT in settings
+ * @param allowConnect If true, auto-connects device when BT is turned on
+ * and allows incoming A2DP/HSP connections
* @return True on success (so far)
*/
- public synchronized boolean enable(boolean saveSetting) {
+ public synchronized boolean enable(boolean saveSetting, boolean allowConnect) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
@@ -490,11 +494,29 @@ public class BluetoothService extends IBluetooth.Stub {
if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
return false;
}
+ mAllowConnect = allowConnect;
mBluetoothState.sendMessage(BluetoothAdapterStateMachine.USER_TURN_ON, saveSetting);
return true;
}
/**
+ * Enable this Bluetooth device, asynchronously, but does not
+ * auto-connect devices. In this state the Bluetooth adapter
+ * also does not allow incoming A2DP/HSP connections (that
+ * must go through this service), but does allow communication
+ * on RFCOMM sockets implemented outside of this service (ie BTOPP).
+ * This method is used to temporarily enable Bluetooth
+ * for data transfer, without changing
+ *
+ * This turns on/off the underlying hardware.
+ *
+ * @return True on success (so far)
+ */
+ public boolean enableNoAutoConnect() {
+ return enable(false, false);
+ }
+
+ /**
* Turn on Bluetooth Module, Load firmware, and do all the preparation
* needed to get the Bluetooth Module ready but keep it not discoverable
* and not connectable.
@@ -2441,6 +2463,13 @@ public class BluetoothService extends IBluetooth.Stub {
}
private void autoConnect() {
+ synchronized (this) {
+ if (!mAllowConnect) {
+ Log.d(TAG, "Not auto-connecting devices because of temporary BT on state.");
+ return;
+ }
+ }
+
String[] bonds = getKnownDevices();
if (bonds == null) {
return;
@@ -2457,6 +2486,12 @@ public class BluetoothService extends IBluetooth.Stub {
}
public boolean notifyIncomingConnection(String address, boolean rejected) {
+ synchronized (this) {
+ if (!mAllowConnect) {
+ Log.d(TAG, "Not allowing incoming connection because of temporary BT on state.");
+ return false;
+ }
+ }
BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
if (state != null) {
Message msg = new Message();
@@ -2478,6 +2513,13 @@ public class BluetoothService extends IBluetooth.Stub {
}
/*package*/ boolean notifyIncomingA2dpConnection(String address, boolean rejected) {
+ synchronized (this) {
+ if (!mAllowConnect) {
+ Log.d(TAG, "Not allowing a2dp connection because of temporary BT on state.");
+ return false;
+ }
+ }
+
BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
if (state != null) {
Message msg = new Message();