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

Commit 43fb7395 authored by Chuwei He's avatar Chuwei He
Browse files

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
parent 204576da
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
+25 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -615,6 +620,26 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
        cleanup.start();
    }

    @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) {