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 | |
| 27 | namespace android { |
| 28 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 29 | // --- InputVerifier --- |
| 30 | |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 31 | InputVerifier::InputVerifier(const std::string& name) |
| 32 | : mVerifier(android::input::verifier::create(name)){}; |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 33 | |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 34 | Result<void> InputVerifier::processMovement(int32_t deviceId, int32_t action, uint32_t pointerCount, |
| 35 | const PointerProperties* pointerProperties, |
| 36 | const PointerCoords* pointerCoords, int32_t flags) { |
| 37 | std::vector<RustPointerProperties> rpp; |
| 38 | for (size_t i = 0; i < pointerCount; i++) { |
| 39 | rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id}); |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 40 | } |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 41 | rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()}; |
| 42 | rust::String errorMessage = |
| 43 | android::input::verifier::process_movement(*mVerifier, deviceId, action, properties, |
| 44 | flags); |
| 45 | if (errorMessage.empty()) { |
| 46 | return {}; |
| 47 | } else { |
| 48 | return Error() << errorMessage; |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 52 | } // namespace android |