blob: 44af998693cd8242643c77faf51ab14a151f64b2 [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
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"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070022#include "InputReaderContext.h"
23#include "StylusState.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000024#include "VibrationElement.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070025
26namespace 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 */
40class InputMapper {
41public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080042 explicit InputMapper(InputDeviceContext& deviceContext);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070043 virtual ~InputMapper();
44
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080045 inline int32_t getDeviceId() { return mDeviceContext.getId(); }
46 inline InputDeviceContext& getDeviceContext() { return mDeviceContext; }
47 inline const std::string getDeviceName() { return mDeviceContext.getName(); }
48 inline InputReaderContext* getContext() { return mDeviceContext.getContext(); }
49 inline InputReaderPolicyInterface* getPolicy() { return getContext()->getPolicy(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070050
51 virtual uint32_t getSources() = 0;
52 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
53 virtual void dump(std::string& dump);
54 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
55 virtual void reset(nsecs_t when);
56 virtual void process(const RawEvent* rawEvent) = 0;
57 virtual void timeoutExpired(nsecs_t when);
58
59 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
60 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
61 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
62 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
63 const int32_t* keyCodes, uint8_t* outFlags);
Chris Ye87143712020-11-10 05:05:58 +000064 virtual void vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070065 virtual void cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +000066 virtual bool isVibrating();
67 virtual std::vector<int32_t> getVibratorIds();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070068 virtual void cancelTouch(nsecs_t when);
Chris Yef59a2f42020-10-16 12:55:26 -070069 virtual bool enableSensor(InputDeviceSensorType sensorType,
70 std::chrono::microseconds samplingPeriod,
71 std::chrono::microseconds maxBatchReportLatency);
72 virtual void disableSensor(InputDeviceSensorType sensorType);
73 virtual void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070074
Kim Low03ea0352020-11-06 12:45:07 -080075 virtual std::optional<int32_t> getBatteryCapacity() { return std::nullopt; }
76 virtual std::optional<int32_t> getBatteryStatus() { return std::nullopt; }
77
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070078 virtual int32_t getMetaState();
79 virtual void updateMetaState(int32_t keyCode);
80
81 virtual void updateExternalStylusState(const StylusState& state);
82
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070083 virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; }
arthurhungc903df12020-08-11 15:08:42 +080084 virtual void updateLedState(bool reset) {}
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070085
86protected:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080087 InputDeviceContext& mDeviceContext;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070088
89 status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
90 void bumpGeneration();
91
92 static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis,
93 const char* name);
94 static void dumpStylusState(std::string& dump, const StylusState& state);
95};
96
97} // namespace android
98
99#endif // _UI_INPUTREADER_INPUT_MAPPER_H