Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 1 | /* |
| 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 Pradhan | 0762b1f | 2023-06-22 23:08:18 +0000 | [diff] [blame] | 21 | #include "input_cxx_bridge.rs.h" |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 22 | |
| 23 | using android::base::Error; |
| 24 | using android::base::Result; |
| 25 | using android::input::RustPointerProperties; |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 26 | |
Siarhei Vishniakou | 1160ecd | 2023-06-28 15:57:47 -0700 | [diff] [blame] | 27 | using DeviceId = int32_t; |
| 28 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 31 | // --- InputVerifier --- |
| 32 | |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 33 | InputVerifier::InputVerifier(const std::string& name) |
Prabir Pradhan | 3117a44 | 2023-08-11 17:48:43 +0000 | [diff] [blame] | 34 | : mVerifier(android::input::verifier::create(rust::String::lossy(name))){}; |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 35 | |
Siarhei Vishniakou | 2d151ac | 2023-09-19 13:30:24 -0700 | [diff] [blame] | 36 | Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t source, int32_t action, |
Siarhei Vishniakou | 1160ecd | 2023-06-28 15:57:47 -0700 | [diff] [blame] | 37 | uint32_t pointerCount, |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 38 | 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 Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 43 | } |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 44 | rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()}; |
| 45 | rust::String errorMessage = |
Siarhei Vishniakou | 2d151ac | 2023-09-19 13:30:24 -0700 | [diff] [blame] | 46 | android::input::verifier::process_movement(*mVerifier, deviceId, source, action, |
| 47 | properties, static_cast<uint32_t>(flags)); |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 48 | if (errorMessage.empty()) { |
| 49 | return {}; |
| 50 | } else { |
| 51 | return Error() << errorMessage; |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
Siarhei Vishniakou | 1160ecd | 2023-06-28 15:57:47 -0700 | [diff] [blame] | 55 | void InputVerifier::resetDevice(DeviceId deviceId) { |
| 56 | android::input::verifier::reset_device(*mVerifier, deviceId); |
| 57 | } |
| 58 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 59 | } // namespace android |