blob: 7811acefd01a4ec70b00170481e46bcda4db07a1 [file] [log] [blame]
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -08001/*
2 * Copyright (C) 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#define LOG_TAG "InputVerifier"
18
19#include <android-base/logging.h>
Harry Cutts26640c92025-01-27 09:01:06 -080020#include <com_android_input_flags.h>
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080021#include <input/InputVerifier.h>
Prabir Pradhan0762b1f2023-06-22 23:08:18 +000022#include "input_cxx_bridge.rs.h"
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070023
24using android::base::Error;
25using android::base::Result;
26using android::input::RustPointerProperties;
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080027
Siarhei Vishniakou1160ecd2023-06-28 15:57:47 -070028using DeviceId = int32_t;
29
Harry Cutts26640c92025-01-27 09:01:06 -080030namespace input_flags = com::android::input::flags;
31
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080032namespace android {
33
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080034// --- InputVerifier ---
35
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070036InputVerifier::InputVerifier(const std::string& name)
Harry Cutts26640c92025-01-27 09:01:06 -080037 : mVerifier(
38 android::input::verifier::create(rust::String::lossy(name),
39 input_flags::enable_button_state_verification())) {
40}
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080041
Siarhei Vishniakou2d151ac2023-09-19 13:30:24 -070042Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t source, int32_t action,
Harry Cutts26640c92025-01-27 09:01:06 -080043 int32_t actionButton, uint32_t pointerCount,
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070044 const PointerProperties* pointerProperties,
Harry Cutts26640c92025-01-27 09:01:06 -080045 const PointerCoords* pointerCoords, int32_t flags,
46 int32_t buttonState) {
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070047 std::vector<RustPointerProperties> rpp;
48 for (size_t i = 0; i < pointerCount; i++) {
49 rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id});
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080050 }
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070051 rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()};
52 rust::String errorMessage =
Siarhei Vishniakou2d151ac2023-09-19 13:30:24 -070053 android::input::verifier::process_movement(*mVerifier, deviceId, source, action,
Harry Cutts26640c92025-01-27 09:01:06 -080054 actionButton, properties,
55 static_cast<uint32_t>(flags),
56 static_cast<uint32_t>(buttonState));
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070057 if (errorMessage.empty()) {
58 return {};
59 } else {
60 return Error() << errorMessage;
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080061 }
62}
63
Siarhei Vishniakou1160ecd2023-06-28 15:57:47 -070064void InputVerifier::resetDevice(DeviceId deviceId) {
65 android::input::verifier::reset_device(*mVerifier, deviceId);
66}
67
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080068} // namespace android