1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2012 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "InputDevice"
18*38e8c45fSAndroid Build Coastguard Worker
19*38e8c45fSAndroid Build Coastguard Worker #include <stdlib.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <unistd.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <ctype.h>
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker #include <android-base/logging.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <android-base/properties.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <android-base/stringprintf.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <ftl/enum.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <input/InputDevice.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <input/InputEventLabels.h>
29*38e8c45fSAndroid Build Coastguard Worker
30*38e8c45fSAndroid Build Coastguard Worker using android::base::GetProperty;
31*38e8c45fSAndroid Build Coastguard Worker using android::base::StringPrintf;
32*38e8c45fSAndroid Build Coastguard Worker
33*38e8c45fSAndroid Build Coastguard Worker namespace android {
34*38e8c45fSAndroid Build Coastguard Worker
35*38e8c45fSAndroid Build Coastguard Worker // Set to true to log detailed debugging messages about IDC file probing.
36*38e8c45fSAndroid Build Coastguard Worker static constexpr bool DEBUG_PROBE = false;
37*38e8c45fSAndroid Build Coastguard Worker
38*38e8c45fSAndroid Build Coastguard Worker static const char* CONFIGURATION_FILE_DIR[] = {
39*38e8c45fSAndroid Build Coastguard Worker "idc/",
40*38e8c45fSAndroid Build Coastguard Worker "keylayout/",
41*38e8c45fSAndroid Build Coastguard Worker "keychars/",
42*38e8c45fSAndroid Build Coastguard Worker };
43*38e8c45fSAndroid Build Coastguard Worker
44*38e8c45fSAndroid Build Coastguard Worker static const char* CONFIGURATION_FILE_EXTENSION[] = {
45*38e8c45fSAndroid Build Coastguard Worker ".idc",
46*38e8c45fSAndroid Build Coastguard Worker ".kl",
47*38e8c45fSAndroid Build Coastguard Worker ".kcm",
48*38e8c45fSAndroid Build Coastguard Worker };
49*38e8c45fSAndroid Build Coastguard Worker
isValidNameChar(char ch)50*38e8c45fSAndroid Build Coastguard Worker static bool isValidNameChar(char ch) {
51*38e8c45fSAndroid Build Coastguard Worker return isascii(ch) && (isdigit(ch) || isalpha(ch) || ch == '-' || ch == '_');
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker
appendInputDeviceConfigurationFileRelativePath(std::string & path,const std::string & name,InputDeviceConfigurationFileType type)54*38e8c45fSAndroid Build Coastguard Worker static void appendInputDeviceConfigurationFileRelativePath(std::string& path,
55*38e8c45fSAndroid Build Coastguard Worker const std::string& name, InputDeviceConfigurationFileType type) {
56*38e8c45fSAndroid Build Coastguard Worker path += CONFIGURATION_FILE_DIR[static_cast<int32_t>(type)];
57*38e8c45fSAndroid Build Coastguard Worker path += name;
58*38e8c45fSAndroid Build Coastguard Worker path += CONFIGURATION_FILE_EXTENSION[static_cast<int32_t>(type)];
59*38e8c45fSAndroid Build Coastguard Worker }
60*38e8c45fSAndroid Build Coastguard Worker
getInputDeviceConfigurationFilePathByDeviceIdentifier(const InputDeviceIdentifier & deviceIdentifier,InputDeviceConfigurationFileType type,const char * suffix)61*38e8c45fSAndroid Build Coastguard Worker std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
62*38e8c45fSAndroid Build Coastguard Worker const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type,
63*38e8c45fSAndroid Build Coastguard Worker const char* suffix) {
64*38e8c45fSAndroid Build Coastguard Worker if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) {
65*38e8c45fSAndroid Build Coastguard Worker if (deviceIdentifier.version != 0) {
66*38e8c45fSAndroid Build Coastguard Worker // Try vendor product version.
67*38e8c45fSAndroid Build Coastguard Worker std::string versionPath =
68*38e8c45fSAndroid Build Coastguard Worker getInputDeviceConfigurationFilePathByName(StringPrintf("Vendor_%04x_Product_%"
69*38e8c45fSAndroid Build Coastguard Worker "04x_Version_%04x%s",
70*38e8c45fSAndroid Build Coastguard Worker deviceIdentifier.vendor,
71*38e8c45fSAndroid Build Coastguard Worker deviceIdentifier.product,
72*38e8c45fSAndroid Build Coastguard Worker deviceIdentifier.version,
73*38e8c45fSAndroid Build Coastguard Worker suffix),
74*38e8c45fSAndroid Build Coastguard Worker type);
75*38e8c45fSAndroid Build Coastguard Worker if (!versionPath.empty()) {
76*38e8c45fSAndroid Build Coastguard Worker return versionPath;
77*38e8c45fSAndroid Build Coastguard Worker }
78*38e8c45fSAndroid Build Coastguard Worker }
79*38e8c45fSAndroid Build Coastguard Worker
80*38e8c45fSAndroid Build Coastguard Worker // Try vendor product.
81*38e8c45fSAndroid Build Coastguard Worker std::string productPath =
82*38e8c45fSAndroid Build Coastguard Worker getInputDeviceConfigurationFilePathByName(StringPrintf("Vendor_%04x_Product_%04x%s",
83*38e8c45fSAndroid Build Coastguard Worker deviceIdentifier.vendor,
84*38e8c45fSAndroid Build Coastguard Worker deviceIdentifier.product,
85*38e8c45fSAndroid Build Coastguard Worker suffix),
86*38e8c45fSAndroid Build Coastguard Worker type);
87*38e8c45fSAndroid Build Coastguard Worker if (!productPath.empty()) {
88*38e8c45fSAndroid Build Coastguard Worker return productPath;
89*38e8c45fSAndroid Build Coastguard Worker }
90*38e8c45fSAndroid Build Coastguard Worker }
91*38e8c45fSAndroid Build Coastguard Worker
92*38e8c45fSAndroid Build Coastguard Worker // Try device name.
93*38e8c45fSAndroid Build Coastguard Worker return getInputDeviceConfigurationFilePathByName(deviceIdentifier.getCanonicalName() + suffix,
94*38e8c45fSAndroid Build Coastguard Worker type);
95*38e8c45fSAndroid Build Coastguard Worker }
96*38e8c45fSAndroid Build Coastguard Worker
getInputDeviceConfigurationFilePathByName(const std::string & name,InputDeviceConfigurationFileType type)97*38e8c45fSAndroid Build Coastguard Worker std::string getInputDeviceConfigurationFilePathByName(
98*38e8c45fSAndroid Build Coastguard Worker const std::string& name, InputDeviceConfigurationFileType type) {
99*38e8c45fSAndroid Build Coastguard Worker // Search system repository.
100*38e8c45fSAndroid Build Coastguard Worker std::string path;
101*38e8c45fSAndroid Build Coastguard Worker
102*38e8c45fSAndroid Build Coastguard Worker // Treblized input device config files will be located /product/usr, /system_ext/usr,
103*38e8c45fSAndroid Build Coastguard Worker // /odm/usr or /vendor/usr.
104*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> pathPrefixes{
105*38e8c45fSAndroid Build Coastguard Worker "/product/usr/",
106*38e8c45fSAndroid Build Coastguard Worker "/system_ext/usr/",
107*38e8c45fSAndroid Build Coastguard Worker "/odm/usr/",
108*38e8c45fSAndroid Build Coastguard Worker "/vendor/usr/",
109*38e8c45fSAndroid Build Coastguard Worker };
110*38e8c45fSAndroid Build Coastguard Worker // These files may also be in the APEX pointed by input_device.config_file.apex sysprop.
111*38e8c45fSAndroid Build Coastguard Worker if (auto apex = GetProperty("input_device.config_file.apex", ""); !apex.empty()) {
112*38e8c45fSAndroid Build Coastguard Worker pathPrefixes.push_back("/apex/" + apex + "/etc/usr/");
113*38e8c45fSAndroid Build Coastguard Worker }
114*38e8c45fSAndroid Build Coastguard Worker // ANDROID_ROOT may not be set on host
115*38e8c45fSAndroid Build Coastguard Worker if (auto android_root = getenv("ANDROID_ROOT"); android_root != nullptr) {
116*38e8c45fSAndroid Build Coastguard Worker pathPrefixes.push_back(std::string(android_root) + "/usr/");
117*38e8c45fSAndroid Build Coastguard Worker }
118*38e8c45fSAndroid Build Coastguard Worker for (const auto& prefix : pathPrefixes) {
119*38e8c45fSAndroid Build Coastguard Worker path = prefix;
120*38e8c45fSAndroid Build Coastguard Worker appendInputDeviceConfigurationFileRelativePath(path, name, type);
121*38e8c45fSAndroid Build Coastguard Worker if (!access(path.c_str(), R_OK)) {
122*38e8c45fSAndroid Build Coastguard Worker LOG_IF(INFO, DEBUG_PROBE)
123*38e8c45fSAndroid Build Coastguard Worker << "Found system-provided input device configuration file at " << path;
124*38e8c45fSAndroid Build Coastguard Worker return path;
125*38e8c45fSAndroid Build Coastguard Worker } else if (errno != ENOENT) {
126*38e8c45fSAndroid Build Coastguard Worker LOG(WARNING) << "Couldn't find a system-provided input device configuration file at "
127*38e8c45fSAndroid Build Coastguard Worker << path << " due to error " << errno << " (" << strerror(errno)
128*38e8c45fSAndroid Build Coastguard Worker << "); there may be an IDC file there that cannot be loaded.";
129*38e8c45fSAndroid Build Coastguard Worker } else {
130*38e8c45fSAndroid Build Coastguard Worker LOG_IF(ERROR, DEBUG_PROBE)
131*38e8c45fSAndroid Build Coastguard Worker << "Didn't find system-provided input device configuration file at " << path
132*38e8c45fSAndroid Build Coastguard Worker << ": " << strerror(errno);
133*38e8c45fSAndroid Build Coastguard Worker }
134*38e8c45fSAndroid Build Coastguard Worker }
135*38e8c45fSAndroid Build Coastguard Worker
136*38e8c45fSAndroid Build Coastguard Worker // Search user repository.
137*38e8c45fSAndroid Build Coastguard Worker // TODO Should only look here if not in safe mode.
138*38e8c45fSAndroid Build Coastguard Worker path = "";
139*38e8c45fSAndroid Build Coastguard Worker char *androidData = getenv("ANDROID_DATA");
140*38e8c45fSAndroid Build Coastguard Worker if (androidData != nullptr) {
141*38e8c45fSAndroid Build Coastguard Worker path += androidData;
142*38e8c45fSAndroid Build Coastguard Worker }
143*38e8c45fSAndroid Build Coastguard Worker path += "/system/devices/";
144*38e8c45fSAndroid Build Coastguard Worker appendInputDeviceConfigurationFileRelativePath(path, name, type);
145*38e8c45fSAndroid Build Coastguard Worker if (!access(path.c_str(), R_OK)) {
146*38e8c45fSAndroid Build Coastguard Worker LOG_IF(INFO, DEBUG_PROBE) << "Found system user input device configuration file at "
147*38e8c45fSAndroid Build Coastguard Worker << path;
148*38e8c45fSAndroid Build Coastguard Worker return path;
149*38e8c45fSAndroid Build Coastguard Worker } else if (errno != ENOENT) {
150*38e8c45fSAndroid Build Coastguard Worker LOG(WARNING) << "Couldn't find a system user input device configuration file at " << path
151*38e8c45fSAndroid Build Coastguard Worker << " due to error " << errno << " (" << strerror(errno)
152*38e8c45fSAndroid Build Coastguard Worker << "); there may be an IDC file there that cannot be loaded.";
153*38e8c45fSAndroid Build Coastguard Worker } else {
154*38e8c45fSAndroid Build Coastguard Worker LOG_IF(ERROR, DEBUG_PROBE) << "Didn't find system user input device configuration file at "
155*38e8c45fSAndroid Build Coastguard Worker << path << ": " << strerror(errno);
156*38e8c45fSAndroid Build Coastguard Worker }
157*38e8c45fSAndroid Build Coastguard Worker
158*38e8c45fSAndroid Build Coastguard Worker // Not found.
159*38e8c45fSAndroid Build Coastguard Worker LOG_IF(INFO, DEBUG_PROBE) << "Probe failed to find input device configuration file with name '"
160*38e8c45fSAndroid Build Coastguard Worker << name << "' and type " << ftl::enum_string(type);
161*38e8c45fSAndroid Build Coastguard Worker return "";
162*38e8c45fSAndroid Build Coastguard Worker }
163*38e8c45fSAndroid Build Coastguard Worker
164*38e8c45fSAndroid Build Coastguard Worker // --- InputDeviceIdentifier
165*38e8c45fSAndroid Build Coastguard Worker
getCanonicalName() const166*38e8c45fSAndroid Build Coastguard Worker std::string InputDeviceIdentifier::getCanonicalName() const {
167*38e8c45fSAndroid Build Coastguard Worker std::string replacedName = name;
168*38e8c45fSAndroid Build Coastguard Worker for (char& ch : replacedName) {
169*38e8c45fSAndroid Build Coastguard Worker if (!isValidNameChar(ch)) {
170*38e8c45fSAndroid Build Coastguard Worker ch = '_';
171*38e8c45fSAndroid Build Coastguard Worker }
172*38e8c45fSAndroid Build Coastguard Worker }
173*38e8c45fSAndroid Build Coastguard Worker return replacedName;
174*38e8c45fSAndroid Build Coastguard Worker }
175*38e8c45fSAndroid Build Coastguard Worker
176*38e8c45fSAndroid Build Coastguard Worker
177*38e8c45fSAndroid Build Coastguard Worker // --- InputDeviceInfo ---
178*38e8c45fSAndroid Build Coastguard Worker
InputDeviceInfo()179*38e8c45fSAndroid Build Coastguard Worker InputDeviceInfo::InputDeviceInfo() {
180*38e8c45fSAndroid Build Coastguard Worker initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ui::LogicalDisplayId::INVALID);
181*38e8c45fSAndroid Build Coastguard Worker }
182*38e8c45fSAndroid Build Coastguard Worker
InputDeviceInfo(const InputDeviceInfo & other)183*38e8c45fSAndroid Build Coastguard Worker InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
184*38e8c45fSAndroid Build Coastguard Worker : mId(other.mId),
185*38e8c45fSAndroid Build Coastguard Worker mGeneration(other.mGeneration),
186*38e8c45fSAndroid Build Coastguard Worker mControllerNumber(other.mControllerNumber),
187*38e8c45fSAndroid Build Coastguard Worker mIdentifier(other.mIdentifier),
188*38e8c45fSAndroid Build Coastguard Worker mAlias(other.mAlias),
189*38e8c45fSAndroid Build Coastguard Worker mIsExternal(other.mIsExternal),
190*38e8c45fSAndroid Build Coastguard Worker mHasMic(other.mHasMic),
191*38e8c45fSAndroid Build Coastguard Worker mKeyboardLayoutInfo(other.mKeyboardLayoutInfo),
192*38e8c45fSAndroid Build Coastguard Worker mSources(other.mSources),
193*38e8c45fSAndroid Build Coastguard Worker mKeyboardType(other.mKeyboardType),
194*38e8c45fSAndroid Build Coastguard Worker mKeyCharacterMap(other.mKeyCharacterMap
195*38e8c45fSAndroid Build Coastguard Worker ? std::make_unique<KeyCharacterMap>(*other.mKeyCharacterMap)
196*38e8c45fSAndroid Build Coastguard Worker : nullptr),
197*38e8c45fSAndroid Build Coastguard Worker mUsiVersion(other.mUsiVersion),
198*38e8c45fSAndroid Build Coastguard Worker mAssociatedDisplayId(other.mAssociatedDisplayId),
199*38e8c45fSAndroid Build Coastguard Worker mEnabled(other.mEnabled),
200*38e8c45fSAndroid Build Coastguard Worker mHasVibrator(other.mHasVibrator),
201*38e8c45fSAndroid Build Coastguard Worker mHasBattery(other.mHasBattery),
202*38e8c45fSAndroid Build Coastguard Worker mHasButtonUnderPad(other.mHasButtonUnderPad),
203*38e8c45fSAndroid Build Coastguard Worker mHasSensor(other.mHasSensor),
204*38e8c45fSAndroid Build Coastguard Worker mMotionRanges(other.mMotionRanges),
205*38e8c45fSAndroid Build Coastguard Worker mSensors(other.mSensors),
206*38e8c45fSAndroid Build Coastguard Worker mLights(other.mLights),
207*38e8c45fSAndroid Build Coastguard Worker mViewBehavior(other.mViewBehavior) {}
208*38e8c45fSAndroid Build Coastguard Worker
operator =(const InputDeviceInfo & other)209*38e8c45fSAndroid Build Coastguard Worker InputDeviceInfo& InputDeviceInfo::operator=(const InputDeviceInfo& other) {
210*38e8c45fSAndroid Build Coastguard Worker mId = other.mId;
211*38e8c45fSAndroid Build Coastguard Worker mGeneration = other.mGeneration;
212*38e8c45fSAndroid Build Coastguard Worker mControllerNumber = other.mControllerNumber;
213*38e8c45fSAndroid Build Coastguard Worker mIdentifier = other.mIdentifier;
214*38e8c45fSAndroid Build Coastguard Worker mAlias = other.mAlias;
215*38e8c45fSAndroid Build Coastguard Worker mIsExternal = other.mIsExternal;
216*38e8c45fSAndroid Build Coastguard Worker mHasMic = other.mHasMic;
217*38e8c45fSAndroid Build Coastguard Worker mKeyboardLayoutInfo = other.mKeyboardLayoutInfo;
218*38e8c45fSAndroid Build Coastguard Worker mSources = other.mSources;
219*38e8c45fSAndroid Build Coastguard Worker mKeyboardType = other.mKeyboardType;
220*38e8c45fSAndroid Build Coastguard Worker mKeyCharacterMap = other.mKeyCharacterMap
221*38e8c45fSAndroid Build Coastguard Worker ? std::make_unique<KeyCharacterMap>(*other.mKeyCharacterMap)
222*38e8c45fSAndroid Build Coastguard Worker : nullptr;
223*38e8c45fSAndroid Build Coastguard Worker mUsiVersion = other.mUsiVersion;
224*38e8c45fSAndroid Build Coastguard Worker mAssociatedDisplayId = other.mAssociatedDisplayId;
225*38e8c45fSAndroid Build Coastguard Worker mEnabled = other.mEnabled;
226*38e8c45fSAndroid Build Coastguard Worker mHasVibrator = other.mHasVibrator;
227*38e8c45fSAndroid Build Coastguard Worker mHasBattery = other.mHasBattery;
228*38e8c45fSAndroid Build Coastguard Worker mHasButtonUnderPad = other.mHasButtonUnderPad;
229*38e8c45fSAndroid Build Coastguard Worker mHasSensor = other.mHasSensor;
230*38e8c45fSAndroid Build Coastguard Worker mMotionRanges = other.mMotionRanges;
231*38e8c45fSAndroid Build Coastguard Worker mSensors = other.mSensors;
232*38e8c45fSAndroid Build Coastguard Worker mLights = other.mLights;
233*38e8c45fSAndroid Build Coastguard Worker mViewBehavior = other.mViewBehavior;
234*38e8c45fSAndroid Build Coastguard Worker return *this;
235*38e8c45fSAndroid Build Coastguard Worker }
236*38e8c45fSAndroid Build Coastguard Worker
~InputDeviceInfo()237*38e8c45fSAndroid Build Coastguard Worker InputDeviceInfo::~InputDeviceInfo() {
238*38e8c45fSAndroid Build Coastguard Worker }
239*38e8c45fSAndroid Build Coastguard Worker
initialize(int32_t id,int32_t generation,int32_t controllerNumber,const InputDeviceIdentifier & identifier,const std::string & alias,bool isExternal,bool hasMic,ui::LogicalDisplayId associatedDisplayId,InputDeviceViewBehavior viewBehavior,bool enabled)240*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber,
241*38e8c45fSAndroid Build Coastguard Worker const InputDeviceIdentifier& identifier, const std::string& alias,
242*38e8c45fSAndroid Build Coastguard Worker bool isExternal, bool hasMic,
243*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId associatedDisplayId,
244*38e8c45fSAndroid Build Coastguard Worker InputDeviceViewBehavior viewBehavior, bool enabled) {
245*38e8c45fSAndroid Build Coastguard Worker mId = id;
246*38e8c45fSAndroid Build Coastguard Worker mGeneration = generation;
247*38e8c45fSAndroid Build Coastguard Worker mControllerNumber = controllerNumber;
248*38e8c45fSAndroid Build Coastguard Worker mIdentifier = identifier;
249*38e8c45fSAndroid Build Coastguard Worker mAlias = alias;
250*38e8c45fSAndroid Build Coastguard Worker mIsExternal = isExternal;
251*38e8c45fSAndroid Build Coastguard Worker mHasMic = hasMic;
252*38e8c45fSAndroid Build Coastguard Worker mSources = 0;
253*38e8c45fSAndroid Build Coastguard Worker mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
254*38e8c45fSAndroid Build Coastguard Worker mAssociatedDisplayId = associatedDisplayId;
255*38e8c45fSAndroid Build Coastguard Worker mEnabled = enabled;
256*38e8c45fSAndroid Build Coastguard Worker mHasVibrator = false;
257*38e8c45fSAndroid Build Coastguard Worker mHasBattery = false;
258*38e8c45fSAndroid Build Coastguard Worker mHasButtonUnderPad = false;
259*38e8c45fSAndroid Build Coastguard Worker mHasSensor = false;
260*38e8c45fSAndroid Build Coastguard Worker mViewBehavior = viewBehavior;
261*38e8c45fSAndroid Build Coastguard Worker mUsiVersion.reset();
262*38e8c45fSAndroid Build Coastguard Worker mMotionRanges.clear();
263*38e8c45fSAndroid Build Coastguard Worker mSensors.clear();
264*38e8c45fSAndroid Build Coastguard Worker mLights.clear();
265*38e8c45fSAndroid Build Coastguard Worker }
266*38e8c45fSAndroid Build Coastguard Worker
getMotionRange(int32_t axis,uint32_t source) const267*38e8c45fSAndroid Build Coastguard Worker const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(
268*38e8c45fSAndroid Build Coastguard Worker int32_t axis, uint32_t source) const {
269*38e8c45fSAndroid Build Coastguard Worker for (const MotionRange& range : mMotionRanges) {
270*38e8c45fSAndroid Build Coastguard Worker if (range.axis == axis && isFromSource(range.source, source)) {
271*38e8c45fSAndroid Build Coastguard Worker return ⦥
272*38e8c45fSAndroid Build Coastguard Worker }
273*38e8c45fSAndroid Build Coastguard Worker }
274*38e8c45fSAndroid Build Coastguard Worker return nullptr;
275*38e8c45fSAndroid Build Coastguard Worker }
276*38e8c45fSAndroid Build Coastguard Worker
addSource(uint32_t source)277*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addSource(uint32_t source) {
278*38e8c45fSAndroid Build Coastguard Worker mSources |= source;
279*38e8c45fSAndroid Build Coastguard Worker }
280*38e8c45fSAndroid Build Coastguard Worker
addMotionRange(int32_t axis,uint32_t source,float min,float max,float flat,float fuzz,float resolution)281*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addMotionRange(int32_t axis, uint32_t source, float min, float max,
282*38e8c45fSAndroid Build Coastguard Worker float flat, float fuzz, float resolution) {
283*38e8c45fSAndroid Build Coastguard Worker MotionRange range = { axis, source, min, max, flat, fuzz, resolution };
284*38e8c45fSAndroid Build Coastguard Worker mMotionRanges.push_back(range);
285*38e8c45fSAndroid Build Coastguard Worker }
286*38e8c45fSAndroid Build Coastguard Worker
addMotionRange(const MotionRange & range)287*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addMotionRange(const MotionRange& range) {
288*38e8c45fSAndroid Build Coastguard Worker mMotionRanges.push_back(range);
289*38e8c45fSAndroid Build Coastguard Worker }
290*38e8c45fSAndroid Build Coastguard Worker
addSensorInfo(const InputDeviceSensorInfo & info)291*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addSensorInfo(const InputDeviceSensorInfo& info) {
292*38e8c45fSAndroid Build Coastguard Worker if (mSensors.find(info.type) != mSensors.end()) {
293*38e8c45fSAndroid Build Coastguard Worker ALOGW("Sensor type %s already exists, will be replaced by new sensor added.",
294*38e8c45fSAndroid Build Coastguard Worker ftl::enum_string(info.type).c_str());
295*38e8c45fSAndroid Build Coastguard Worker }
296*38e8c45fSAndroid Build Coastguard Worker mSensors.insert_or_assign(info.type, info);
297*38e8c45fSAndroid Build Coastguard Worker }
298*38e8c45fSAndroid Build Coastguard Worker
addBatteryInfo(const InputDeviceBatteryInfo & info)299*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addBatteryInfo(const InputDeviceBatteryInfo& info) {
300*38e8c45fSAndroid Build Coastguard Worker if (mBatteries.find(info.id) != mBatteries.end()) {
301*38e8c45fSAndroid Build Coastguard Worker ALOGW("Battery id %d already exists, will be replaced by new battery added.", info.id);
302*38e8c45fSAndroid Build Coastguard Worker }
303*38e8c45fSAndroid Build Coastguard Worker mBatteries.insert_or_assign(info.id, info);
304*38e8c45fSAndroid Build Coastguard Worker }
305*38e8c45fSAndroid Build Coastguard Worker
addLightInfo(const InputDeviceLightInfo & info)306*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::addLightInfo(const InputDeviceLightInfo& info) {
307*38e8c45fSAndroid Build Coastguard Worker if (mLights.find(info.id) != mLights.end()) {
308*38e8c45fSAndroid Build Coastguard Worker ALOGW("Light id %d already exists, will be replaced by new light added.", info.id);
309*38e8c45fSAndroid Build Coastguard Worker }
310*38e8c45fSAndroid Build Coastguard Worker mLights.insert_or_assign(info.id, info);
311*38e8c45fSAndroid Build Coastguard Worker }
312*38e8c45fSAndroid Build Coastguard Worker
setKeyboardType(int32_t keyboardType)313*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::setKeyboardType(int32_t keyboardType) {
314*38e8c45fSAndroid Build Coastguard Worker mKeyboardType = keyboardType;
315*38e8c45fSAndroid Build Coastguard Worker }
316*38e8c45fSAndroid Build Coastguard Worker
setKeyboardLayoutInfo(KeyboardLayoutInfo layoutInfo)317*38e8c45fSAndroid Build Coastguard Worker void InputDeviceInfo::setKeyboardLayoutInfo(KeyboardLayoutInfo layoutInfo) {
318*38e8c45fSAndroid Build Coastguard Worker mKeyboardLayoutInfo = std::move(layoutInfo);
319*38e8c45fSAndroid Build Coastguard Worker }
320*38e8c45fSAndroid Build Coastguard Worker
getSensors()321*38e8c45fSAndroid Build Coastguard Worker std::vector<InputDeviceSensorInfo> InputDeviceInfo::getSensors() {
322*38e8c45fSAndroid Build Coastguard Worker std::vector<InputDeviceSensorInfo> infos;
323*38e8c45fSAndroid Build Coastguard Worker infos.reserve(mSensors.size());
324*38e8c45fSAndroid Build Coastguard Worker for (const auto& [type, info] : mSensors) {
325*38e8c45fSAndroid Build Coastguard Worker infos.push_back(info);
326*38e8c45fSAndroid Build Coastguard Worker }
327*38e8c45fSAndroid Build Coastguard Worker return infos;
328*38e8c45fSAndroid Build Coastguard Worker }
329*38e8c45fSAndroid Build Coastguard Worker
getLights()330*38e8c45fSAndroid Build Coastguard Worker std::vector<InputDeviceLightInfo> InputDeviceInfo::getLights() {
331*38e8c45fSAndroid Build Coastguard Worker std::vector<InputDeviceLightInfo> infos;
332*38e8c45fSAndroid Build Coastguard Worker infos.reserve(mLights.size());
333*38e8c45fSAndroid Build Coastguard Worker for (const auto& [id, info] : mLights) {
334*38e8c45fSAndroid Build Coastguard Worker infos.push_back(info);
335*38e8c45fSAndroid Build Coastguard Worker }
336*38e8c45fSAndroid Build Coastguard Worker return infos;
337*38e8c45fSAndroid Build Coastguard Worker }
338*38e8c45fSAndroid Build Coastguard Worker
339*38e8c45fSAndroid Build Coastguard Worker } // namespace android
340