blob: 892c7cd12953b25e87a0d1ea08449657e2f33a9e [file] [log] [blame]
Michael Wright1f2c7682015-06-03 13:46:48 +01001/*
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>
Siarhei Vishniakou6c6dd652018-07-16 17:01:40 +010018#include <vector>
Michael Wright1f2c7682015-06-03 13:46:48 +010019
20#include <jni.h>
Michael Wright1f2c7682015-06-03 13:46:48 +010021
22namespace android {
23namespace uhid {
24
25class DeviceCallback {
26public:
27 DeviceCallback(JNIEnv* env, jobject callback);
28 ~DeviceCallback();
29
30 void onDeviceOpen();
Kim Lowd47c0132018-11-09 17:15:13 -080031 void onDeviceGetReport(uint32_t requestId, uint8_t reportId);
Michael Wright1f2c7682015-06-03 13:46:48 +010032 void onDeviceError();
33
34private:
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070035 JNIEnv* getJNIEnv();
Michael Wright1f2c7682015-06-03 13:46:48 +010036 jobject mCallbackObject;
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070037 JavaVM* mJavaVM;
Michael Wright1f2c7682015-06-03 13:46:48 +010038};
39
40class Device {
41public:
42 static Device* open(int32_t id, const char* name, int32_t vid, int32_t pid,
Siarhei Vishniakou6c6dd652018-07-16 17:01:40 +010043 std::vector<uint8_t> descriptor, std::unique_ptr<DeviceCallback> callback);
Michael Wright1f2c7682015-06-03 13:46:48 +010044
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070045 Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback);
Michael Wright1f2c7682015-06-03 13:46:48 +010046 ~Device();
47
Siarhei Vishniakou6c6dd652018-07-16 17:01:40 +010048 void sendReport(const std::vector<uint8_t>& report) const;
Kim Lowd47c0132018-11-09 17:15:13 -080049 void sendGetFeatureReportReply(uint32_t id, const std::vector<uint8_t>& report) const;
Michael Wright1f2c7682015-06-03 13:46:48 +010050 void close();
51
52 int handleEvents(int events);
53
54private:
55 int32_t mId;
56 int mFd;
57 std::unique_ptr<DeviceCallback> mDeviceCallback;
Michael Wright1f2c7682015-06-03 13:46:48 +010058};
59
60
61} // namespace uhid
62} // namespace android