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
(cherry picked from commit 9f330c542b48dc6edba9aeaff3b3f4bf305713f3)
diff --git a/services/inputflinger/InputManager.h b/services/inputflinger/InputManager.h
index 35d2b0f..8aad35b 100644
--- a/services/inputflinger/InputManager.h
+++ b/services/inputflinger/InputManager.h
@@ -90,6 +90,9 @@
/* Gets the input dispatcher. */
virtual InputDispatcherInterface& getDispatcher() = 0;
+
+ /* Check that the input stages have not deadlocked. */
+ virtual void monitor() = 0;
};
class InputManager : public InputManagerInterface, public BnInputFlinger {
@@ -108,6 +111,7 @@
UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() override;
InputClassifierInterface& getClassifier() override;
InputDispatcherInterface& getDispatcher() override;
+ void monitor() override;
status_t dump(int fd, const Vector<String16>& args) override;
binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
@@ -117,7 +121,7 @@
private:
std::unique_ptr<InputReaderInterface> mReader;
- std::unique_ptr<UnwantedInteractionBlockerInterface> mUnwantedInteractionBlocker;
+ std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker;
std::unique_ptr<InputClassifierInterface> mClassifier;