diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index f6190e4998a4eeb6dea7f71b504ac7251172595c..a7750cd7d8d9f8ef893826dc02504270fd15406c 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -41,6 +41,7 @@ namespace DistributedHardware { namespace DistributedInput { namespace { const uint32_t SLEEP_TIME_US = 100 * 1000; +const int32_t PER_FIFTY_TIME = 50; const std::string MOUSE_NODE_KEY = "mouse"; } @@ -539,6 +540,10 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) } std::lock_guard my_lock(operationMutex_); + logCount_++; + if (logCount_ >= INT32_MAX - 1) { + logCount_ = 1; + } DHLOGD("Opening device start: %{public}s", devicePath.c_str()); int fd = OpenInputDeviceFdByPath(devicePath); if (fd == UN_INIT_FD_VALUE) { @@ -559,7 +564,9 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) if (MakeDevice(fd, std::move(device)) < 0) { CloseFd(fd); - DHLOGI("Opening device error: %{public}s", devicePath.c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("Opening device error: %{public}s", devicePath.c_str()); + } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } @@ -635,11 +642,15 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) void InputHub::QueryEventInfo(int fd, std::unique_ptr &device) { - DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(), - GetAnonyString(device->identifier.descriptor).c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(), + GetAnonyString(device->identifier.descriptor).c_str()); + } struct libevdev *dev = GetLibEvDev(fd); if (dev == nullptr) { - DHLOGE("dev is nullptr"); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGE("dev is nullptr"); + } return; } GetEventTypes(dev, device->identifier); @@ -722,7 +733,9 @@ struct libevdev* InputHub::GetLibEvDev(int fd) int rc = 1; rc = libevdev_new_from_fd(fd, &dev); if (rc < 0) { - DHLOGE("Failed to init libevdev (%{public}s)", strerror(-rc)); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGE("Failed to init libevdev (%{public}s)", strerror(-rc)); + } return nullptr; } return dev; @@ -742,7 +755,9 @@ void InputHub::GetEventTypes(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_KEY)) { - DHLOGE("The device doesn't has EV_KEY type!"); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGE("The device doesn't has EV_KEY type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } for (uint32_t eventKey = 0; eventKey < KEY_CNT; eventKey++) { @@ -758,7 +773,9 @@ int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_ABS)) { - DHLOGE("The device doesn't has EV_ABS type!"); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGE("The device doesn't has EV_ABS type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } DHLOGI("The device has abs info, devName: %{public}s, dhId: %{public}s!", @@ -787,7 +804,9 @@ int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetRELTypes(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_REL)) { - DHLOGE("The device doesn't has EV_REL type!"); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGE("The device doesn't has EV_REL type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } for (uint32_t code = 0; code < REL_CNT; code++) { @@ -844,7 +863,9 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { - DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str()); + } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } @@ -953,8 +974,10 @@ void InputHub::GenerateDescriptor(InputDevice &identifier) const } identifier.descriptor = DH_ID_PREFIX + Sha256(rawDescriptor); - DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), - GetAnonyString(identifier.descriptor).c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), + GetAnonyString(identifier.descriptor).c_str()); + } } int32_t InputHub::RegisterDeviceForEpollLocked(const Device &device) @@ -1322,16 +1345,18 @@ bool InputHub::IsAllDevicesStoped() void InputHub::RecordDeviceLog(const std::string &devicePath, const InputDevice &identifier) { - DHLOGI("add device: %{public}s\n", devicePath.c_str()); - DHLOGI(" bus: %{public}04x\n" - " vendor %{public}04x\n" - " product %{public}04x\n" - " version %{public}04x\n", - identifier.bus, identifier.vendor, identifier.product, identifier.version); - DHLOGI(" name: \"%{public}s\"\n", identifier.name.c_str()); - DHLOGI(" physicalPath: \"%{public}s\"\n", identifier.physicalPath.c_str()); - DHLOGI(" unique id: \"%{public}s\"\n", identifier.uniqueId.c_str()); - DHLOGI(" descriptor: \"%{public}s\"\n", GetAnonyString(identifier.descriptor).c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("add device: %{public}s\n", devicePath.c_str()); + DHLOGI(" bus: %{public}04x\n" + " vendor %{public}04x\n" + " product %{public}04x\n" + " version %{public}04x\n", + identifier.bus, identifier.vendor, identifier.product, identifier.version); + DHLOGI(" name: \"%{public}s\"\n", identifier.name.c_str()); + DHLOGI(" physicalPath: \"%{public}s\"\n", identifier.physicalPath.c_str()); + DHLOGI(" unique id: \"%{public}s\"\n", identifier.uniqueId.c_str()); + DHLOGI(" descriptor: \"%{public}s\"\n", GetAnonyString(identifier.descriptor).c_str()); + } } void InputHub::RecordChangeEventLog(const RawEvent &event) @@ -1599,7 +1624,9 @@ InputHub::Device::Device(int fd, const std::string &path) : next(nullptr), fd(fd), path(path), identifier({}), classes(0), enabled(false), isShare(false), isVirtual(fd < 0) { // Figure out the kinds of events the device reports. - DHLOGI("Ctor Device for get event mask, fd: %{public}d, path: %{public}s", fd, path.c_str()); + if (logCount_ % PER_FIFTY_TIME == 0) { + DHLOGI("Ctor Device for get event mask, fd: %{public}d, path: %{public}s", fd, path.c_str()); + } ioctl(fd, EVIOCGBIT(0, sizeof(evBitmask)), evBitmask); ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keyBitmask)), keyBitmask); ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absBitmask)), absBitmask); diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 6e7f67de3ee8e12c63723aae4585371c24052006..51b3e39c667c9fce299b49e943001b48f463ca25 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -33,6 +33,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +static std::atomic logCount_ = {1}; struct AffectDhIds { std::vector sharingDhIds; std::vector noSharingDhIds;