summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/hid
diff options
context:
space:
mode:
authorPriti Aghera <paghera@broadcom.com>2012-04-09 12:59:30 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-16 21:57:27 -0700
commit57addccaa75691f8eb6f35204d608a63695a9705 (patch)
tree9c9c606289b32fb0fc7599a6c65d170d544814e9 /src/com/android/bluetooth/hid
parentd570893c5ec3bc9fd1860aa0355c550d3a51f8dd (diff)
downloadandroid_packages_apps_Bluetooth-57addccaa75691f8eb6f35204d608a63695a9705.tar.gz
android_packages_apps_Bluetooth-57addccaa75691f8eb6f35204d608a63695a9705.tar.bz2
android_packages_apps_Bluetooth-57addccaa75691f8eb6f35204d608a63695a9705.zip
HID-PTS:Included API and calbabkcs for hid pts tests
Change-Id: I7f3b19dbcda24dbb0cd4700a54f7cd05e84d3745
Diffstat (limited to 'src/com/android/bluetooth/hid')
-rwxr-xr-x[-rw-r--r--]src/com/android/bluetooth/hid/HidService.java217
1 files changed, 217 insertions, 0 deletions
diff --git a/src/com/android/bluetooth/hid/HidService.java b/src/com/android/bluetooth/hid/HidService.java
index bc432befc..2bf580f2a 100644..100755
--- a/src/com/android/bluetooth/hid/HidService.java
+++ b/src/com/android/bluetooth/hid/HidService.java
@@ -12,6 +12,7 @@ import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothInputDevice;
import android.content.Intent;
+import android.os.Bundle;
import android.os.IBinder;
import android.os.Handler;
import android.os.Message;
@@ -46,6 +47,15 @@ public class HidService extends Service {
private static final int MESSAGE_CONNECT = 1;
private static final int MESSAGE_DISCONNECT = 2;
private static final int MESSAGE_CONNECT_STATE_CHANGED = 3;
+ private static final int MESSAGE_GET_PROTOCOL_MODE = 4;
+ private static final int MESSAGE_VIRTUAL_UNPLUG = 5;
+ private static final int MESSAGE_ON_GET_PROTOCOL_MODE = 6;
+ private static final int MESSAGE_SET_PROTOCOL_MODE = 7;
+ private static final int MESSAGE_GET_REPORT = 8;
+ private static final int MESSAGE_ON_GET_REPORT = 9;
+ private static final int MESSAGE_SET_REPORT = 10;
+ private static final int MESSAGE_SEND_DATA = 11;
+ private static final int MESSAGE_ON_VIRTUAL_UNPLUG = 12;
static {
classInitNative();
@@ -113,6 +123,80 @@ public class HidService extends Service {
broadcastConnectionState(device, convertHalState(halState));
}
break;
+ case MESSAGE_GET_PROTOCOL_MODE:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ if(!getProtocolModeNative(getByteAddress(device)) ) {
+ Log.e(TAG, "Error: get protocol mode native returns false");
+ }
+ }
+ break;
+
+ case MESSAGE_ON_GET_PROTOCOL_MODE:
+ {
+ BluetoothDevice device = getDevice((byte[]) msg.obj);
+ int protocolMode = msg.arg1;
+ broadcastProtocolMode(device, protocolMode);
+ }
+ break;
+ case MESSAGE_VIRTUAL_UNPLUG:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ if(!virtualUnPlugNative(getByteAddress(device))) {
+ Log.e(TAG, "Error: virtual unplug native returns false");
+ }
+ }
+ break;
+ case MESSAGE_SET_PROTOCOL_MODE:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ byte protocolMode = (byte) msg.arg1;
+ log("sending set protocol mode(" + protocolMode + ")");
+ if(!setProtocolModeNative(getByteAddress(device), protocolMode)) {
+ Log.e(TAG, "Error: set protocol mode native returns false");
+ }
+ }
+ break;
+ case MESSAGE_GET_REPORT:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ Bundle data = msg.getData();
+ byte reportType = data.getByte(BluetoothInputDevice.EXTRA_REPORT_TYPE);
+ byte reportId = data.getByte(BluetoothInputDevice.EXTRA_REPORT_ID);
+ int bufferSize = data.getInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE);
+ if(!getReportNative(getByteAddress(device), reportType, reportId, bufferSize)) {
+ Log.e(TAG, "Error: get report native returns false");
+ }
+ }
+ break;
+ case MESSAGE_SET_REPORT:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ Bundle data = msg.getData();
+ byte reportType = data.getByte(BluetoothInputDevice.EXTRA_REPORT_TYPE);
+ String report = data.getString(BluetoothInputDevice.EXTRA_REPORT);
+ if(!setReportNative(getByteAddress(device), reportType, report)) {
+ Log.e(TAG, "Error: set report native returns false");
+ }
+ }
+ break;
+ case MESSAGE_SEND_DATA:
+ {
+ BluetoothDevice device = (BluetoothDevice) msg.obj;
+ Bundle data = msg.getData();
+ String report = data.getString(BluetoothInputDevice.EXTRA_REPORT);
+ if(!sendDataNative(getByteAddress(device), report)) {
+ Log.e(TAG, "Error: send data native returns false");
+ }
+ }
+ break;
+ case MESSAGE_ON_VIRTUAL_UNPLUG:
+ {
+ BluetoothDevice device = getDevice((byte[]) msg.obj);
+ int status = msg.arg1;
+ broadcastVirtualUnplugStatus(device, status);
+ }
+ break;
}
}
};
@@ -195,8 +279,118 @@ public class HidService extends Service {
return priority;
}
+ public boolean getProtocolMode(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_PROTOCOL_MODE);
+ msg.obj = device;
+ mHandler.sendMessage(msg);
+ return true;
+ /* String objectPath = getObjectPathFromAddress(device.getAddress());
+ return getProtocolModeInputDeviceNative(objectPath);*/
+ }
+
+ public boolean virtualUnplug(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_VIRTUAL_UNPLUG);
+ msg.obj = device;
+ mHandler.sendMessage(msg);
+
+ return true;
+ }
+
+ public boolean setProtocolMode(BluetoothDevice device, int protocolMode) {
+ 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_PROTOCOL_MODE);
+ msg.obj = device;
+ msg.arg1 = protocolMode;
+ mHandler.sendMessage(msg);
+ return true ;
+ }
+
+ public boolean getReport(BluetoothDevice device, byte reportType, byte reportId, int bufferSize) {
+ 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_REPORT);
+ msg.obj = device;
+ Bundle data = new Bundle();
+ data.putByte(BluetoothInputDevice.EXTRA_REPORT_TYPE, reportType);
+ data.putByte(BluetoothInputDevice.EXTRA_REPORT_ID, reportId);
+ data.putInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE, bufferSize);
+ msg.setData(data);
+ mHandler.sendMessage(msg);
+ return true ;
+ }
+
+ public boolean setReport(BluetoothDevice device, byte reportType, String report) {
+ 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_REPORT);
+ msg.obj = device;
+ Bundle data = new Bundle();
+ data.putByte(BluetoothInputDevice.EXTRA_REPORT_TYPE, reportType);
+ data.putString(BluetoothInputDevice.EXTRA_REPORT, report);
+ msg.setData(data);
+ mHandler.sendMessage(msg);
+ return true ;
+
+ }
+
+ public boolean sendData(BluetoothDevice device, String report) {
+ enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+ int state = this.getConnectionState(device);
+ if (state != BluetoothInputDevice.STATE_CONNECTED) {
+ return false;
+ }
+
+ return sendDataNative(getByteAddress(device), report);
+ /*Message msg = mHandler.obtainMessage(MESSAGE_SEND_DATA);
+ msg.obj = device;
+ Bundle data = new Bundle();
+ data.putString(BluetoothInputDevice.EXTRA_REPORT, report);
+ 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;
+ msg.arg1 = mode;
+ mHandler.sendMessage(msg);
+ }
+
+ private void onVirtualUnplug(byte[] address, int status) {
+ Message msg = mHandler.obtainMessage(MESSAGE_ON_VIRTUAL_UNPLUG);
+ msg.obj = address;
+ msg.arg1 = status;
+ mHandler.sendMessage(msg);
+ }
+
private void onConnectStateChanged(byte[] address, int state) {
Message msg = mHandler.obtainMessage(MESSAGE_CONNECT_STATE_CHANGED);
msg.obj = address;
@@ -230,6 +424,23 @@ public class HidService extends Service {
}
}
+ private void broadcastProtocolMode(BluetoothDevice device, int protocolMode) {
+ Intent intent = new Intent(BluetoothInputDevice.ACTION_PROTOCOL_MODE_CHANGED);
+ intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+ intent.putExtra(BluetoothInputDevice.EXTRA_PROTOCOL_MODE, protocolMode);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ sendBroadcast(intent, BLUETOOTH_PERM);
+ if (DBG) log("Protocol Mode (" + device + "): " + protocolMode);
+ }
+
+ private void broadcastVirtualUnplugStatus(BluetoothDevice device, int status) {
+ Intent intent = new Intent(BluetoothInputDevice.ACTION_VIRTUAL_UNPLUG_STATUS);
+ intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+ intent.putExtra(BluetoothInputDevice.EXTRA_VIRTUAL_UNPLUG_STATUS, status);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ sendBroadcast(intent, BLUETOOTH_PERM);
+ }
+
private BluetoothDevice getDevice(byte[] address) {
return mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(address));
}
@@ -269,4 +480,10 @@ public class HidService extends Service {
private native void initializeNativeDataNative();
private native boolean connectHidNative(byte[] btAddress);
private native boolean disconnectHidNative(byte[] btAddress);
+ private native boolean getProtocolModeNative(byte[] btAddress);
+ private native boolean virtualUnPlugNative(byte[] btAddress);
+ private native boolean setProtocolModeNative(byte[] btAddress, byte protocolMode);
+ 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);
}