summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chuwei He <chuweih@google.com> 2024-10-29 15:24:14 +0900
committer Chuwei He <chuweih@google.com> 2024-10-30 12:23:50 +0900
commit43fb7395288e8d4ba0a2830768ea8de752bdb01f (patch)
tree28ff1dac58188405f11a9e9c751c59c92a6f1cdd
parent204576daeef5dd4ec76c512203d8b129ea62a2f0 (diff)
Add support for argument array for executeShellCommand (1/2)
Currently, UiAutomation#executeShellCommand only takes String as command, and arguments with spaces cannot be correctly passed in. This change adds support for using argument array, which enables the use of arguments with spaces. This patch adds necessary support for the change in UiAutomationConnection. Test: atest CtsUiAutomationTestCases Bug: b/293132368 Change-Id: I4d6341f727e941b66e7b38ba5bc5018d25e136ef
-rwxr-xr-x[-rw-r--r--]core/java/android/app/IUiAutomationConnection.aidl2
-rwxr-xr-x[-rw-r--r--]core/java/android/app/UiAutomationConnection.java25
2 files changed, 27 insertions, 0 deletions
diff --git a/core/java/android/app/IUiAutomationConnection.aidl b/core/java/android/app/IUiAutomationConnection.aidl
index 69c3bd3976bc..0264f73f126d 100644..100755
--- a/core/java/android/app/IUiAutomationConnection.aidl
+++ b/core/java/android/app/IUiAutomationConnection.aidl
@@ -61,6 +61,8 @@ interface IUiAutomationConnection {
oneway void shutdown();
void executeShellCommandWithStderr(String command, in ParcelFileDescriptor sink,
in ParcelFileDescriptor source, in ParcelFileDescriptor stderrSink);
+ void executeShellCommandArrayWithStderr(in String[] command, in ParcelFileDescriptor sink,
+ in ParcelFileDescriptor source, in ParcelFileDescriptor stderrSink);
List<String> getAdoptedShellPermissions();
void addOverridePermissionState(int uid, String permission, int result);
void removeOverridePermissionState(int uid, String permission);
diff --git a/core/java/android/app/UiAutomationConnection.java b/core/java/android/app/UiAutomationConnection.java
index 3c4bd9eb0747..72db465dda53 100644..100755
--- a/core/java/android/app/UiAutomationConnection.java
+++ b/core/java/android/app/UiAutomationConnection.java
@@ -553,7 +553,12 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
} catch (IOException exc) {
throw new RuntimeException("Error running shell command '" + command + "'", exc);
}
+ handleExecuteShellCommandProcess(process, sink, source, stderrSink);
+ }
+ private void handleExecuteShellCommandProcess(final java.lang.Process process,
+ final ParcelFileDescriptor sink, final ParcelFileDescriptor source,
+ final ParcelFileDescriptor stderrSink) {
// Read from process and write to pipe
final Thread readFromProcess;
if (sink != null) {
@@ -616,6 +621,26 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
}
@Override
+ public void executeShellCommandArrayWithStderr(final String[] command,
+ final ParcelFileDescriptor sink, final ParcelFileDescriptor source,
+ final ParcelFileDescriptor stderrSink) throws RemoteException {
+ synchronized (mLock) {
+ throwIfCalledByNotTrustedUidLocked();
+ throwIfShutdownLocked();
+ throwIfNotConnectedLocked();
+ }
+ final java.lang.Process process;
+
+ try {
+ process = Runtime.getRuntime().exec(command);
+ } catch (IOException exc) {
+ throw new RuntimeException(
+ "Error running shell command '" + String.join(" ", command) + "'", exc);
+ }
+ handleExecuteShellCommandProcess(process, sink, source, stderrSink);
+ }
+
+ @Override
public void shutdown() {
synchronized (mLock) {
if (isConnectedLocked()) {