summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Antonio Kantek <kanant@google.com> 2025-01-16 19:25:54 +0000
committer Antonio Kantek <kanant@google.com> 2025-01-23 19:13:14 +0000
commit1e9ade9a075e07e5203dcfe51ab0a3e1753025ac (patch)
tree2ae7cf56dc7796a5a1982efa3af001be69536219
parentbfa852e02a52465145cb55148aa8d18adacd8f5d (diff)
Deprecate UiAutomation#injectInputEvent for CTS tests
For input event injection, CTS tests should rely on uinput (com.android.cts.input.UinputDevice), hid devices (com.android.cts.input.HidDevice), or InjectInputInProcess * (com.android.cts.input.InjectInputInProcess) for in-process injection. Bug: 277261245 Test: m Flag: com.android.input.flags.deprecate_uiautomation_input_injection Change-Id: I83c82c16c4b43236c2bcd562c3d2178488dcdd48
-rw-r--r--core/api/test-current.txt4
-rw-r--r--core/java/android/app/UiAutomation.java44
2 files changed, 37 insertions, 11 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index f06bd48a8cd8..6e11cbc0c34b 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -478,8 +478,8 @@ package android.app {
method public void destroy();
method @NonNull public java.util.Set<java.lang.String> getAdoptedShellPermissions();
method @Deprecated public boolean grantRuntimePermission(String, String, android.os.UserHandle);
- method public boolean injectInputEvent(@NonNull android.view.InputEvent, boolean, boolean);
- method public void injectInputEventToInputFilter(@NonNull android.view.InputEvent);
+ method @Deprecated @FlaggedApi("com.android.input.flags.deprecate_uiautomation_input_injection") public boolean injectInputEvent(@NonNull android.view.InputEvent, boolean, boolean);
+ method @Deprecated @FlaggedApi("com.android.input.flags.deprecate_uiautomation_input_injection") public void injectInputEventToInputFilter(@NonNull android.view.InputEvent);
method public boolean isNodeInCache(@NonNull android.view.accessibility.AccessibilityNodeInfo);
method public void removeOverridePermissionState(int, @NonNull String);
method @Deprecated public boolean revokeRuntimePermission(String, String, android.os.UserHandle);
diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java
index 6f8e335cff80..c89cb553762b 100644
--- a/core/java/android/app/UiAutomation.java
+++ b/core/java/android/app/UiAutomation.java
@@ -18,6 +18,8 @@ package android.app;
import static android.view.Display.DEFAULT_DISPLAY;
+import static com.android.input.flags.Flags.FLAG_DEPRECATE_UIAUTOMATION_INPUT_INJECTION;
+
import android.accessibilityservice.AccessibilityGestureEvent;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityService.Callbacks;
@@ -26,6 +28,7 @@ import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.IAccessibilityServiceClient;
import android.accessibilityservice.IAccessibilityServiceConnection;
import android.accessibilityservice.MagnificationConfig;
+import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -108,7 +111,10 @@ import java.util.concurrent.TimeoutException;
* client should be using a higher-level library or implement high-level functions.
* For example, performing a tap on the screen requires construction and injecting
* of a touch down and up events which have to be delivered to the system by a
- * call to {@link #injectInputEvent(InputEvent, boolean)}.
+ * call to {@link #injectInputEvent(InputEvent, boolean)}. <strong>Note:</strong> For CTS tests, it
+ * is preferable to inject input events using uinput (com.android.cts.input.UinputDevice) or hid
+ * devices (com.android.cts.input.HidDevice). Alternatively, use InjectInputInProcess
+ * (com.android.cts.input.InjectInputInProcess) for in-process injection.
* </p>
* <p>
* The APIs exposed by this class operate across applications enabling a client
@@ -956,9 +962,17 @@ public final class UiAutomation {
* <strong>Note:</strong> It is caller's responsibility to recycle the event.
* </p>
*
- * @param event The event to inject.
- * @param sync Whether to inject the event synchronously.
- * @return Whether event injection succeeded.
+ * <p>
+ * <strong>Note:</strong> Avoid this method when injecting input events in CTS tests. Instead
+ * use uinput (com.android.cts.input.UinputDevice)
+ * or hid devices (com.android.cts.input.HidDevice), as they provide a more accurate simulation
+ * of real device behavior. Alternatively, InjectInputInProcess
+ * (com.android.cts.input.InjectInputProcess) can be used for in-process injection.
+ * </p>
+ *
+ * @param event the event to inject
+ * @param sync whether to inject the event synchronously
+ * @return {@code true} if event injection succeeded
*/
public boolean injectInputEvent(InputEvent event, boolean sync) {
return injectInputEvent(event, sync, true /* waitForAnimations */);
@@ -971,15 +985,21 @@ public final class UiAutomation {
* <strong>Note:</strong> It is caller's responsibility to recycle the event.
* </p>
*
- * @param event The event to inject.
- * @param sync Whether to inject the event synchronously.
- * @param waitForAnimations Whether to wait for all window container animations and surface
- * operations to complete.
- * @return Whether event injection succeeded.
+ * @param event the event to inject
+ * @param sync whether to inject the event synchronously.
+ * @param waitForAnimations whether to wait for all window container animations and surface
+ * operations to complete
+ * @return {@code true} if event injection succeeded
*
+ * @deprecated for CTS tests prefer inject input events using uinput
+ * (com.android.cts.input.UinputDevice) or hid devices (com.android.cts.input.HidDevice).
+ * Alternatively, InjectInputInProcess (com.android.cts.input.InjectInputProcess) can be used
+ * for in-process injection.
* @hide
*/
@TestApi
+ @Deprecated // Deprecated for CTS tests
+ @FlaggedApi(FLAG_DEPRECATE_UIAUTOMATION_INPUT_INJECTION)
public boolean injectInputEvent(@NonNull InputEvent event, boolean sync,
boolean waitForAnimations) {
try {
@@ -1002,9 +1022,15 @@ public final class UiAutomation {
* Events injected to the input subsystem using the standard {@link #injectInputEvent} method
* skip the accessibility input filter to avoid feedback loops.
*
+ * @deprecated for CTS tests prefer inject input events using uinput
+ * (com.android.cts.input.UinputDevice) or hid devices (com.android.cts.input.HidDevice).
+ * Alternatively, InjectInputInProcess (com.android.cts.input.InjectInputProcess) can be used
+ * for in-process injection.
* @hide
*/
@TestApi
+ @Deprecated
+ @FlaggedApi(FLAG_DEPRECATE_UIAUTOMATION_INPUT_INJECTION)
public void injectInputEventToInputFilter(@NonNull InputEvent event) {
try {
mUiAutomationConnection.injectInputEventToInputFilter(event);