summaryrefslogtreecommitdiffstats
path: root/cmds/hid/jni/com_android_commands_hid_Device.h
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2015-06-03 13:46:48 +0100
committerMichael Wright <michaelwr@google.com>2015-06-12 11:49:29 +0100
commit1f2c7688c1f673790d61645632ae5e1838f021a4 (patch)
tree73fcbb2d92ccc790cf7bf62b31c8c2d28f6264b3 /cmds/hid/jni/com_android_commands_hid_Device.h
parent6a5c0e10b192fe70e237c83bc752e2cbf66ffe0e (diff)
downloadframeworks_base-1f2c7688c1f673790d61645632ae5e1838f021a4.zip
frameworks_base-1f2c7688c1f673790d61645632ae5e1838f021a4.tar.gz
frameworks_base-1f2c7688c1f673790d61645632ae5e1838f021a4.tar.bz2
Add new `hid` command.
This allows the shell user to inject HID events. Change-Id: I37faff576299ff14092b61ed39f2a1c086f672a5
Diffstat (limited to 'cmds/hid/jni/com_android_commands_hid_Device.h')
-rw-r--r--cmds/hid/jni/com_android_commands_hid_Device.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/cmds/hid/jni/com_android_commands_hid_Device.h b/cmds/hid/jni/com_android_commands_hid_Device.h
new file mode 100644
index 0000000..6c5899e
--- /dev/null
+++ b/cmds/hid/jni/com_android_commands_hid_Device.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <memory>
+
+#include <jni.h>
+#include <utils/Looper.h>
+#include <utils/StrongPointer.h>
+
+namespace android {
+namespace uhid {
+
+class DeviceCallback {
+public:
+ DeviceCallback(JNIEnv* env, jobject callback);
+ ~DeviceCallback();
+
+ void onDeviceOpen();
+ void onDeviceError();
+
+private:
+ jobject mCallbackObject;
+};
+
+class Device {
+public:
+ static Device* open(int32_t id, const char* name, int32_t vid, int32_t pid,
+ std::unique_ptr<uint8_t[]> descriptor, size_t descriptorSize,
+ std::unique_ptr<DeviceCallback> callback, sp<Looper> looper);
+
+ Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback, sp<Looper> looper);
+ ~Device();
+
+ void sendReport(uint8_t* report, size_t reportSize);
+ void close();
+
+ int handleEvents(int events);
+
+private:
+ int32_t mId;
+ int mFd;
+ std::unique_ptr<DeviceCallback> mDeviceCallback;
+ sp<Looper> mLooper;
+};
+
+
+} // namespace uhid
+} // namespace android