1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 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 #define LOG_TAG "InputVerifier"
18*38e8c45fSAndroid Build Coastguard Worker
19*38e8c45fSAndroid Build Coastguard Worker #include <android-base/logging.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <input/InputVerifier.h>
21*38e8c45fSAndroid Build Coastguard Worker #include "input_cxx_bridge.rs.h"
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker using android::base::Error;
24*38e8c45fSAndroid Build Coastguard Worker using android::base::Result;
25*38e8c45fSAndroid Build Coastguard Worker using android::input::RustPointerProperties;
26*38e8c45fSAndroid Build Coastguard Worker
27*38e8c45fSAndroid Build Coastguard Worker using DeviceId = int32_t;
28*38e8c45fSAndroid Build Coastguard Worker
29*38e8c45fSAndroid Build Coastguard Worker namespace android {
30*38e8c45fSAndroid Build Coastguard Worker
31*38e8c45fSAndroid Build Coastguard Worker // --- InputVerifier ---
32*38e8c45fSAndroid Build Coastguard Worker
InputVerifier(const std::string & name)33*38e8c45fSAndroid Build Coastguard Worker InputVerifier::InputVerifier(const std::string& name)
34*38e8c45fSAndroid Build Coastguard Worker : mVerifier(android::input::verifier::create(rust::String::lossy(name))){};
35*38e8c45fSAndroid Build Coastguard Worker
processMovement(DeviceId deviceId,int32_t source,int32_t action,uint32_t pointerCount,const PointerProperties * pointerProperties,const PointerCoords * pointerCoords,int32_t flags)36*38e8c45fSAndroid Build Coastguard Worker Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t source, int32_t action,
37*38e8c45fSAndroid Build Coastguard Worker uint32_t pointerCount,
38*38e8c45fSAndroid Build Coastguard Worker const PointerProperties* pointerProperties,
39*38e8c45fSAndroid Build Coastguard Worker const PointerCoords* pointerCoords, int32_t flags) {
40*38e8c45fSAndroid Build Coastguard Worker std::vector<RustPointerProperties> rpp;
41*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < pointerCount; i++) {
42*38e8c45fSAndroid Build Coastguard Worker rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id});
43*38e8c45fSAndroid Build Coastguard Worker }
44*38e8c45fSAndroid Build Coastguard Worker rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()};
45*38e8c45fSAndroid Build Coastguard Worker rust::String errorMessage =
46*38e8c45fSAndroid Build Coastguard Worker android::input::verifier::process_movement(*mVerifier, deviceId, source, action,
47*38e8c45fSAndroid Build Coastguard Worker properties, static_cast<uint32_t>(flags));
48*38e8c45fSAndroid Build Coastguard Worker if (errorMessage.empty()) {
49*38e8c45fSAndroid Build Coastguard Worker return {};
50*38e8c45fSAndroid Build Coastguard Worker } else {
51*38e8c45fSAndroid Build Coastguard Worker return Error() << errorMessage;
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker }
54*38e8c45fSAndroid Build Coastguard Worker
resetDevice(DeviceId deviceId)55*38e8c45fSAndroid Build Coastguard Worker void InputVerifier::resetDevice(DeviceId deviceId) {
56*38e8c45fSAndroid Build Coastguard Worker android::input::verifier::reset_device(*mVerifier, deviceId);
57*38e8c45fSAndroid Build Coastguard Worker }
58*38e8c45fSAndroid Build Coastguard Worker
59*38e8c45fSAndroid Build Coastguard Worker } // namespace android
60