• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <memory>
18 #include <vector>
19 
20 #include <jni.h>
21 
22 namespace android {
23 namespace uhid {
24 
25 class DeviceCallback {
26 public:
27     DeviceCallback(JNIEnv* env, jobject callback);
28     ~DeviceCallback();
29 
30     void onDeviceOpen();
31     void onDeviceGetReport(uint32_t requestId, uint8_t reportId);
32     void onDeviceError();
33 
34 private:
35     JNIEnv* getJNIEnv();
36     jobject mCallbackObject;
37     JavaVM* mJavaVM;
38 };
39 
40 class Device {
41 public:
42     static Device* open(int32_t id, const char* name, int32_t vid, int32_t pid,
43             std::vector<uint8_t> descriptor, std::unique_ptr<DeviceCallback> callback);
44 
45     Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback);
46     ~Device();
47 
48     void sendReport(const std::vector<uint8_t>& report) const;
49     void sendGetFeatureReportReply(uint32_t id, const std::vector<uint8_t>& report) const;
50     void close();
51 
52     int handleEvents(int events);
53 
54 private:
55     int32_t mId;
56     int mFd;
57     std::unique_ptr<DeviceCallback> mDeviceCallback;
58 };
59 
60 
61 } // namespace uhid
62 } // namespace android
63