Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 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" |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 22 | #include "InputListener.h" |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 23 | #include "InputReaderContext.h" |
| 24 | #include "StylusState.h" |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 25 | #include "VibrationElement.h" |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | /* An input mapper transforms raw input events into cooked event data. |
| 30 | * A single input device can have multiple associated input mappers in order to interpret |
| 31 | * different classes of events. |
| 32 | * |
| 33 | * InputMapper lifecycle: |
| 34 | * - create |
| 35 | * - configure with 0 changes |
| 36 | * - reset |
| 37 | * - process, process, process (may occasionally reconfigure with non-zero changes or reset) |
| 38 | * - reset |
| 39 | * - destroy |
| 40 | */ |
| 41 | class InputMapper { |
| 42 | public: |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 43 | explicit InputMapper(InputDeviceContext& deviceContext); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 44 | virtual ~InputMapper(); |
| 45 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 46 | inline int32_t getDeviceId() { return mDeviceContext.getId(); } |
| 47 | inline InputDeviceContext& getDeviceContext() { return mDeviceContext; } |
Siarhei Vishniakou | 12c0fcb | 2021-12-17 13:40:44 -0800 | [diff] [blame^] | 48 | inline const std::string getDeviceName() const { return mDeviceContext.getName(); } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 49 | inline InputReaderContext* getContext() { return mDeviceContext.getContext(); } |
| 50 | inline InputReaderPolicyInterface* getPolicy() { return getContext()->getPolicy(); } |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 51 | inline InputListenerInterface& getListener() { return getContext()->getListener(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 52 | |
| 53 | virtual uint32_t getSources() = 0; |
| 54 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 55 | virtual void dump(std::string& dump); |
| 56 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 57 | virtual void reset(nsecs_t when); |
| 58 | virtual void process(const RawEvent* rawEvent) = 0; |
| 59 | virtual void timeoutExpired(nsecs_t when); |
| 60 | |
| 61 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 62 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 63 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 64 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 65 | const int32_t* keyCodes, uint8_t* outFlags); |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 66 | virtual void vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 67 | virtual void cancelVibrate(int32_t token); |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 68 | virtual bool isVibrating(); |
| 69 | virtual std::vector<int32_t> getVibratorIds(); |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 70 | virtual void cancelTouch(nsecs_t when, nsecs_t readTime); |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 71 | virtual bool enableSensor(InputDeviceSensorType sensorType, |
| 72 | std::chrono::microseconds samplingPeriod, |
| 73 | std::chrono::microseconds maxBatchReportLatency); |
| 74 | virtual void disableSensor(InputDeviceSensorType sensorType); |
| 75 | virtual void flushSensor(InputDeviceSensorType sensorType); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 76 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 77 | virtual std::optional<int32_t> getBatteryCapacity() { return std::nullopt; } |
| 78 | virtual std::optional<int32_t> getBatteryStatus() { return std::nullopt; } |
| 79 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 80 | virtual bool setLightColor(int32_t lightId, int32_t color) { return true; } |
| 81 | virtual bool setLightPlayerId(int32_t lightId, int32_t playerId) { return true; } |
| 82 | virtual std::optional<int32_t> getLightColor(int32_t lightId) { return std::nullopt; } |
| 83 | virtual std::optional<int32_t> getLightPlayerId(int32_t lightId) { return std::nullopt; } |
| 84 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 85 | virtual int32_t getMetaState(); |
Arthur Hung | cb40a00 | 2021-08-03 14:31:01 +0000 | [diff] [blame] | 86 | /** |
| 87 | * Process the meta key and update the global meta state when changed. |
| 88 | * Return true if the meta key could be handled by the InputMapper. |
| 89 | */ |
| 90 | virtual bool updateMetaState(int32_t keyCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 91 | |
| 92 | virtual void updateExternalStylusState(const StylusState& state); |
| 93 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 94 | virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; } |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 95 | virtual void updateLedState(bool reset) {} |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 96 | |
| 97 | protected: |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 98 | InputDeviceContext& mDeviceContext; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 99 | |
| 100 | status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo); |
| 101 | void bumpGeneration(); |
| 102 | |
| 103 | static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, |
| 104 | const char* name); |
| 105 | static void dumpStylusState(std::string& dump, const StylusState& state); |
| 106 | }; |
| 107 | |
| 108 | } // namespace android |
| 109 | |
| 110 | #endif // _UI_INPUTREADER_INPUT_MAPPER_H |