Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc13292c authored by Ameer Armaly's avatar Ameer Armaly
Browse files

Add passthrough functionality for touch exploration and gesture detection.

Bug: 136131815:
Test: atest GestureManifoldTest AccessibilityGestureDetectorTest TouchExplorerTest
Change-Id: I8c6b7a333dcb9a4949387a7a683e2dc229d2b18f
parent b1fa029b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2871,7 +2871,9 @@ package android.accessibilityservice {
    method protected void onServiceConnected();
    method public void onSystemActionsChanged();
    method public final boolean performGlobalAction(int);
    method public void setGestureDetectionPassthroughRegion(int, @NonNull android.graphics.Region);
    method public final void setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo);
    method public void setTouchExplorationPassthroughRegion(int, @NonNull android.graphics.Region);
    method public boolean takeScreenshot(int, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.accessibilityservice.AccessibilityService.ScreenshotResult>);
    field public static final int GESTURE_2_FINGER_DOUBLE_TAP = 20; // 0x14
    field public static final int GESTURE_2_FINGER_DOUBLE_TAP_AND_HOLD = 40; // 0x28
+51 −0
Original line number Diff line number Diff line
@@ -2414,4 +2414,55 @@ public abstract class AccessibilityService extends Service {
            return mTimestamp;
        };
    }

    /**
     * When {@link AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is enabled, this
     * function requests that touch interactions starting in the specified region of the screen
     * bypass the gesture detector. There can only be one gesture detection passthrough region per
     * display. Requesting a new gesture detection passthrough region clears the existing one. To
     * disable this passthrough and return to the original behavior, pass in an empty region. When
     * {@link AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is disabled this
     * function has no effect.
     *
     * @param displayId The display on which to set this region.
     * @param region the region of the screen.
     */
    public void setGestureDetectionPassthroughRegion(int displayId, @NonNull Region region) {
        Preconditions.checkNotNull(region, "region cannot be null");
        final IAccessibilityServiceConnection connection =
                AccessibilityInteractionClient.getInstance().getConnection(mConnectionId);
        if (connection != null) {
            try {
                connection.setGestureDetectionPassthroughRegion(displayId, region);
            } catch (RemoteException re) {
                throw new RuntimeException(re);
            }
        }
    }

    /**
     * When {@link AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is enabled, this
     * function requests that touch interactions starting in the specified region of the screen
     * bypass the touch explorer and go straight to the view hierarchy. There can only be one touch
     * exploration passthrough region per display. Requesting a new touch explorationpassthrough
     * region clears the existing one. To disable this passthrough and return to the original
     * behavior, pass in an empty region. When {@link
     * AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is disabled this function has
     * no effect.
     *
     * @param displayId The display on which to set this region.
     * @param region the region of the screen .
     */
    public void setTouchExplorationPassthroughRegion(int displayId, @NonNull Region region) {
        Preconditions.checkNotNull(region, "region cannot be null");
        final IAccessibilityServiceConnection connection =
                AccessibilityInteractionClient.getInstance().getConnection(mConnectionId);
        if (connection != null) {
            try {
                connection.setTouchExplorationPassthroughRegion(displayId, region);
            } catch (RemoteException re) {
                throw new RuntimeException(re);
            }
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -111,4 +111,8 @@ interface IAccessibilityServiceConnection {
    int getWindowIdForLeashToken(IBinder token);

    void takeScreenshot(int displayId, in RemoteCallback callback);

    void setGestureDetectionPassthroughRegion(int displayId, in Region region);

    void setTouchExplorationPassthroughRegion(int displayId, in Region region);
}
+4 −0
Original line number Diff line number Diff line
@@ -157,4 +157,8 @@ public class AccessibilityServiceConnectionImpl extends IAccessibilityServiceCon
    }

    public void takeScreenshot(int displayId, RemoteCallback callback) {}

    public void setTouchExplorationPassthroughRegion(int displayId, Region region) {}

    public void setGestureDetectionPassthroughRegion(int displayId, Region region) {}
}
+14 −0
Original line number Diff line number Diff line
@@ -230,6 +230,10 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
        /* This is exactly PendingIntent.getActivity, separated out for testability */
        PendingIntent getPendingIntentActivity(Context context, int requestCode, Intent intent,
                int flags);

        void setGestureDetectionPassthroughRegion(int displayId, Region region);

        void setTouchExplorationPassthroughRegion(int displayId, Region region);
    }

    public AbstractAccessibilityServiceConnection(Context context, ComponentName componentName,
@@ -1736,4 +1740,14 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
    public boolean isMultiFingerGesturesEnabled() {
        return mRequestMultiFingerGestures;
    }

    @Override
    public void setGestureDetectionPassthroughRegion(int displayId, Region region) {
        mSystemSupport.setGestureDetectionPassthroughRegion(displayId, region);
    }

    @Override
    public void setTouchExplorationPassthroughRegion(int displayId, Region region) {
        mSystemSupport.setTouchExplorationPassthroughRegion(displayId, region);
    }
}
Loading