Fix screenshot shortcut when accessibility is enabled.

Previously, pressing the power button would cause the input state to reset in order to pass on the key events relating to the power button.
When pressing the power button in combination with the volume down button, to take a screen shot, this would mean that the system would receive the ACTION_UP for the volume button before the ACTION_DOWN.
In this change we pass on the power buttons but do not reset state, allowing us to process other events normally.

Flag: com.android.server.accessibility.do_not_reset_key_event_state
Fix:331900630
Test: Enable the DEBUG variable in AccessibilityInputFilter.java. Press volume down and power to take a screenshot. Inspect the logs to observe the event stream.
Test: Press volume up and down with one finger on the screen. Observe the volume adjustment works normally.
Test: Press power and volume up to activate the power menu.
Change-Id: Ie986bcb25f738b0163c92ddb22897f781890f5c1
diff --git a/services/accessibility/accessibility.aconfig b/services/accessibility/accessibility.aconfig
index 0448f6d..e66fe1b 100644
--- a/services/accessibility/accessibility.aconfig
+++ b/services/accessibility/accessibility.aconfig
@@ -49,6 +49,16 @@
 }
 
 flag {
+    name: "do_not_reset_key_event_state"
+    namespace: "accessibility"
+    description: "Don't reset the event stream state when receiving an event without policy flag FLAG_PASS_TO_USER. Just pass it through the pipeline."
+    bug: "331900630"
+    metadata {
+        purpose: PURPOSE_BUGFIX
+    }
+}
+
+flag {
     name: "enable_a11y_checker_logging"
     namespace: "accessibility"
     description: "Whether to identify and log app a11y issues."
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java
index 54e545d..5fb60e7 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java
@@ -347,8 +347,13 @@
         final int eventSource = event.getSource();
         final int displayId = event.getDisplayId();
         if ((policyFlags & WindowManagerPolicy.FLAG_PASS_TO_USER) == 0) {
-            state.reset();
-            clearEventStreamHandler(displayId, eventSource);
+            if (!Flags.doNotResetKeyEventState()) {
+                state.reset();
+                clearEventStreamHandler(displayId, eventSource);
+            }
+            if (DEBUG) {
+                Slog.d(TAG, "Not processing event " + event);
+            }
             super.onInputEvent(event, policyFlags);
             return;
         }
@@ -503,9 +508,15 @@
 
     private void processKeyEvent(EventStreamState state, KeyEvent event, int policyFlags) {
         if (!state.shouldProcessKeyEvent(event)) {
+            if (DEBUG) {
+                Slog.d(TAG, "processKeyEvent: not processing: " + event);
+            }
             super.onInputEvent(event, policyFlags);
             return;
         }
+        if (DEBUG) {
+            Slog.d(TAG, "processKeyEvent: " + event);
+        }
         // Since the display id of KeyEvent always would be -1 and there is only one
         // KeyboardInterceptor for all display, pass KeyEvent to the mEventHandler of
         // DEFAULT_DISPLAY to handle.