Merge "Service Gesture Detection: copy motion events when sending to the service." into tm-dev

This commit is contained in:
Ameer Armaly
2022-03-28 20:21:46 +00:00
committed by Android (Google) Code Review

View File

@@ -1301,25 +1301,24 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
/** Send a motion event to the service to allow it to perform gesture detection. */ /** Send a motion event to the service to allow it to perform gesture detection. */
public boolean sendMotionEventToListeningServices(MotionEvent event) { public boolean sendMotionEventToListeningServices(MotionEvent event) {
synchronized (mLock) { boolean result;
event = MotionEvent.obtain(event);
if (DEBUG) { if (DEBUG) {
Slog.d(LOG_TAG, "Sending event to service: " + event); Slog.d(LOG_TAG, "Sending event to service: " + event);
} }
return notifyMotionEvent(event); result = scheduleNotifyMotionEvent(event);
} return result;
} }
/** /**
* Notifies services that the touch state on a given display has changed. * Notifies services that the touch state on a given display has changed.
*/ */
public boolean onTouchStateChanged(int displayId, int state) { public boolean onTouchStateChanged(int displayId, int state) {
synchronized (mLock) {
if (DEBUG) { if (DEBUG) {
Slog.d(LOG_TAG, "Notifying touch state:" Slog.d(LOG_TAG, "Notifying touch state:"
+ TouchInteractionController.stateToString(state)); + TouchInteractionController.stateToString(state));
} }
return notifyTouchState(displayId, state); return scheduleNotifyTouchState(displayId, state);
}
} }
/** /**
@@ -1650,7 +1649,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
return false; return false;
} }
private boolean notifyMotionEvent(MotionEvent event) { private boolean scheduleNotifyMotionEvent(MotionEvent event) {
synchronized (mLock) {
AccessibilityUserState state = getCurrentUserStateLocked(); AccessibilityUserState state = getCurrentUserStateLocked();
for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { for (int i = state.mBoundServices.size() - 1; i >= 0; i--) {
AccessibilityServiceConnection service = state.mBoundServices.get(i); AccessibilityServiceConnection service = state.mBoundServices.get(i);
@@ -1659,10 +1659,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
return true; return true;
} }
} }
}
return false; return false;
} }
private boolean notifyTouchState(int displayId, int touchState) { private boolean scheduleNotifyTouchState(int displayId, int touchState) {
synchronized (mLock) {
AccessibilityUserState state = getCurrentUserStateLocked(); AccessibilityUserState state = getCurrentUserStateLocked();
for (int i = state.mBoundServices.size() - 1; i >= 0; i--) { for (int i = state.mBoundServices.size() - 1; i >= 0; i--) {
AccessibilityServiceConnection service = state.mBoundServices.get(i); AccessibilityServiceConnection service = state.mBoundServices.get(i);
@@ -1671,6 +1673,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
return true; return true;
} }
} }
}
return false; return false;
} }