summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/hid
diff options
context:
space:
mode:
authorHemant Gupta <hemantg@codeaurora.org>2014-07-15 12:10:34 +0530
committerLinux Build Service Account <lnxbuild@localhost>2016-08-24 08:16:59 -0600
commitb6c1b44f102a7b4e7074673a3b01c61858918d36 (patch)
treed8b62bc438ec142ed1dbe8933eb97c89f61fc2ba /src/com/android/bluetooth/hid
parent05a21c105f3670c5010922d2cb235b2ef3c86c39 (diff)
downloadandroid_packages_apps_Bluetooth-b6c1b44f102a7b4e7074673a3b01c61858918d36.tar.gz
android_packages_apps_Bluetooth-b6c1b44f102a7b4e7074673a3b01c61858918d36.tar.bz2
android_packages_apps_Bluetooth-b6c1b44f102a7b4e7074673a3b01c61858918d36.zip
HID: Add support for Set Idle and Get Idle commands (4/4)
This patch adds support for Get Idle and Set Idle command handling in jni and HidService which will be used to provide interface for sending thse commands to HID Remote device. Without this support TC_HOS_HID_BV_05/06 PTS test cases for HID 1.0 cannot be passed. Change-Id: I066d47c022905a39c11d365a9d26d128f94fe2f6 CRs-Fixed: 522511
Diffstat (limited to 'src/com/android/bluetooth/hid')
-rw-r--r--[-rwxr-xr-x]src/com/android/bluetooth/hid/HidService.java88
1 files changed, 87 insertions, 1 deletions
diff --git a/src/com/android/bluetooth/hid/HidService.java b/src/com/android/bluetooth/hid/HidService.java
index be769fc80..3bec957f7 100755..100644
--- a/src/com/android/bluetooth/hid/HidService.java
+++ b/src/com/android/bluetooth/hid/HidService.java
@@ -68,6 +68,9 @@ public class HidService extends ProfileService {
private static final int MESSAGE_SEND_DATA = 11;
private static final int MESSAGE_ON_VIRTUAL_UNPLUG = 12;
private static final int MESSAGE_ON_HANDSHAKE = 13;
+ private static final int MESSAGE_GET_IDLE_TIME = 14;
+ private static final int MESSAGE_ON_GET_IDLE_TIME = 15;
+ private static final int MESSAGE_SET_IDLE_TIME = 16;
static {
classInitNative();
@@ -285,6 +288,31 @@ public class HidService extends ProfileService {
broadcastVirtualUnplugStatus(device, status);
}
break;
+ case MESSAGE_GET_IDLE_TIME:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ if(!getIdleTimeNative(Utils.getByteAddress(device)) ) {
+ Log.e(TAG, "Error: get idle time native returns false");
+ }
+ }
+ break;
+ case MESSAGE_ON_GET_IDLE_TIME:
+ {
+ BluetoothDevice device = getDevice((byte[]) msg.obj);
+ int idleTime = msg.arg1;
+ broadcastIdleTime(device, idleTime);
+ }
+ break;
+ case MESSAGE_SET_IDLE_TIME:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ Bundle data = msg.getData();
+ byte idleTime = data.getByte(BluetoothInputDevice.EXTRA_IDLE_TIME);
+ if(!setIdleTimeNative(Utils.getByteAddress(device), idleTime)) {
+ Log.e(TAG, "Error: get idle time native returns false");
+ }
+ }
+ break;
}
}
};
@@ -392,6 +420,18 @@ public class HidService extends ProfileService {
if (service == null) return false;
return service.sendData(device, report);
}
+
+ public boolean setIdleTime(BluetoothDevice device, byte idleTime) {
+ HidService service = getService();
+ if (service == null) return false;
+ return service.setIdleTime(device, idleTime);
+ }
+
+ public boolean getIdleTime(BluetoothDevice device) {
+ HidService service = getService();
+ if (service == null) return false;
+ return service.getIdleTime(device);
+ }
};
//APIs
@@ -554,7 +594,35 @@ public class HidService extends ProfileService {
mHandler.sendMessage(msg);
return true ;*/
}
-
+
+ boolean getIdleTime(BluetoothDevice device) {
+ enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+ int state = this.getConnectionState(device);
+ if (state != BluetoothInputDevice.STATE_CONNECTED) {
+ return false;
+ }
+ Message msg = mHandler.obtainMessage(MESSAGE_GET_IDLE_TIME,device);
+ mHandler.sendMessage(msg);
+ return true;
+ }
+
+ boolean setIdleTime(BluetoothDevice device, byte idleTime) {
+ enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+ int state = this.getConnectionState(device);
+ if (state != BluetoothInputDevice.STATE_CONNECTED) {
+ return false;
+ }
+ Message msg = mHandler.obtainMessage(MESSAGE_SET_IDLE_TIME);
+ msg.obj = device;
+ Bundle data = new Bundle();
+ data.putByte(BluetoothInputDevice.EXTRA_IDLE_TIME, idleTime);
+ msg.setData(data);
+ mHandler.sendMessage(msg);
+ return true;
+ }
+
private void onGetProtocolMode(byte[] address, int mode) {
Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_PROTOCOL_MODE);
msg.obj = address;
@@ -562,6 +630,13 @@ public class HidService extends ProfileService {
mHandler.sendMessage(msg);
}
+ private void onGetIdleTime(byte[] address, int idleTime) {
+ Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_IDLE_TIME);
+ msg.obj = address;
+ msg.arg1 = idleTime;
+ mHandler.sendMessage(msg);
+ }
+
private void onGetReport(byte[] address, byte[] report, int rpt_size) {
Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_REPORT);
msg.obj = address;
@@ -652,6 +727,15 @@ public class HidService extends ProfileService {
sendBroadcast(intent, BLUETOOTH_PERM);
}
+ private void broadcastIdleTime(BluetoothDevice device, int idleTime) {
+ Intent intent = new Intent(BluetoothInputDevice.ACTION_IDLE_TIME_CHANGED);
+ intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+ intent.putExtra(BluetoothInputDevice.EXTRA_IDLE_TIME, idleTime);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ sendBroadcast(intent, BLUETOOTH_PERM);
+ if (DBG) log("Idle time (" + device + "): " + idleTime);
+ }
+
private boolean okToConnect(BluetoothDevice device) {
AdapterService adapterService = AdapterService.getAdapterService();
//check if it is inbound connection in Quiet mode, priority and Bond status
@@ -708,4 +792,6 @@ public class HidService extends ProfileService {
private native boolean getReportNative(byte[]btAddress, byte reportType, byte reportId, int bufferSize);
private native boolean setReportNative(byte[] btAddress, byte reportType, String report);
private native boolean sendDataNative(byte[] btAddress, String report);
+ private native boolean setIdleTimeNative(byte[] btAddress, byte idleTime);
+ private native boolean getIdleTimeNative(byte[] btAddress);
}