Harry Cutts | 144ff54 | 2022-11-28 17:41:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | #include "InstrumentedInputReader.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | InstrumentedInputReader::InstrumentedInputReader(std::shared_ptr<EventHubInterface> eventHub, |
| 22 | const sp<InputReaderPolicyInterface>& policy, |
| 23 | InputListenerInterface& listener) |
| 24 | : InputReader(eventHub, policy, listener), mFakeContext(this) {} |
| 25 | |
| 26 | void InstrumentedInputReader::pushNextDevice(std::shared_ptr<InputDevice> device) { |
| 27 | mNextDevices.push(device); |
| 28 | } |
| 29 | |
| 30 | std::shared_ptr<InputDevice> InstrumentedInputReader::newDevice(int32_t deviceId, |
| 31 | const std::string& name, |
| 32 | const std::string& location) { |
| 33 | InputDeviceIdentifier identifier; |
| 34 | identifier.name = name; |
| 35 | identifier.location = location; |
| 36 | int32_t generation = deviceId + 1; |
| 37 | return std::make_shared<InputDevice>(&mFakeContext, deviceId, generation, identifier); |
| 38 | } |
| 39 | |
| 40 | std::shared_ptr<InputDevice> InstrumentedInputReader::createDeviceLocked( |
Arpit Singh | 82f29a1 | 2023-06-13 15:05:53 +0000 | [diff] [blame] | 41 | nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) REQUIRES(mLock) { |
Harry Cutts | 144ff54 | 2022-11-28 17:41:06 +0000 | [diff] [blame] | 42 | if (!mNextDevices.empty()) { |
| 43 | std::shared_ptr<InputDevice> device(std::move(mNextDevices.front())); |
| 44 | mNextDevices.pop(); |
| 45 | return device; |
| 46 | } |
Arpit Singh | 82f29a1 | 2023-06-13 15:05:53 +0000 | [diff] [blame] | 47 | return InputReader::createDeviceLocked(when, eventHubId, identifier); |
Harry Cutts | 144ff54 | 2022-11-28 17:41:06 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // namespace android |