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
InstrumentedInputReader(std::shared_ptr<EventHubInterface> eventHub,const sp<InputReaderPolicyInterface> & policy,InputListenerInterface & listener)21 InstrumentedInputReader::InstrumentedInputReader(std::shared_ptr<EventHubInterface> eventHub,
22 const sp<InputReaderPolicyInterface>& policy,
23 InputListenerInterface& listener)
24 : InputReader(eventHub, policy, listener), mFakeContext(this) {}
25
pushNextDevice(std::shared_ptr<InputDevice> device)26 void InstrumentedInputReader::pushNextDevice(std::shared_ptr<InputDevice> device) {
27 mNextDevices.push(device);
28 }
29
newDevice(int32_t deviceId,const std::string & name,const std::string & location)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
createDeviceLocked(nsecs_t when,int32_t eventHubId,const InputDeviceIdentifier & identifier)40 std::shared_ptr<InputDevice> InstrumentedInputReader::createDeviceLocked(
41 nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) REQUIRES(mLock) {
42 if (!mNextDevices.empty()) {
43 std::shared_ptr<InputDevice> device(std::move(mNextDevices.front()));
44 mNextDevices.pop();
45 return device;
46 }
47 return InputReader::createDeviceLocked(when, eventHubId, identifier);
48 }
49
50 } // namespace android
51