blob: 110ca5fab062c80f83843d5dc42fb5541b682315 [file] [log] [blame]
Harry Cutts144ff542022-11-28 17:41:06 +00001/*
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
19namespace android {
20
21InstrumentedInputReader::InstrumentedInputReader(std::shared_ptr<EventHubInterface> eventHub,
22 const sp<InputReaderPolicyInterface>& policy,
23 InputListenerInterface& listener)
24 : InputReader(eventHub, policy, listener), mFakeContext(this) {}
25
26void InstrumentedInputReader::pushNextDevice(std::shared_ptr<InputDevice> device) {
27 mNextDevices.push(device);
28}
29
30std::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
40std::shared_ptr<InputDevice> InstrumentedInputReader::createDeviceLocked(
Arpit Singh82f29a12023-06-13 15:05:53 +000041 nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) REQUIRES(mLock) {
Harry Cutts144ff542022-11-28 17:41:06 +000042 if (!mNextDevices.empty()) {
43 std::shared_ptr<InputDevice> device(std::move(mNextDevices.front()));
44 mNextDevices.pop();
45 return device;
46 }
Arpit Singh82f29a12023-06-13 15:05:53 +000047 return InputReader::createDeviceLocked(when, eventHubId, identifier);
Harry Cutts144ff542022-11-28 17:41:06 +000048}
49
50} // namespace android