summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/hid
diff options
context:
space:
mode:
authorGanesh Ganapathi Batta <ganeshg@broadcom.com>2012-08-08 15:14:16 -0700
committerMatthew Xie <mattx@google.com>2012-08-14 00:32:12 -0700
commitca6110d57998fee7c7b572ca29061ee99a82ba37 (patch)
tree3e508cf443f6d84ae3e81011a1f054b11efd4bfa /src/com/android/bluetooth/hid
parent44d87716fccf8ff6f114db72711388fa57068078 (diff)
downloadandroid_packages_apps_Bluetooth-ca6110d57998fee7c7b572ca29061ee99a82ba37.tar.gz
android_packages_apps_Bluetooth-ca6110d57998fee7c7b572ca29061ee99a82ba37.tar.bz2
android_packages_apps_Bluetooth-ca6110d57998fee7c7b572ca29061ee99a82ba37.zip
Implement enableNoAutoconnect() for NFC handover
Implementation of BT enable in Quiet mode without initiating auto connect and not allowing Incoming HFP, A2DP and HID connections. Change-Id: I857aea8d95677f8287df4641ec0aeae58a9f7a99
Diffstat (limited to 'src/com/android/bluetooth/hid')
-rwxr-xr-xsrc/com/android/bluetooth/hid/HidService.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/com/android/bluetooth/hid/HidService.java b/src/com/android/bluetooth/hid/HidService.java
index 8bf9e1ff5..b60685611 100755
--- a/src/com/android/bluetooth/hid/HidService.java
+++ b/src/com/android/bluetooth/hid/HidService.java
@@ -26,6 +26,7 @@ import java.util.Map;
import com.android.bluetooth.Utils;
import android.content.pm.PackageManager;
import com.android.bluetooth.btservice.ProfileService;
+import com.android.bluetooth.btservice.AdapterService;
/**
* Provides Bluetooth Hid Host profile, as a service in
@@ -39,6 +40,7 @@ public class HidService extends ProfileService {
private Map<BluetoothDevice, Integer> mInputDevices;
private boolean mNativeAvailable;
private static HidService sHidService;
+ private BluetoothDevice mTargetDevice = null;
private static final int MESSAGE_CONNECT = 1;
private static final int MESSAGE_DISCONNECT = 2;
@@ -139,6 +141,7 @@ public class HidService extends ProfileService {
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED);
break;
}
+ mTargetDevice = device;
}
break;
case MESSAGE_DISCONNECT:
@@ -160,15 +163,22 @@ public class HidService extends ProfileService {
BluetoothInputDevice.STATE_DISCONNECTED :prevStateInteger;
if(DBG) Log.d(TAG, "MESSAGE_CONNECT_STATE_CHANGED newState:"+
convertHalState(halState)+", prevState:"+prevState);
- if(halState == CONN_STATE_CONNECTED &&
- prevState == BluetoothInputDevice.STATE_DISCONNECTED &&
- (BluetoothProfile.PRIORITY_OFF == getPriority(device) ||
- device.getBondState() == BluetoothDevice.BOND_NONE)) {
+ if(halState == CONN_STATE_CONNECTED &&
+ prevState == BluetoothInputDevice.STATE_DISCONNECTED &&
+ (!okToConnect(device))) {
Log.d(TAG,"Incoming HID connection rejected");
disconnectHidNative(Utils.getByteAddress(device));
} else {
broadcastConnectionState(device, convertHalState(halState));
}
+ if (halState != CONN_STATE_CONNECTING) {
+ mTargetDevice = null;
+ }
+ else {
+ // CONN_STATE_CONNECTING is received only during
+ // local initiated connection.
+ mTargetDevice = device;
+ }
}
break;
case MESSAGE_GET_PROTOCOL_MODE:
@@ -573,6 +583,18 @@ public class HidService extends ProfileService {
sendBroadcast(intent, BLUETOOTH_PERM);
}
+ private boolean okToConnect(BluetoothDevice device) {
+ AdapterService adapterService = AdapterService.getAdapterService();
+ //check if it is inbound connection in Quiet mode, priority and Bond status
+ //to decide if its ok to allow this connection
+ if((adapterService == null)||
+ ((adapterService.isQuietModeEnabled()) &&(mTargetDevice == null)) ||
+ (BluetoothProfile.PRIORITY_OFF == getPriority(device)) ||
+ (device.getBondState() == BluetoothDevice.BOND_NONE))
+ return false;
+
+ return true;
+ }
private static int convertHalState(int halState) {
switch (halState) {
case CONN_STATE_CONNECTED: