Reland: Change input injection security model
This reverts commit 861faa0811967a732a127568d9a306cb1565bdd8.
Changes from revert:
- Don't inject events from the shell uid in CTS tests
Bug: 207667844
Bug: 194952792
Test: atest WindowFocusTests WindowInsetsControllerTests
Test: TBD
Change-Id: I84fa3b8cf630422ead0f4e5944f85c8e461c7f29
Merged-In: I84fa3b8cf630422ead0f4e5944f85c8e461c7f29
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
index 024ea17..283a1f0 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
@@ -61,8 +61,6 @@
import androidx.annotation.NonNull;
-import com.android.compatibility.common.util.SystemUtil;
-
import org.junit.Test;
import java.util.ArrayList;
@@ -81,9 +79,7 @@
private static void sendKey(int action, int keyCode, int displayId) {
final KeyEvent keyEvent = new KeyEvent(action, keyCode);
keyEvent.setDisplayId(displayId);
- SystemUtil.runWithShellPermissionIdentity(() -> {
- getInstrumentation().sendKeySync(keyEvent);
- });
+ getInstrumentation().sendKeySync(keyEvent);
}
private static void sendAndAssertTargetConsumedKey(InputTargetActivity target, int keyCode,
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowInputTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowInputTests.java
index 322355f..2e29a74 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowInputTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowInputTests.java
@@ -73,12 +73,11 @@
import java.util.ArrayList;
import java.util.Random;
import java.util.Set;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeoutException;
/**
* Ensure moving windows and tapping is done synchronously.
@@ -728,9 +727,10 @@
eventHover.setSource(InputDevice.SOURCE_MOUSE);
try {
mInstrumentation.sendPointerSync(eventHover);
- fail("Not allowed to inject event to the window from another process.");
- } catch (SecurityException e) {
- // Should not be allowed to inject event to the window from another process.
+ fail("Not allowed to inject to windows owned by another uid from Instrumentation.");
+ } catch (RuntimeException e) {
+ // Should not be allowed to inject event to a window owned by another uid from the
+ // Instrumentation class.
}
}
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsControllerTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsControllerTests.java
index aa19b08..65465b2 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsControllerTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsControllerTests.java
@@ -62,6 +62,7 @@
import android.os.Bundle;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
+import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -77,7 +78,6 @@
import androidx.annotation.Nullable;
import com.android.compatibility.common.util.PollingCheck;
-import com.android.compatibility.common.util.SystemUtil;
import com.android.cts.mockime.ImeEventStream;
import com.android.cts.mockime.ImeSettings;
import com.android.cts.mockime.MockImeSession;
@@ -844,8 +844,10 @@
}
private void sendPointerSync(MotionEvent event) {
- SystemUtil.runWithShellPermissionIdentity(
- () -> getInstrumentation().sendPointerSync(event));
+ event.setSource(event.getSource() | InputDevice.SOURCE_CLASS_POINTER);
+ // Use UiAutomation to inject into TestActivity because it is started and owned by the
+ // Shell, which has a different uid than this instrumentation.
+ getInstrumentation().getUiAutomation().injectInputEvent(event, true);
}
private static class AnimationCallback extends WindowInsetsAnimation.Callback {