• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #ifndef _UI_INPUTREADER_INPUT_MAPPER_H
18 #define _UI_INPUTREADER_INPUT_MAPPER_H
19 
20 #include "EventHub.h"
21 #include "InputDevice.h"
22 #include "InputListener.h"
23 #include "InputReaderContext.h"
24 #include "StylusState.h"
25 
26 namespace android {
27 
28 /* An input mapper transforms raw input events into cooked event data.
29  * A single input device can have multiple associated input mappers in order to interpret
30  * different classes of events.
31  *
32  * InputMapper lifecycle:
33  * - create
34  * - configure with 0 changes
35  * - reset
36  * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
37  * - reset
38  * - destroy
39  */
40 class InputMapper {
41 public:
42     explicit InputMapper(InputDeviceContext& deviceContext);
43     virtual ~InputMapper();
44 
getDeviceId()45     inline int32_t getDeviceId() { return mDeviceContext.getId(); }
getDeviceContext()46     inline InputDeviceContext& getDeviceContext() { return mDeviceContext; }
getDeviceName()47     inline const std::string getDeviceName() { return mDeviceContext.getName(); }
getContext()48     inline InputReaderContext* getContext() { return mDeviceContext.getContext(); }
getPolicy()49     inline InputReaderPolicyInterface* getPolicy() { return getContext()->getPolicy(); }
getListener()50     inline InputListenerInterface* getListener() { return getContext()->getListener(); }
51 
52     virtual uint32_t getSources() = 0;
53     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
54     virtual void dump(std::string& dump);
55     virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
56     virtual void reset(nsecs_t when);
57     virtual void process(const RawEvent* rawEvent) = 0;
58     virtual void timeoutExpired(nsecs_t when);
59 
60     virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
61     virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
62     virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
63     virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
64                                        const int32_t* keyCodes, uint8_t* outFlags);
65     virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
66     virtual void cancelVibrate(int32_t token);
67     virtual void cancelTouch(nsecs_t when);
68 
69     virtual int32_t getMetaState();
70     virtual void updateMetaState(int32_t keyCode);
71 
72     virtual void updateExternalStylusState(const StylusState& state);
73 
getAssociatedDisplayId()74     virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; }
75 
76 protected:
77     InputDeviceContext& mDeviceContext;
78 
79     status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
80     void bumpGeneration();
81 
82     static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis,
83                                         const char* name);
84     static void dumpStylusState(std::string& dump, const StylusState& state);
85 };
86 
87 } // namespace android
88 
89 #endif // _UI_INPUTREADER_INPUT_MAPPER_H
90