blob: 4626f5add7389fddcb83723c69f4cdada6a24a03 [file] [log] [blame]
Harry Cuttsa5b71292022-11-28 12:56:17 +00001/*
2 * Copyright 2022 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#include "FakeEventHub.h"
18
19#include <android-base/thread_annotations.h>
20#include <gtest/gtest.h>
21#include <linux/input-event-codes.h>
22
23#include "TestConstants.h"
24
25namespace android {
26
27const std::string FakeEventHub::BATTERY_DEVPATH = "/sys/devices/mydevice/power_supply/mybattery";
28
29FakeEventHub::~FakeEventHub() {
30 for (size_t i = 0; i < mDevices.size(); i++) {
31 delete mDevices.valueAt(i);
32 }
33}
34
35void FakeEventHub::addDevice(int32_t deviceId, const std::string& name,
36 ftl::Flags<InputDeviceClass> classes, int bus) {
37 Device* device = new Device(classes);
38 device->identifier.name = name;
39 device->identifier.bus = bus;
40 mDevices.add(deviceId, device);
41
42 enqueueEvent(ARBITRARY_TIME, READ_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
43}
44
45void FakeEventHub::removeDevice(int32_t deviceId) {
46 delete mDevices.valueFor(deviceId);
47 mDevices.removeItem(deviceId);
48
49 enqueueEvent(ARBITRARY_TIME, READ_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
50}
51
52bool FakeEventHub::isDeviceEnabled(int32_t deviceId) const {
53 Device* device = getDevice(deviceId);
54 if (device == nullptr) {
55 ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__);
56 return false;
57 }
58 return device->enabled;
59}
60
61status_t FakeEventHub::enableDevice(int32_t deviceId) {
62 status_t result;
63 Device* device = getDevice(deviceId);
64 if (device == nullptr) {
65 ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__);
66 return BAD_VALUE;
67 }
68 if (device->enabled) {
69 ALOGW("Duplicate call to %s, device %" PRId32 " already enabled", __func__, deviceId);
70 return OK;
71 }
72 result = device->enable();
73 return result;
74}
75
76status_t FakeEventHub::disableDevice(int32_t deviceId) {
77 Device* device = getDevice(deviceId);
78 if (device == nullptr) {
79 ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__);
80 return BAD_VALUE;
81 }
82 if (!device->enabled) {
83 ALOGW("Duplicate call to %s, device %" PRId32 " already disabled", __func__, deviceId);
84 return OK;
85 }
86 return device->disable();
87}
88
89void FakeEventHub::finishDeviceScan() {
90 enqueueEvent(ARBITRARY_TIME, READ_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
91}
92
93void FakeEventHub::addConfigurationProperty(int32_t deviceId, const char* key, const char* value) {
94 getDevice(deviceId)->configuration.addProperty(key, value);
95}
96
97void FakeEventHub::addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) {
98 getDevice(deviceId)->configuration.addAll(configuration);
99}
100
101void FakeEventHub::addAbsoluteAxis(int32_t deviceId, int axis, int32_t minValue, int32_t maxValue,
102 int flat, int fuzz, int resolution) {
103 Device* device = getDevice(deviceId);
104
105 RawAbsoluteAxisInfo info;
106 info.valid = true;
107 info.minValue = minValue;
108 info.maxValue = maxValue;
109 info.flat = flat;
110 info.fuzz = fuzz;
111 info.resolution = resolution;
112 device->absoluteAxes.add(axis, info);
113}
114
115void FakeEventHub::addRelativeAxis(int32_t deviceId, int32_t axis) {
116 getDevice(deviceId)->relativeAxes.add(axis, true);
117}
118
119void FakeEventHub::setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) {
120 getDevice(deviceId)->keyCodeStates.replaceValueFor(keyCode, state);
121}
122
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000123void FakeEventHub::setRawLayoutInfo(int32_t deviceId, RawLayoutInfo info) {
124 getDevice(deviceId)->layoutInfo = info;
Harry Cuttsa5b71292022-11-28 12:56:17 +0000125}
126
127void FakeEventHub::setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) {
128 getDevice(deviceId)->scanCodeStates.replaceValueFor(scanCode, state);
129}
130
131void FakeEventHub::setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) {
132 getDevice(deviceId)->switchStates.replaceValueFor(switchCode, state);
133}
134
135void FakeEventHub::setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) {
136 getDevice(deviceId)->absoluteAxisValue.replaceValueFor(axis, value);
137}
138
139void FakeEventHub::addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t keyCode,
140 uint32_t flags) {
141 Device* device = getDevice(deviceId);
142 KeyInfo info;
143 info.keyCode = keyCode;
144 info.flags = flags;
145 if (scanCode) {
146 device->keysByScanCode.add(scanCode, info);
147 }
148 if (usageCode) {
149 device->keysByUsageCode.add(usageCode, info);
150 }
151}
152
153void FakeEventHub::addKeyCodeMapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) {
154 getDevice(deviceId)->keyCodeMapping.insert_or_assign(fromKeyCode, toKeyCode);
155}
156
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000157void FakeEventHub::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const {
158 Device* device = getDevice(deviceId);
159 device->keyRemapping.insert_or_assign(fromKeyCode, toKeyCode);
160}
161
Harry Cuttsa5b71292022-11-28 12:56:17 +0000162void FakeEventHub::addLed(int32_t deviceId, int32_t led, bool initialState) {
163 getDevice(deviceId)->leds.add(led, initialState);
164}
165
166void FakeEventHub::addSensorAxis(int32_t deviceId, int32_t absCode,
167 InputDeviceSensorType sensorType, int32_t sensorDataIndex) {
168 SensorInfo info;
169 info.sensorType = sensorType;
170 info.sensorDataIndex = sensorDataIndex;
171 getDevice(deviceId)->sensorsByAbsCode.emplace(absCode, info);
172}
173
174void FakeEventHub::setMscEvent(int32_t deviceId, int32_t mscEvent) {
175 typename BitArray<MSC_MAX>::Buffer buffer;
176 buffer[mscEvent / 32] = 1 << mscEvent % 32;
177 getDevice(deviceId)->mscBitmask.loadFromBuffer(buffer);
178}
179
180void FakeEventHub::addRawLightInfo(int32_t rawId, RawLightInfo&& info) {
181 mRawLightInfos.emplace(rawId, std::move(info));
182}
183
184void FakeEventHub::fakeLightBrightness(int32_t rawId, int32_t brightness) {
185 mLightBrightness.emplace(rawId, brightness);
186}
187
188void FakeEventHub::fakeLightIntensities(int32_t rawId,
189 const std::unordered_map<LightColor, int32_t> intensities) {
190 mLightIntensities.emplace(rawId, std::move(intensities));
191}
192
193bool FakeEventHub::getLedState(int32_t deviceId, int32_t led) {
194 return getDevice(deviceId)->leds.valueFor(led);
195}
196
197std::vector<std::string>& FakeEventHub::getExcludedDevices() {
198 return mExcludedDevices;
199}
200
201void FakeEventHub::addVirtualKeyDefinition(int32_t deviceId,
202 const VirtualKeyDefinition& definition) {
203 getDevice(deviceId)->virtualKeys.push_back(definition);
204}
205
206void FakeEventHub::enqueueEvent(nsecs_t when, nsecs_t readTime, int32_t deviceId, int32_t type,
207 int32_t code, int32_t value) {
208 std::scoped_lock<std::mutex> lock(mLock);
209 RawEvent event;
210 event.when = when;
211 event.readTime = readTime;
212 event.deviceId = deviceId;
213 event.type = type;
214 event.code = code;
215 event.value = value;
216 mEvents.push_back(event);
217
218 if (type == EV_ABS) {
219 setAbsoluteAxisValue(deviceId, code, value);
220 }
221}
222
223void FakeEventHub::setVideoFrames(
224 std::unordered_map<int32_t /*deviceId*/, std::vector<TouchVideoFrame>> videoFrames) {
225 mVideoFrames = std::move(videoFrames);
226}
227
228void FakeEventHub::assertQueueIsEmpty() {
229 std::unique_lock<std::mutex> lock(mLock);
230 base::ScopedLockAssertion assumeLocked(mLock);
231 const bool queueIsEmpty =
232 mEventsCondition.wait_for(lock, WAIT_TIMEOUT,
233 [this]() REQUIRES(mLock) { return mEvents.size() == 0; });
234 if (!queueIsEmpty) {
235 FAIL() << "Timed out waiting for EventHub queue to be emptied.";
236 }
237}
238
239FakeEventHub::Device* FakeEventHub::getDevice(int32_t deviceId) const {
240 ssize_t index = mDevices.indexOfKey(deviceId);
241 return index >= 0 ? mDevices.valueAt(index) : nullptr;
242}
243
244ftl::Flags<InputDeviceClass> FakeEventHub::getDeviceClasses(int32_t deviceId) const {
245 Device* device = getDevice(deviceId);
246 return device ? device->classes : ftl::Flags<InputDeviceClass>(0);
247}
248
249InputDeviceIdentifier FakeEventHub::getDeviceIdentifier(int32_t deviceId) const {
250 Device* device = getDevice(deviceId);
251 return device ? device->identifier : InputDeviceIdentifier();
252}
253
254int32_t FakeEventHub::getDeviceControllerNumber(int32_t) const {
255 return 0;
256}
257
Harry Cuttsc34f7582023-03-07 16:23:30 +0000258std::optional<PropertyMap> FakeEventHub::getConfiguration(int32_t deviceId) const {
Harry Cuttsa5b71292022-11-28 12:56:17 +0000259 Device* device = getDevice(deviceId);
Harry Cuttsc34f7582023-03-07 16:23:30 +0000260 if (device == nullptr) {
261 return {};
Harry Cuttsa5b71292022-11-28 12:56:17 +0000262 }
Harry Cuttsc34f7582023-03-07 16:23:30 +0000263 return device->configuration;
Harry Cuttsa5b71292022-11-28 12:56:17 +0000264}
265
266status_t FakeEventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
267 RawAbsoluteAxisInfo* outAxisInfo) const {
268 Device* device = getDevice(deviceId);
269 if (device) {
270 ssize_t index = device->absoluteAxes.indexOfKey(axis);
271 if (index >= 0) {
272 *outAxisInfo = device->absoluteAxes.valueAt(index);
273 return OK;
274 }
275 }
276 outAxisInfo->clear();
277 return -1;
278}
279
280bool FakeEventHub::hasRelativeAxis(int32_t deviceId, int axis) const {
281 Device* device = getDevice(deviceId);
282 if (device) {
283 return device->relativeAxes.indexOfKey(axis) >= 0;
284 }
285 return false;
286}
287
288bool FakeEventHub::hasInputProperty(int32_t, int) const {
289 return false;
290}
291
292bool FakeEventHub::hasMscEvent(int32_t deviceId, int mscEvent) const {
293 Device* device = getDevice(deviceId);
294 if (device) {
295 return mscEvent >= 0 && mscEvent <= MSC_MAX ? device->mscBitmask.test(mscEvent) : false;
296 }
297 return false;
298}
299
300status_t FakeEventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
301 int32_t metaState, int32_t* outKeycode, int32_t* outMetaState,
302 uint32_t* outFlags) const {
303 Device* device = getDevice(deviceId);
304 if (device) {
305 const KeyInfo* key = getKey(device, scanCode, usageCode);
306 if (key) {
307 if (outKeycode) {
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000308 auto it = device->keyRemapping.find(key->keyCode);
309 *outKeycode = it != device->keyRemapping.end() ? it->second : key->keyCode;
Harry Cuttsa5b71292022-11-28 12:56:17 +0000310 }
311 if (outFlags) {
312 *outFlags = key->flags;
313 }
314 if (outMetaState) {
315 *outMetaState = metaState;
316 }
317 return OK;
318 }
319 }
320 return NAME_NOT_FOUND;
321}
322
323const FakeEventHub::KeyInfo* FakeEventHub::getKey(Device* device, int32_t scanCode,
324 int32_t usageCode) const {
325 if (usageCode) {
326 ssize_t index = device->keysByUsageCode.indexOfKey(usageCode);
327 if (index >= 0) {
328 return &device->keysByUsageCode.valueAt(index);
329 }
330 }
331 if (scanCode) {
332 ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
333 if (index >= 0) {
334 return &device->keysByScanCode.valueAt(index);
335 }
336 }
337 return nullptr;
338}
339
340status_t FakeEventHub::mapAxis(int32_t, int32_t, AxisInfo*) const {
341 return NAME_NOT_FOUND;
342}
343
344base::Result<std::pair<InputDeviceSensorType, int32_t>> FakeEventHub::mapSensor(
345 int32_t deviceId, int32_t absCode) const {
346 Device* device = getDevice(deviceId);
347 if (!device) {
348 return Errorf("Sensor device not found.");
349 }
350 auto it = device->sensorsByAbsCode.find(absCode);
351 if (it == device->sensorsByAbsCode.end()) {
352 return Errorf("Sensor map not found.");
353 }
354 const SensorInfo& info = it->second;
355 return std::make_pair(info.sensorType, info.sensorDataIndex);
356}
357
358void FakeEventHub::setExcludedDevices(const std::vector<std::string>& devices) {
359 mExcludedDevices = devices;
360}
361
362std::vector<RawEvent> FakeEventHub::getEvents(int) {
363 std::scoped_lock lock(mLock);
364
365 std::vector<RawEvent> buffer;
366 std::swap(buffer, mEvents);
367
368 mEventsCondition.notify_all();
369 return buffer;
370}
371
372std::vector<TouchVideoFrame> FakeEventHub::getVideoFrames(int32_t deviceId) {
373 auto it = mVideoFrames.find(deviceId);
374 if (it != mVideoFrames.end()) {
375 std::vector<TouchVideoFrame> frames = std::move(it->second);
376 mVideoFrames.erase(deviceId);
377 return frames;
378 }
379 return {};
380}
381
382int32_t FakeEventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
383 Device* device = getDevice(deviceId);
384 if (device) {
385 ssize_t index = device->scanCodeStates.indexOfKey(scanCode);
386 if (index >= 0) {
387 return device->scanCodeStates.valueAt(index);
388 }
389 }
390 return AKEY_STATE_UNKNOWN;
391}
392
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000393std::optional<RawLayoutInfo> FakeEventHub::getRawLayoutInfo(int32_t deviceId) const {
Harry Cuttsa5b71292022-11-28 12:56:17 +0000394 Device* device = getDevice(deviceId);
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000395 return device ? device->layoutInfo : std::nullopt;
Harry Cuttsa5b71292022-11-28 12:56:17 +0000396}
397
398int32_t FakeEventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
399 Device* device = getDevice(deviceId);
400 if (device) {
401 ssize_t index = device->keyCodeStates.indexOfKey(keyCode);
402 if (index >= 0) {
403 return device->keyCodeStates.valueAt(index);
404 }
405 }
406 return AKEY_STATE_UNKNOWN;
407}
408
409int32_t FakeEventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
410 Device* device = getDevice(deviceId);
411 if (device) {
412 ssize_t index = device->switchStates.indexOfKey(sw);
413 if (index >= 0) {
414 return device->switchStates.valueAt(index);
415 }
416 }
417 return AKEY_STATE_UNKNOWN;
418}
419
420status_t FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
421 int32_t* outValue) const {
422 Device* device = getDevice(deviceId);
423 if (device) {
424 ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
425 if (index >= 0) {
426 *outValue = device->absoluteAxisValue.valueAt(index);
427 return OK;
428 }
429 }
430 *outValue = 0;
431 return -1;
432}
433
434int32_t FakeEventHub::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const {
435 Device* device = getDevice(deviceId);
436 if (!device) {
437 return AKEYCODE_UNKNOWN;
438 }
439 auto it = device->keyCodeMapping.find(locationKeyCode);
440 return it != device->keyCodeMapping.end() ? it->second : locationKeyCode;
441}
442
443// Return true if the device has non-empty key layout.
444bool FakeEventHub::markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
445 uint8_t* outFlags) const {
446 Device* device = getDevice(deviceId);
447 if (!device) return false;
448
449 bool result = device->keysByScanCode.size() > 0 || device->keysByUsageCode.size() > 0;
450 for (size_t i = 0; i < keyCodes.size(); i++) {
451 for (size_t j = 0; j < device->keysByScanCode.size(); j++) {
452 if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) {
453 outFlags[i] = 1;
454 }
455 }
456 for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
457 if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) {
458 outFlags[i] = 1;
459 }
460 }
461 }
462 return result;
463}
464
465bool FakeEventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const {
466 Device* device = getDevice(deviceId);
467 if (device) {
468 ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
469 return index >= 0;
470 }
471 return false;
472}
473
474bool FakeEventHub::hasKeyCode(int32_t deviceId, int32_t keyCode) const {
475 Device* device = getDevice(deviceId);
476 if (!device) {
477 return false;
478 }
479 for (size_t i = 0; i < device->keysByScanCode.size(); i++) {
480 if (keyCode == device->keysByScanCode.valueAt(i).keyCode) {
481 return true;
482 }
483 }
484 for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
485 if (keyCode == device->keysByUsageCode.valueAt(j).keyCode) {
486 return true;
487 }
488 }
489 return false;
490}
491
492bool FakeEventHub::hasLed(int32_t deviceId, int32_t led) const {
493 Device* device = getDevice(deviceId);
494 return device && device->leds.indexOfKey(led) >= 0;
495}
496
497void FakeEventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
498 Device* device = getDevice(deviceId);
499 if (device) {
500 ssize_t index = device->leds.indexOfKey(led);
501 if (index >= 0) {
502 device->leds.replaceValueAt(led, on);
503 } else {
504 ADD_FAILURE() << "Attempted to set the state of an LED that the EventHub declared "
505 "was not present. led="
506 << led;
507 }
508 }
509}
510
511void FakeEventHub::getVirtualKeyDefinitions(
512 int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
513 outVirtualKeys.clear();
514
515 Device* device = getDevice(deviceId);
516 if (device) {
517 outVirtualKeys = device->virtualKeys;
518 }
519}
520
521const std::shared_ptr<KeyCharacterMap> FakeEventHub::getKeyCharacterMap(int32_t) const {
522 return nullptr;
523}
524
525bool FakeEventHub::setKeyboardLayoutOverlay(int32_t, std::shared_ptr<KeyCharacterMap>) {
526 return false;
527}
528
529std::vector<int32_t> FakeEventHub::getVibratorIds(int32_t deviceId) const {
530 return mVibrators;
531}
532
533std::optional<int32_t> FakeEventHub::getBatteryCapacity(int32_t, int32_t) const {
534 return BATTERY_CAPACITY;
535}
536
537std::optional<int32_t> FakeEventHub::getBatteryStatus(int32_t, int32_t) const {
538 return BATTERY_STATUS;
539}
540
541std::vector<int32_t> FakeEventHub::getRawBatteryIds(int32_t deviceId) const {
542 return {DEFAULT_BATTERY};
543}
544
545std::optional<RawBatteryInfo> FakeEventHub::getRawBatteryInfo(int32_t deviceId,
546 int32_t batteryId) const {
547 if (batteryId != DEFAULT_BATTERY) return {};
548 static const auto BATTERY_INFO = RawBatteryInfo{.id = DEFAULT_BATTERY,
549 .name = "default battery",
550 .flags = InputBatteryClass::CAPACITY,
551 .path = BATTERY_DEVPATH};
552 return BATTERY_INFO;
553}
554
555std::vector<int32_t> FakeEventHub::getRawLightIds(int32_t deviceId) const {
556 std::vector<int32_t> ids;
557 for (const auto& [rawId, info] : mRawLightInfos) {
558 ids.push_back(rawId);
559 }
560 return ids;
561}
562
563std::optional<RawLightInfo> FakeEventHub::getRawLightInfo(int32_t deviceId, int32_t lightId) const {
564 auto it = mRawLightInfos.find(lightId);
565 if (it == mRawLightInfos.end()) {
566 return std::nullopt;
567 }
568 return it->second;
569}
570
571void FakeEventHub::setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) {
572 mLightBrightness.emplace(lightId, brightness);
573}
574
575void FakeEventHub::setLightIntensities(int32_t deviceId, int32_t lightId,
576 std::unordered_map<LightColor, int32_t> intensities) {
577 mLightIntensities.emplace(lightId, intensities);
578};
579
580std::optional<int32_t> FakeEventHub::getLightBrightness(int32_t deviceId, int32_t lightId) const {
581 auto lightIt = mLightBrightness.find(lightId);
582 if (lightIt == mLightBrightness.end()) {
583 return std::nullopt;
584 }
585 return lightIt->second;
586}
587
588std::optional<std::unordered_map<LightColor, int32_t>> FakeEventHub::getLightIntensities(
589 int32_t deviceId, int32_t lightId) const {
590 auto lightIt = mLightIntensities.find(lightId);
591 if (lightIt == mLightIntensities.end()) {
592 return std::nullopt;
593 }
594 return lightIt->second;
595};
596
Vaibhav Devmurari5fc7d852023-03-17 18:43:33 +0000597void FakeEventHub::setSysfsRootPath(int32_t deviceId, std::string sysfsRootPath) const {
598 Device* device = getDevice(deviceId);
599 if (device == nullptr) {
600 return;
601 }
602 device->sysfsRootPath = sysfsRootPath;
603}
604
605void FakeEventHub::sysfsNodeChanged(const std::string& sysfsNodePath) {
606 int32_t foundDeviceId = -1;
607 Device* foundDevice = nullptr;
608 for (size_t i = 0; i < mDevices.size(); i++) {
609 Device* d = mDevices.valueAt(i);
610 if (sysfsNodePath.find(d->sysfsRootPath) != std::string::npos) {
611 foundDeviceId = mDevices.keyAt(i);
612 foundDevice = d;
613 }
614 }
615 if (foundDevice == nullptr) {
616 return;
617 }
618 // If device sysfs changed -> reopen the device
619 if (!mRawLightInfos.empty() && !foundDevice->classes.test(InputDeviceClass::LIGHT)) {
620 removeDevice(foundDeviceId);
621 addDevice(foundDeviceId, foundDevice->identifier.name,
622 foundDevice->classes | InputDeviceClass::LIGHT, foundDevice->identifier.bus);
623 }
624}
625
Harry Cuttsa5b71292022-11-28 12:56:17 +0000626} // namespace android