From 2a7ab6e8571411056fe0bd86a5742901939f81ef Mon Sep 17 00:00:00 2001 From: Ameer Armaly Date: Tue, 22 Mar 2022 10:59:10 -0700 Subject: [PATCH] Service Gesture Detection: copy motion events when sending to the service. Sending without copying causes some motion events to get duplicated in the service's motion event stream. Fix: 223674686 Bug: 223673301 Test: Manual. Perform three-finger swipes and insure they work as expected. Change-Id: Ie94ef06605902f2b3be5fb426511d5c80cf1ac09 --- .../AccessibilityManagerService.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 22c77e92842a2..53a3e091a7852 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -1301,25 +1301,24 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub /** Send a motion event to the service to allow it to perform gesture detection. */ public boolean sendMotionEventToListeningServices(MotionEvent event) { - synchronized (mLock) { - if (DEBUG) { - Slog.d(LOG_TAG, "Sending event to service: " + event); - } - return notifyMotionEvent(event); + boolean result; + event = MotionEvent.obtain(event); + if (DEBUG) { + Slog.d(LOG_TAG, "Sending event to service: " + event); } + result = scheduleNotifyMotionEvent(event); + return result; } /** * Notifies services that the touch state on a given display has changed. */ public boolean onTouchStateChanged(int displayId, int state) { - synchronized (mLock) { if (DEBUG) { Slog.d(LOG_TAG, "Notifying touch state:" + TouchInteractionController.stateToString(state)); } - return notifyTouchState(displayId, state); - } + return scheduleNotifyTouchState(displayId, state); } /** @@ -1650,25 +1649,29 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub return false; } - private boolean notifyMotionEvent(MotionEvent event) { - AccessibilityUserState state = getCurrentUserStateLocked(); - for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { - AccessibilityServiceConnection service = state.mBoundServices.get(i); - if (service.mRequestTouchExplorationMode) { - service.notifyMotionEvent(event); - return true; + private boolean scheduleNotifyMotionEvent(MotionEvent event) { + synchronized (mLock) { + AccessibilityUserState state = getCurrentUserStateLocked(); + for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { + AccessibilityServiceConnection service = state.mBoundServices.get(i); + if (service.mRequestTouchExplorationMode) { + service.notifyMotionEvent(event); + return true; + } } } return false; } - private boolean notifyTouchState(int displayId, int touchState) { - AccessibilityUserState state = getCurrentUserStateLocked(); - for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { - AccessibilityServiceConnection service = state.mBoundServices.get(i); - if (service.mRequestTouchExplorationMode) { - service.notifyTouchState(displayId, touchState); - return true; + private boolean scheduleNotifyTouchState(int displayId, int touchState) { + synchronized (mLock) { + AccessibilityUserState state = getCurrentUserStateLocked(); + for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { + AccessibilityServiceConnection service = state.mBoundServices.get(i); + if (service.mRequestTouchExplorationMode) { + service.notifyTouchState(displayId, touchState); + return true; + } } } return false;