summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authorHemant Gupta <hemantg@codeaurora.org>2014-07-15 12:10:34 +0530
committerLinux Build Service Account <lnxbuild@localhost>2015-10-06 03:25:15 -0600
commit961bb14e998b1a064208fea199e81bb7b073bad4 (patch)
tree82507b2a3ae518ca8c8bee02065cbf0de00a5b03 /jni
parent8290a4653efb9fd8852b9cbb046e77080f82b9ef (diff)
downloadandroid_packages_apps_Bluetooth-961bb14e998b1a064208fea199e81bb7b073bad4.tar.gz
android_packages_apps_Bluetooth-961bb14e998b1a064208fea199e81bb7b073bad4.tar.bz2
android_packages_apps_Bluetooth-961bb14e998b1a064208fea199e81bb7b073bad4.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 'jni')
-rw-r--r--jni/com_android_bluetooth_hid.cpp75
1 files changed, 73 insertions, 2 deletions
diff --git a/jni/com_android_bluetooth_hid.cpp b/jni/com_android_bluetooth_hid.cpp
index adff0f58a..d91dbd23e 100644
--- a/jni/com_android_bluetooth_hid.cpp
+++ b/jni/com_android_bluetooth_hid.cpp
@@ -37,6 +37,7 @@ static jmethodID method_onConnectStateChanged;
static jmethodID method_onGetProtocolMode;
static jmethodID method_onGetReport;
static jmethodID method_onHandshake;
+static jmethodID method_onGetIdleTime;
static jmethodID method_onVirtualUnplug;
static const bthh_interface_t *sBluetoothHidInterface = NULL;
@@ -97,6 +98,29 @@ static void get_protocol_mode_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_st
sCallbackEnv->DeleteLocalRef(addr);
}
+static void get_idle_time_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_time) {
+ jbyteArray addr;
+
+ CHECK_CALLBACK_ENV
+ if (hh_status != BTHH_OK) {
+ ALOGE("BTHH Status is not OK!");
+ checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
+ return;
+ }
+
+ addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
+ if (!addr) {
+ ALOGE("Fail to new jbyteArray bd addr for get protocal mode callback");
+ checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
+ return;
+ }
+ sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr);
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onGetIdleTime, addr, (jint) idle_time);
+ checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
+ sCallbackEnv->DeleteLocalRef(addr);
+}
+
static void get_report_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t *rpt_data, int rpt_size) {
jbyteArray addr;
jbyteArray data;
@@ -187,7 +211,7 @@ static bthh_callbacks_t sBluetoothHidCallbacks = {
connection_state_callback,
NULL,
get_protocol_mode_callback,
- NULL,
+ get_idle_time_callback,
get_report_callback,
virtual_unplug_callback,
handshake_callback
@@ -202,6 +226,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
method_onConnectStateChanged = env->GetMethodID(clazz, "onConnectStateChanged", "([BI)V");
method_onGetProtocolMode = env->GetMethodID(clazz, "onGetProtocolMode", "([BI)V");
+ method_onGetIdleTime = env->GetMethodID(clazz, "onGetIdleTime", "([BI)V");
method_onGetReport = env->GetMethodID(clazz, "onGetReport", "([B[BI)V");
method_onHandshake = env->GetMethodID(clazz, "onHandshake", "([BI)V");
method_onVirtualUnplug = env->GetMethodID(clazz, "onVirtualUnplug", "([BI)V");
@@ -487,7 +512,7 @@ static jboolean sendDataNative(JNIEnv *env, jobject object, jbyteArray address,
const char *c_report = env->GetStringUTFChars(report, NULL);
if ( (status = sBluetoothHidInterface->send_data((bt_bdaddr_t *) addr, (char*) c_report)) !=
BT_STATUS_SUCCESS) {
- ALOGE("Failed set report, status: %d", status);
+ ALOGE("Failed send data, status: %d", status);
ret = JNI_FALSE;
}
env->ReleaseStringUTFChars(report, c_report);
@@ -497,6 +522,50 @@ static jboolean sendDataNative(JNIEnv *env, jobject object, jbyteArray address,
}
+static jboolean getIdleTimeNative(JNIEnv *env, jobject object, jbyteArray address) {
+ bt_status_t status;
+ jbyte *addr;
+ jboolean ret = JNI_TRUE;
+ if (!sBluetoothHidInterface) return JNI_FALSE;
+
+ addr = env->GetByteArrayElements(address, NULL);
+ if (!addr) {
+ ALOGE("Bluetooth device address null");
+ return JNI_FALSE;
+ }
+
+ if ( (status = sBluetoothHidInterface->get_idle_time((bt_bdaddr_t *) addr)) !=
+ BT_STATUS_SUCCESS) {
+ ALOGE("Failed get idle time, status: %d", status);
+ ret = JNI_FALSE;
+ }
+ env->ReleaseByteArrayElements(address, addr, 0);
+
+ return ret;
+}
+
+static jboolean setIdleTimeNative(JNIEnv *env, jobject object, jbyteArray address, jbyte idle_time) {
+ bt_status_t status;
+ jbyte *addr;
+ jboolean ret = JNI_TRUE;
+ if (!sBluetoothHidInterface) return JNI_FALSE;
+
+ addr = env->GetByteArrayElements(address, NULL);
+ if (!addr) {
+ ALOGE("Bluetooth device address null");
+ return JNI_FALSE;
+ }
+
+ if ( (status = sBluetoothHidInterface->set_idle_time((bt_bdaddr_t *) addr, idle_time)) !=
+ BT_STATUS_SUCCESS) {
+ ALOGE("Failed set idle time, status: %d", status);
+ ret = JNI_FALSE;
+ }
+ env->ReleaseByteArrayElements(address, addr, 0);
+
+ return ret;
+}
+
static JNINativeMethod sMethods[] = {
{"classInitNative", "()V", (void *) classInitNative},
{"initializeNative", "()V", (void *) initializeNative},
@@ -509,6 +578,8 @@ static JNINativeMethod sMethods[] = {
{"getReportNative", "([BBBI)Z", (void *) getReportNative},
{"setReportNative", "([BBLjava/lang/String;)Z", (void *) setReportNative},
{"sendDataNative", "([BLjava/lang/String;)Z", (void *) sendDataNative},
+ {"getIdleTimeNative", "([B)Z", (void *) getIdleTimeNative},
+ {"setIdleTimeNative", "([BB)Z", (void *) setIdleTimeNative},
};
int register_com_android_bluetooth_hid(JNIEnv* env)