blob: bb15e4d86bf787ebdaa5ab3768107b7de7b185d5 [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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070018
19#include "EventHub.h"
20#include "InputDevice.h"
Siarhei Vishniakouf2f073b2021-02-09 21:59:56 +000021#include "InputListener.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070022#include "InputReaderContext.h"
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070023#include "NotifyArgs.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070024#include "StylusState.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000025#include "VibrationElement.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070026
27namespace 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 */
41class InputMapper {
42public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080043 explicit InputMapper(InputDeviceContext& deviceContext);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070044 virtual ~InputMapper();
45
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080046 inline int32_t getDeviceId() { return mDeviceContext.getId(); }
47 inline InputDeviceContext& getDeviceContext() { return mDeviceContext; }
Philip Junker4af3b3d2021-12-14 10:36:55 +010048 inline InputDeviceContext& getDeviceContext() const { return mDeviceContext; };
Siarhei Vishniakou12c0fcb2021-12-17 13:40:44 -080049 inline const std::string getDeviceName() const { return mDeviceContext.getName(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080050 inline InputReaderContext* getContext() { return mDeviceContext.getContext(); }
51 inline InputReaderPolicyInterface* getPolicy() { return getContext()->getPolicy(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070052
Philip Junker4af3b3d2021-12-14 10:36:55 +010053 virtual uint32_t getSources() const = 0;
Harry Cuttsd02ea102023-03-17 18:21:30 +000054 virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070055 virtual void dump(std::string& dump);
Arpit Singh4be4eef2023-03-28 14:26:01 +000056 [[nodiscard]] virtual std::list<NotifyArgs> reconfigure(nsecs_t when,
57 const InputReaderConfiguration* config,
58 uint32_t changes);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070059 [[nodiscard]] virtual std::list<NotifyArgs> reset(nsecs_t when);
60 [[nodiscard]] virtual std::list<NotifyArgs> process(const RawEvent* rawEvent) = 0;
61 [[nodiscard]] virtual std::list<NotifyArgs> timeoutExpired(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070062
63 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
64 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
65 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +010066 virtual int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
67
Siarhei Vishniakou74007942022-06-13 13:57:47 -070068 virtual bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
69 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070070 [[nodiscard]] virtual std::list<NotifyArgs> vibrate(const VibrationSequence& sequence,
71 ssize_t repeat, int32_t token);
72 [[nodiscard]] virtual std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +000073 virtual bool isVibrating();
74 virtual std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070075 [[nodiscard]] virtual std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -070076 virtual bool enableSensor(InputDeviceSensorType sensorType,
77 std::chrono::microseconds samplingPeriod,
78 std::chrono::microseconds maxBatchReportLatency);
79 virtual void disableSensor(InputDeviceSensorType sensorType);
80 virtual void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070081
Kim Low03ea0352020-11-06 12:45:07 -080082 virtual std::optional<int32_t> getBatteryCapacity() { return std::nullopt; }
83 virtual std::optional<int32_t> getBatteryStatus() { return std::nullopt; }
84
Chris Ye3fdbfef2021-01-06 18:45:18 -080085 virtual bool setLightColor(int32_t lightId, int32_t color) { return true; }
86 virtual bool setLightPlayerId(int32_t lightId, int32_t playerId) { return true; }
87 virtual std::optional<int32_t> getLightColor(int32_t lightId) { return std::nullopt; }
88 virtual std::optional<int32_t> getLightPlayerId(int32_t lightId) { return std::nullopt; }
89
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070090 virtual int32_t getMetaState();
Arthur Hungcb40a002021-08-03 14:31:01 +000091 /**
92 * Process the meta key and update the global meta state when changed.
93 * Return true if the meta key could be handled by the InputMapper.
94 */
95 virtual bool updateMetaState(int32_t keyCode);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070096
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070097 [[nodiscard]] virtual std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070098
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070099 virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; }
arthurhungc903df12020-08-11 15:08:42 +0800100 virtual void updateLedState(bool reset) {}
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700101
102protected:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800103 InputDeviceContext& mDeviceContext;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700104
105 status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
106 void bumpGeneration();
107
108 static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis,
109 const char* name);
110 static void dumpStylusState(std::string& dump, const StylusState& state);
111};
112
113} // namespace android