xref: /aosp_15_r20/frameworks/native/include/input/InputVerifier.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2023 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <android-base/result.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <input/Input.h>
21*38e8c45fSAndroid Build Coastguard Worker #include "rust/cxx.h"
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker namespace android {
24*38e8c45fSAndroid Build Coastguard Worker 
25*38e8c45fSAndroid Build Coastguard Worker namespace input {
26*38e8c45fSAndroid Build Coastguard Worker namespace verifier {
27*38e8c45fSAndroid Build Coastguard Worker struct InputVerifier;
28*38e8c45fSAndroid Build Coastguard Worker }
29*38e8c45fSAndroid Build Coastguard Worker } // namespace input
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker /*
32*38e8c45fSAndroid Build Coastguard Worker  * Crash if the provided touch stream is inconsistent.
33*38e8c45fSAndroid Build Coastguard Worker  * This class is a pass-through to the rust implementation of InputVerifier.
34*38e8c45fSAndroid Build Coastguard Worker  * The rust class could also be used directly, but it would be less convenient.
35*38e8c45fSAndroid Build Coastguard Worker  * We can't directly invoke the rust methods on a rust object. So, there's no way to do:
36*38e8c45fSAndroid Build Coastguard Worker  * mVerifier.process_movement(...).
37*38e8c45fSAndroid Build Coastguard Worker  * This C++ class makes it a bit easier to use.
38*38e8c45fSAndroid Build Coastguard Worker  *
39*38e8c45fSAndroid Build Coastguard Worker  * TODO(b/211379801): Add support for hover events:
40*38e8c45fSAndroid Build Coastguard Worker  * - No hover move without enter
41*38e8c45fSAndroid Build Coastguard Worker  * - No touching pointers when hover enter
42*38e8c45fSAndroid Build Coastguard Worker  * - No hovering pointers when touching
43*38e8c45fSAndroid Build Coastguard Worker  * - Only 1 hovering pointer max
44*38e8c45fSAndroid Build Coastguard Worker  */
45*38e8c45fSAndroid Build Coastguard Worker class InputVerifier {
46*38e8c45fSAndroid Build Coastguard Worker public:
47*38e8c45fSAndroid Build Coastguard Worker     InputVerifier(const std::string& name);
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker     android::base::Result<void> processMovement(int32_t deviceId, int32_t source, int32_t action,
50*38e8c45fSAndroid Build Coastguard Worker                                                 uint32_t pointerCount,
51*38e8c45fSAndroid Build Coastguard Worker                                                 const PointerProperties* pointerProperties,
52*38e8c45fSAndroid Build Coastguard Worker                                                 const PointerCoords* pointerCoords, int32_t flags);
53*38e8c45fSAndroid Build Coastguard Worker 
54*38e8c45fSAndroid Build Coastguard Worker     void resetDevice(int32_t deviceId);
55*38e8c45fSAndroid Build Coastguard Worker 
56*38e8c45fSAndroid Build Coastguard Worker private:
57*38e8c45fSAndroid Build Coastguard Worker     rust::Box<android::input::verifier::InputVerifier> mVerifier;
58*38e8c45fSAndroid Build Coastguard Worker };
59*38e8c45fSAndroid Build Coastguard Worker 
60*38e8c45fSAndroid Build Coastguard Worker } // namespace android
61