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

Commit a783eb10 authored by Jooyung Han's avatar Jooyung Han Committed by Android (Google) Code Review
Browse files

Merge "Fix UIAutomation.executeShellCommand()" into main

parents 4b6c463e 4e4c89a1
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -1647,10 +1647,13 @@ public final class UiAutomation {

            // Calling out without a lock held.
            mUiAutomationConnection.executeShellCommand(command, sink, null);
        } catch (IOException ioe) {
            Log.e(LOG_TAG, "Error executing shell command!", ioe);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error executing shell command!", re);
        } catch (IOException | RemoteException e) {
            Log.e(LOG_TAG, "Error executing shell command!", e);
        } catch (IllegalArgumentException | NullPointerException | SecurityException e) {
            // An exception of these types is propagated from the server.
            // Rethrow it to keep the old behavior. To avoid FD leak, close the source.
            IoUtils.closeQuietly(source);
            throw e;
        } finally {
            IoUtils.closeQuietly(sink);
        }
@@ -1734,10 +1737,15 @@ public final class UiAutomation {
            // Calling out without a lock held.
            mUiAutomationConnection.executeShellCommandWithStderr(
                    command, sink_read, source_write, stderr_sink_read);
        } catch (IOException ioe) {
            Log.e(LOG_TAG, "Error executing shell command!", ioe);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error executing shell command!", re);
        } catch (IOException | RemoteException e) {
            Log.e(LOG_TAG, "Error executing shell command!", e);
        } catch (IllegalArgumentException | SecurityException | NullPointerException e) {
            // An exception of these types is propagated from the server.
            // Rethrow it to keep the old behavior. To avoid FD leaks, close the sources.
            IoUtils.closeQuietly(sink_write);
            IoUtils.closeQuietly(source_read);
            IoUtils.closeQuietly(stderr_source_read);
            throw e;
        } finally {
            IoUtils.closeQuietly(sink_read);
            IoUtils.closeQuietly(source_write);
+15 −2
Original line number Diff line number Diff line
@@ -550,8 +550,21 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {

        try {
            process = Runtime.getRuntime().exec(command);
        } catch (IOException exc) {
            throw new RuntimeException("Error running shell command '" + command + "'", exc);
        } catch (IOException ex) {
            // Make sure the passed FDs are closed.
            IoUtils.closeQuietly(sink);
            IoUtils.closeQuietly(source);
            IoUtils.closeQuietly(stderrSink);
            // No to need to wrap in RuntimeException. Only to keep the old behavior.
            // This is just logged and not propagated to the remote caller anyway.
            throw new RuntimeException("Error running shell command '" + command + "'", ex);
        } catch (IllegalArgumentException | NullPointerException | SecurityException ex) {
            // Make sure the passed FDs are closed.
            IoUtils.closeQuietly(sink);
            IoUtils.closeQuietly(source);
            IoUtils.closeQuietly(stderrSink);
            // Rethrow the exception. This will be propagated to the remote caller.
            throw ex;
        }

        // Read from process and write to pipe