xref: /aosp_15_r20/hardware/libhardware/modules/input/evdev/InputDeviceManager.cpp (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker 
17*e01b6f76SAndroid Build Coastguard Worker #define LOG_TAG "InputDeviceManager"
18*e01b6f76SAndroid Build Coastguard Worker //#define LOG_NDEBUG 0
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include "InputDeviceManager.h"
21*e01b6f76SAndroid Build Coastguard Worker 
22*e01b6f76SAndroid Build Coastguard Worker #include <utils/Log.h>
23*e01b6f76SAndroid Build Coastguard Worker 
24*e01b6f76SAndroid Build Coastguard Worker #include "InputDevice.h"
25*e01b6f76SAndroid Build Coastguard Worker 
26*e01b6f76SAndroid Build Coastguard Worker namespace android {
27*e01b6f76SAndroid Build Coastguard Worker 
onInputEvent(const std::shared_ptr<InputDeviceNode> & node,InputEvent & event,nsecs_t event_time)28*e01b6f76SAndroid Build Coastguard Worker void InputDeviceManager::onInputEvent(const std::shared_ptr<InputDeviceNode>& node, InputEvent& event,
29*e01b6f76SAndroid Build Coastguard Worker         nsecs_t event_time) {
30*e01b6f76SAndroid Build Coastguard Worker     if (mDevices[node] == nullptr) {
31*e01b6f76SAndroid Build Coastguard Worker         ALOGE("got input event for unknown node %s", node->getPath().c_str());
32*e01b6f76SAndroid Build Coastguard Worker         return;
33*e01b6f76SAndroid Build Coastguard Worker     }
34*e01b6f76SAndroid Build Coastguard Worker     mDevices[node]->processInput(event, event_time);
35*e01b6f76SAndroid Build Coastguard Worker }
36*e01b6f76SAndroid Build Coastguard Worker 
onDeviceAdded(const std::shared_ptr<InputDeviceNode> & node)37*e01b6f76SAndroid Build Coastguard Worker void InputDeviceManager::onDeviceAdded(const std::shared_ptr<InputDeviceNode>& node) {
38*e01b6f76SAndroid Build Coastguard Worker     mDevices[node] = std::make_shared<EvdevDevice>(mHost, node);
39*e01b6f76SAndroid Build Coastguard Worker }
40*e01b6f76SAndroid Build Coastguard Worker 
onDeviceRemoved(const std::shared_ptr<InputDeviceNode> & node)41*e01b6f76SAndroid Build Coastguard Worker void InputDeviceManager::onDeviceRemoved(const std::shared_ptr<InputDeviceNode>& node) {
42*e01b6f76SAndroid Build Coastguard Worker     if (mDevices[node] == nullptr) {
43*e01b6f76SAndroid Build Coastguard Worker         ALOGE("could not remove unknown node %s", node->getPath().c_str());
44*e01b6f76SAndroid Build Coastguard Worker         return;
45*e01b6f76SAndroid Build Coastguard Worker     }
46*e01b6f76SAndroid Build Coastguard Worker     // TODO: tell the InputDevice and InputDeviceNode that they are being
47*e01b6f76SAndroid Build Coastguard Worker     // removed so they can run any cleanup, including unregistering from the
48*e01b6f76SAndroid Build Coastguard Worker     // host.
49*e01b6f76SAndroid Build Coastguard Worker     mDevices.erase(node);
50*e01b6f76SAndroid Build Coastguard Worker }
51*e01b6f76SAndroid Build Coastguard Worker 
52*e01b6f76SAndroid Build Coastguard Worker }  // namespace android
53