InputDispatcher: Properly store values inside optional
Before this CL, we were storing values inside the optional incorrectly.
The variable was first dereferenced (which is always valid, even if
there's no value contained inside), and then the value was stored.
However, the optional bool flag itself was not updated. As a result, the
assertion ALOG_ASSERT was failing. This was not observed in our runs
likely due to the behaviour of ALOG_ASSERT.
The failure could be reproduced when this was switched to LOG_IF(FATAL
locally. The test `PolicyNotifiedForUnhandledKey` was hitting that
assertion and failing.
The incorrect behaviour was introduced in ag/22679128: Use std::map
for fallback keys.
In this CL, the code is changed to properly update the optional and to
crash always when the unexpected condition occurs.
Bug: 377853843
Flag: EXEMPT bugfix
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I1f74ff11ac62fcf577ecd146067858d43adc0288
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 755995c..cd4ed5c 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -6805,14 +6805,15 @@
// The fallback keycode cannot change at any other point in the lifecycle.
if (initialDown) {
if (fallback) {
- *fallbackKeyCode = event.getKeyCode();
+ fallbackKeyCode = event.getKeyCode();
} else {
- *fallbackKeyCode = AKEYCODE_UNKNOWN;
+ fallbackKeyCode = AKEYCODE_UNKNOWN;
}
connection->inputState.setFallbackKey(originalKeyCode, *fallbackKeyCode);
}
- ALOG_ASSERT(fallbackKeyCode);
+ LOG_IF(FATAL, !fallbackKeyCode)
+ << "fallbackKeyCode is not initialized. initialDown = " << initialDown;
// Cancel the fallback key if the policy decides not to send it anymore.
// We will continue to dispatch the key to the policy but we will no