blob: 851babfb54a5a8a5810a22083dd4b6d31b347bf3 [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>
20#include <input/InputVerifier.h>
Prabir Pradhan0762b1f2023-06-22 23:08:18 +000021#include "input_cxx_bridge.rs.h"
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070022
23using android::base::Error;
24using android::base::Result;
25using android::input::RustPointerProperties;
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080026
Siarhei Vishniakou1160ecd2023-06-28 15:57:47 -070027using DeviceId = int32_t;
28
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080029namespace android {
30
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080031// --- InputVerifier ---
32
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070033InputVerifier::InputVerifier(const std::string& name)
34 : mVerifier(android::input::verifier::create(name)){};
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080035
Siarhei Vishniakou1160ecd2023-06-28 15:57:47 -070036Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t action,
37 uint32_t pointerCount,
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070038 const PointerProperties* pointerProperties,
39 const PointerCoords* pointerCoords, int32_t flags) {
40 std::vector<RustPointerProperties> rpp;
41 for (size_t i = 0; i < pointerCount; i++) {
42 rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id});
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080043 }
Siarhei Vishniakou5c02a712023-05-15 15:45:02 -070044 rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()};
45 rust::String errorMessage =
46 android::input::verifier::process_movement(*mVerifier, deviceId, action, properties,
47 flags);
48 if (errorMessage.empty()) {
49 return {};
50 } else {
51 return Error() << errorMessage;
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080052 }
53}
54
Siarhei Vishniakou1160ecd2023-06-28 15:57:47 -070055void InputVerifier::resetDevice(DeviceId deviceId) {
56 android::input::verifier::reset_device(*mVerifier, deviceId);
57}
58
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080059} // namespace android