From 7d6cbd4c26ba81dbfacca6bdc2956bcba92da3b1 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Mon, 30 Oct 2023 19:51:24 +0800 Subject: [PATCH] modify touchpad error, improve log Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 18 ++++++------ common/include/input_hub.h | 2 +- utils/src/dinput_utils_tool.cpp | 49 ++++++--------------------------- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index d7fe27f..54388e4 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -171,9 +171,12 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) size_t count = ReadInputEvent(readSize, *GetDeviceByFdLocked(eventItem.data.fd)); Device* device = GetSupportDeviceByFd(eventItem.data.fd); if (!device) { + DHLOGE("Can not find device by fd: %d", eventItem.data.fd); continue; } if (!sharedDHIds_[device->identifier.descriptor]) { + DHLOGE("Not in sharing stat, device descriptor: %s", + GetAnonyString(device->identifier.descriptor).c_str()); continue; } DHLOGD("shared device dhId: %s, name: %s", GetAnonyString(device->identifier.descriptor).c_str(), @@ -434,6 +437,7 @@ bool InputHub::IsDeviceRegistered(const std::string &devicePath) std::lock_guard deviceLock(devicesMutex_); for (const auto &[deviceId, device] : devices_) { if (device->path == devicePath) { + DHLOGI("Device node already registered, node path: %s", device->path.c_str()); return true; // device was already registered } } @@ -447,7 +451,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) } std::lock_guard my_lock(operationMutex_); - DHLOGI("Opening device: %s", devicePath.c_str()); + DHLOGI("Opening device start: %s", devicePath.c_str()); int fd = OpenInputDeviceFdByPath(devicePath); if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); @@ -468,9 +472,11 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) if (MakeDevice(fd, std::move(device)) < 0) { CloseFd(fd); + DHLOGI("Opening device error: %s", devicePath.c_str()); return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } + DHLOGI("Opening device finish: %s", devicePath.c_str()); return DH_SUCCESS; } @@ -714,12 +720,12 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) if (TestBit(BTN_TOUCH, device->keyBitmask) && TestBit(ABS_MT_POSITION_X, device->absBitmask) && TestBit(ABS_MT_POSITION_Y, device->absBitmask)) { - QueryLocalTouchScreenInfo(fd); + QueryLocalTouchScreenInfo(fd, device); device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; } else if (TestBit(BTN_TOUCH, device->keyBitmask) && TestBit(ABS_X, device->absBitmask) && TestBit(ABS_Y, device->absBitmask)) { - QueryLocalTouchScreenInfo(fd); + QueryLocalTouchScreenInfo(fd, device); device->classes |= INPUT_DEVICE_CLASS_TOUCH; } @@ -760,13 +766,9 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) return DH_SUCCESS; } -int32_t InputHub::QueryLocalTouchScreenInfo(int fd) +int32_t InputHub::QueryLocalTouchScreenInfo(int fd, std::unique_ptr &device) { LocalTouchScreenInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo(); - std::unique_ptr device = std::make_unique(fd, 0, ""); - if (QueryInputDeviceInfo(fd, device) < 0) { - return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; - } device->identifier.classes |= INPUT_DEVICE_CLASS_TOUCH_MT; info.localAbsInfo.deviceInfo = device->identifier; diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 8068a56..b9fada6 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -158,7 +158,7 @@ private: void RecordEventLog(const RawEvent *event); void RecordDeviceLog(const int32_t deviceId, const std::string &devicePath, const InputDevice &identifier); void HandleTouchScreenEvent(struct input_event readBuffer[], const size_t count, std::vector &needFilted); - int32_t QueryLocalTouchScreenInfo(int fd); + int32_t QueryLocalTouchScreenInfo(int fd, std::unique_ptr &device); bool CheckTouchPointRegion(struct input_event readBuffer[], const AbsInfo &absInfo); size_t CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[], const size_t count); diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 317c443..9d08470 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -139,76 +139,44 @@ std::string SetAnonyId(const std::string &message) bool IsBoolean(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_boolean(); - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_boolean(); } bool IsString(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_string(); - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_string(); } bool IsInt32(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_number_integer() && INT32_MIN <= jsonObj[key] && + return jsonObj.contains(key) && jsonObj[key].is_number_integer() && INT32_MIN <= jsonObj[key] && jsonObj[key] <= INT32_MAX; - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; } bool IsInt64(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_number_integer() && INT64_MIN <= jsonObj[key] && + return jsonObj.contains(key) && jsonObj[key].is_number_integer() && INT64_MIN <= jsonObj[key] && jsonObj[key] <= INT64_MAX; - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; } bool IsUInt16(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT16_MAX; - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT16_MAX; } bool IsUInt32(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT32_MAX; - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT32_MAX; } bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT64_MAX; - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT64_MAX; } bool IsArray(const nlohmann::json &jsonObj, const std::string &key) { - bool res = jsonObj.contains(key) && jsonObj[key].is_array(); - if (!res) { - DHLOGE("The key %s in jsonObj is invalid.", key.c_str()); - } - return res; + return jsonObj.contains(key) && jsonObj[key].is_array(); } std::string GetNodeDesc(std::string parameters) @@ -380,6 +348,7 @@ void ScanInputDevicesPath(const std::string &dirName, std::vector & continue; } std::string tmpDevName = dirName + "/" + std::string(de->d_name); + DHLOGI("Find input node path: %s", tmpDevName.c_str()); vecInputDevPath.push_back(tmpDevName); } closedir(dir); -- Gitee