Prevent display brightness flicker on power button
ag/22712141 tried to fix an issue where using system keys would
not trigger user activity, allowing the device to go into sleep
mode even while interacting with things like volume controls. The
cause of this is that system shortcuts were never sent to keyguard,
which is responsible for manging the power state. Unfortunately,
the fix caused the side effect of considering the power button user
activity, which would brighten the display if in dim mode before
bringing the display to sleep. This was quite subtle as we only
learned of this problem recently.
This CL refines the logic introduced in ag/22712141, correcting the
specific issue while restoring the original user activity logic.
Bug: 312671872
Test: Flashed on device, tested on keyguard and several apps
Flag: EXEMPT bugfix
Change-Id: I57f98ec1b138d4e71cd8c21742eacd8a2813e9d3
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 9b97629..ffdb1c4 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -1894,8 +1894,6 @@
doInterceptKeyBeforeDispatchingCommand(focusedWindowToken, *entry);
};
postCommandLocked(std::move(command));
- // Poke user activity for keys not passed to user
- pokeUserActivityLocked(*entry);
return false; // wait for the command to run
} else {
entry->interceptKeyResult = KeyEntry::InterceptKeyResult::CONTINUE;
@@ -1912,8 +1910,12 @@
*dropReason == DropReason::POLICY ? InputEventInjectionResult::SUCCEEDED
: InputEventInjectionResult::FAILED);
mReporter->reportDroppedKey(entry->id);
- // Poke user activity for undispatched keys
- pokeUserActivityLocked(*entry);
+ // Poke user activity for consumed keys, as it may have not been reported due to
+ // the focused window requesting user activity to be disabled
+ if (*dropReason == DropReason::POLICY &&
+ mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {
+ pokeUserActivityLocked(*entry);
+ }
return true;
}
@@ -3313,22 +3315,16 @@
if (keyEntry.flags & AKEY_EVENT_FLAG_CANCELED) {
return;
}
- // If the key code is unknown, we don't consider it user activity
- if (keyEntry.keyCode == AKEYCODE_UNKNOWN) {
- return;
- }
// Don't inhibit events that were intercepted or are not passed to
// the apps, like system shortcuts
if (windowDisablingUserActivityInfo != nullptr &&
- keyEntry.interceptKeyResult != KeyEntry::InterceptKeyResult::SKIP &&
- keyEntry.policyFlags & POLICY_FLAG_PASS_TO_USER) {
+ keyEntry.interceptKeyResult != KeyEntry::InterceptKeyResult::SKIP) {
if (DEBUG_DISPATCH_CYCLE) {
ALOGD("Not poking user activity: disabled by window '%s'.",
windowDisablingUserActivityInfo->name.c_str());
}
return;
}
-
break;
}
default: {