From f20b6ba6b0f791dfdebd26c48014a2733370498f Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Thu, 12 Sep 2024 18:11:44 +0000 Subject: InputDevice: modernize IDC probe debugging logs * Use the new-style stream syntax for readability * Upgrade DEBUGs to INFOs (since the new-style stream syntax filters DEBUG logs by default, and since these are hidden behind a compile-time constant it's fine to promote them) * Include the reason we didn't find a particular IDC file Bug: 365593937 Test: set DEBUG_PROBE to true, check logcat for the InputReader tag while connecting an input device Flag: EXEMPT code disabled by compile-time constant Change-Id: I7801252b688b4869911792aa66d2dcdceed8713b --- libs/input/InputDevice.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'libs/input/InputDevice.cpp') diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 9333ab83a6..962ce09b46 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,9 @@ using android::base::StringPrintf; namespace android { +// Set to true to log detailed debugging messages about IDC file probing. +static constexpr bool DEBUG_PROBE = false; + static const char* CONFIGURATION_FILE_DIR[] = { "idc/", "keylayout/", @@ -114,15 +118,14 @@ std::string getInputDeviceConfigurationFilePathByName( for (const auto& prefix : pathPrefixes) { path = prefix; appendInputDeviceConfigurationFileRelativePath(path, name, type); -#if DEBUG_PROBE - ALOGD("Probing for system provided input device configuration file: path='%s'", - path.c_str()); -#endif if (!access(path.c_str(), R_OK)) { -#if DEBUG_PROBE - ALOGD("Found"); -#endif + LOG_IF(INFO, DEBUG_PROBE) + << "Found system-provided input device configuration file at " << path; return path; + } else { + LOG_IF(ERROR, DEBUG_PROBE) + << "Didn't find system-provided input device configuration file at " << path + << ": " << strerror(errno); } } @@ -135,21 +138,18 @@ std::string getInputDeviceConfigurationFilePathByName( } path += "/system/devices/"; appendInputDeviceConfigurationFileRelativePath(path, name, type); -#if DEBUG_PROBE - ALOGD("Probing for system user input device configuration file: path='%s'", path.c_str()); -#endif if (!access(path.c_str(), R_OK)) { -#if DEBUG_PROBE - ALOGD("Found"); -#endif + LOG_IF(INFO, DEBUG_PROBE) << "Found system user input device configuration file at " + << path; return path; + } else { + LOG_IF(ERROR, DEBUG_PROBE) << "Didn't find system user input device configuration file at " + << path << ": " << strerror(errno); } // Not found. -#if DEBUG_PROBE - ALOGD("Probe failed to find input device configuration file: name='%s', type=%d", - name.c_str(), type); -#endif + LOG_IF(INFO, DEBUG_PROBE) << "Probe failed to find input device configuration file with name '" + << name << "' and type " << ftl::enum_string(type); return ""; } -- cgit v1.2.3-59-g8ed1b From b632185b24c0df53f20f4cf0923593e662c2ce42 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Thu, 12 Sep 2024 18:49:39 +0000 Subject: InputDevice: warn if a potential IDC file can't be opened When probing for IDC files, we expect to get "File not found" errors, but any other error could indicate a deeper problem (such as the permissions issue that appears to be behind b/365593937). In that case, it would be useful to have a warning log even if DEBUG_PROBE isn't set. Test: remove the read permissions for everyone on an IDC file, then watch logcat for the InputDevice tag while connecting the corresponding device Bug: 365593937 Flag: EXEMPT logging change Change-Id: I022ec383f0c0b22a66524341530c055a69e05f0b --- libs/input/InputDevice.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libs/input/InputDevice.cpp') diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 962ce09b46..c9030312f9 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -122,6 +122,10 @@ std::string getInputDeviceConfigurationFilePathByName( LOG_IF(INFO, DEBUG_PROBE) << "Found system-provided input device configuration file at " << path; return path; + } else if (errno != ENOENT) { + LOG(WARNING) << "Couldn't find a system-provided input device configuration file at " + << path << " due to error " << errno << " (" << strerror(errno) + << "); there may be an IDC file there that cannot be loaded."; } else { LOG_IF(ERROR, DEBUG_PROBE) << "Didn't find system-provided input device configuration file at " << path @@ -142,6 +146,10 @@ std::string getInputDeviceConfigurationFilePathByName( LOG_IF(INFO, DEBUG_PROBE) << "Found system user input device configuration file at " << path; return path; + } else if (errno != ENOENT) { + LOG(WARNING) << "Couldn't find a system user input device configuration file at " << path + << " due to error " << errno << " (" << strerror(errno) + << "); there may be an IDC file there that cannot be loaded."; } else { LOG_IF(ERROR, DEBUG_PROBE) << "Didn't find system user input device configuration file at " << path << ": " << strerror(errno); -- cgit v1.2.3-59-g8ed1b