summaryrefslogtreecommitdiff
path: root/libs/input/PrintTools.cpp
diff options
context:
space:
mode:
author Siarhei Vishniakou <svv@google.com> 2022-05-17 05:03:42 -0700
committer Siarhei Vishniakou <svv@google.com> 2022-05-19 02:55:32 -0700
commit9f330c542b48dc6edba9aeaff3b3f4bf305713f3 (patch)
tree2db076dc9a4df968ff52f6b4172bd6a4a95589ce /libs/input/PrintTools.cpp
parent639db6527174037f5a95385caf9cdd5cbadc56e0 (diff)
Add lock to protect UnwantedInteractionBlocker
The call to 'dump' may come from any thread, and therefore could cause a crash. Add a lock to protect this input stage. To run the test: adb shell -t "/data/nativetest64/inputflinger_tests/inputflinger_tests --gtest_filter='*Dump*' --gtest_repeat=100000 --gtest_break_on_failure" Before this patch, the test failed after ~5K - ~13K iterations (took 10-20 seconds to crash). Bug: 232645962 Test: m inputflinger_tests && adb sync data && <run the test> Change-Id: I2a199690450bc5bb4a8576aa59075e99d37a531b
Diffstat (limited to 'libs/input/PrintTools.cpp')
-rw-r--r--libs/input/PrintTools.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/input/PrintTools.cpp b/libs/input/PrintTools.cpp
index 5d6ae4ed91..01f6bf514b 100644
--- a/libs/input/PrintTools.cpp
+++ b/libs/input/PrintTools.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "PrintTools"
#include <input/PrintTools.h>
+#include <sstream>
namespace android {
@@ -24,4 +25,20 @@ const char* toString(bool value) {
return value ? "true" : "false";
}
+std::string addLinePrefix(std::string str, const std::string& prefix) {
+ std::stringstream ss;
+ bool newLineStarted = true;
+ for (const auto& ch : str) {
+ if (newLineStarted) {
+ ss << prefix;
+ newLineStarted = false;
+ }
+ if (ch == '\n') {
+ newLineStarted = true;
+ }
+ ss << ch;
+ }
+ return ss.str();
+}
+
} // namespace android