1 /*
2  * Copyright 2023 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 #pragma once
18 
19 #include <android-base/result.h>
20 #include <input/Input.h>
21 #include "rust/cxx.h"
22 
23 namespace android {
24 
25 namespace input {
26 namespace verifier {
27 struct InputVerifier;
28 }
29 } // namespace input
30 
31 /*
32  * Crash if the provided touch stream is inconsistent.
33  * This class is a pass-through to the rust implementation of InputVerifier.
34  * The rust class could also be used directly, but it would be less convenient.
35  * We can't directly invoke the rust methods on a rust object. So, there's no way to do:
36  * mVerifier.process_movement(...).
37  * This C++ class makes it a bit easier to use.
38  *
39  * TODO(b/211379801): Add support for hover events:
40  * - No hover move without enter
41  * - No touching pointers when hover enter
42  * - No hovering pointers when touching
43  * - Only 1 hovering pointer max
44  */
45 class InputVerifier {
46 public:
47     InputVerifier(const std::string& name);
48 
49     android::base::Result<void> processMovement(int32_t deviceId, int32_t source, int32_t action,
50                                                 uint32_t pointerCount,
51                                                 const PointerProperties* pointerProperties,
52                                                 const PointerCoords* pointerCoords, int32_t flags);
53 
54     void resetDevice(int32_t deviceId);
55 
56 private:
57     rust::Box<android::input::verifier::InputVerifier> mVerifier;
58 };
59 
60 } // namespace android
61