SyncPointerCapture (5/n): Move Pointer Capture to InputDispatcher

This CL re-implements Pointer Capture in InputDispatcher, moving it away
for WindowManagerService.

The pipeline for Pointer Capture is changed so that requests to enable
and disable Pointer Capture from an app are redirected directly to
InputDispatcher by InputManagerService.

The new expected pipeline for Pointer Capture is as follows:
- App requests Pointer Capture through InputManagerService with its
window token.
- InputManagerService gets the InputWindowToken for the WindowToken, and
relays the Pointer Capture request to InputDispatcher.
- Pointer Capture is enabled in InputFlinger:
  1. InputDispatcher receives the Pointer Capture request, and ignores
  requests from windows that are not focused.
    InputDispatcherInterface::requestPointerCapture(windowToken,
        enabled)
  2. InputDispatcher sets the Pointer Capture state through its policy,
  which sends a configuration change to InputReader.
    InputDispatcherPolicyInterface::setPointerCapture(enabled)
  3. InputReader changes its configuration to enable/disable Pointer
  Capture, and sends notifyPointerCaptureChanged to InputDispatcher.
    InputListener::notifyPointerCaptureChanged(args)
  4. The Pointer Capture change notification is sent to the input
  channel.
- App receives a Pointer Capture change event through its InputChannel.

The window that has Pointer Capture is tracked in InputDispatcher. If
the window loses focus, Pointer Capture is disabled immediately, and
InputDispatcher synthesizes a Pointer Capture change event to dispatch
to the app before it sends the event signalling the focus loss.

Bug: 141749603
Test: atest inputflinger_tests
Test: atest PointerCaptureTest (CTS)
Test: manual: Pointer Capture works

Change-Id: Ie27f6e279af9b0d844160fb146476e1812fb02b3
diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h
index 0661709..fba5514 100644
--- a/services/inputflinger/dispatcher/Entry.h
+++ b/services/inputflinger/dispatcher/Entry.h
@@ -36,6 +36,7 @@
         FOCUS,
         KEY,
         MOTION,
+        POINTER_CAPTURE_CHANGED,
     };
 
     static const char* typeToString(Type type) {
@@ -50,6 +51,8 @@
                 return "KEY";
             case Type::MOTION:
                 return "MOTION";
+            case Type::POINTER_CAPTURE_CHANGED:
+                return "POINTER_CAPTURE_CHANGED";
         }
     }
 
@@ -115,6 +118,15 @@
     virtual ~FocusEntry();
 };
 
+struct PointerCaptureChangedEntry : EventEntry {
+    bool pointerCaptureEnabled;
+
+    PointerCaptureChangedEntry(int32_t id, nsecs_t eventTime, bool hasPointerCapture);
+    std::string getDescription() const override;
+
+    virtual ~PointerCaptureChangedEntry();
+};
+
 struct KeyEntry : EventEntry {
     int32_t deviceId;
     uint32_t source;
@@ -254,6 +266,7 @@
     sp<IBinder> oldToken;
     sp<IBinder> newToken;
     std::string obscuringPackage;
+    bool enabled;
 };
 
 } // namespace android::inputdispatcher