public interface

ShellExecutor

 androidx.test.services.shellexecutor.ShellExecutor

Subclasses:

ShellExecutorImpl

Gradle dependencies

compile group: 'androidx.test', name: 'orchestrator', version: '1.5.0'

  • groupId: androidx.test
  • artifactId: orchestrator
  • version: 1.5.0

Artifact androidx.test:orchestrator:1.5.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:orchestrator com.android.support.test:orchestrator

Overview

Executes a shell command in a similar manner and environment as , (i.e. as either root or shell user).

Unlike this is available on all API levels and will not conflict with other instances of .

Summary

Methods
public java.io.InputStreamexecuteShellCommand(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell)

Execute a command with elevated permissions and return immediately.

public java.io.InputStreamexecuteShellCommand(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell, long timeoutMs)

Execute a command with elevated permissions and return immediately.

public java.lang.StringexecuteShellCommandSync(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell)

Execute a command with elevated permissions and block.

public java.lang.StringexecuteShellCommandSync(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell, long timeoutMs)

Execute a command with elevated permissions and block.

public java.lang.StringgetBinderKey()

Methods

public java.lang.String getBinderKey()

public java.lang.String executeShellCommandSync(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell, long timeoutMs)

Execute a command with elevated permissions and block.

Parameters:

command: The shell command to be executed.
parameters: A java.util.Map parameters to be given to the shell command
shellEnv: A java.util.Map of shell environment variables to be set
executeThroughShell: If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.
timeoutMs: Optional, destroys the executing subprocess if it runs longer than this timeout.

Returns:

java.lang.String representing the contents of the shell output of the command.

public java.lang.String executeShellCommandSync(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell)

Execute a command with elevated permissions and block.

Parameters:

command: The shell command to be executed.
parameters: A java.util.Map parameters to be given to the shell command
shellEnv: A java.util.Map of shell environment variables to be set
executeThroughShell: If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

Returns:

java.lang.String representing the contents of the shell output of the command.

public java.io.InputStream executeShellCommand(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell, long timeoutMs)

Execute a command with elevated permissions and return immediately.

Parameters:

command: The shell command to be executed.
parameters: A java.util.Map parameters to be given to the shell command
shellEnv: A java.util.Map of shell environment variables to be set
executeThroughShell: If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.
timeoutMs: Optional, destroys the executing subprocess if it runs longer than this timeout.

Returns:

java.io.InputStream representing the shell output of the command.

public java.io.InputStream executeShellCommand(java.lang.String command, java.util.List<java.lang.String> parameters, java.util.Map<java.lang.String, java.lang.String> shellEnv, boolean executeThroughShell)

Execute a command with elevated permissions and return immediately.

Parameters:

command: The shell command to be executed.
parameters: A java.util.Map parameters to be given to the shell command
shellEnv: A java.util.Map of shell environment variables to be set
executeThroughShell: If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

Returns:

java.io.InputStream representing the shell output of the command.

Source

/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.services.shellexecutor;

import android.os.RemoteException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * Executes a shell command in a similar manner and environment as {@link UiAutomation
 * #executeShellCommand} , (i.e. as either root or shell user).
 *
 * <p>Unlike {@link UiAutomation} this is available on all API levels and will not conflict with
 * other instances of {@link UiAutomation}.
 */
public interface ShellExecutor {
  /* Returns the instrumentation key for ShellExecutor. */
  String getBinderKey();

  /**
   * Execute a command with elevated permissions and block.
   *
   * @param command The shell command to be executed.
   * @param parameters A {@link Map} parameters to be given to the shell command
   * @param shellEnv A {@link Map} of shell environment variables to be set
   * @param executeThroughShell If set to true, the command string will be executed through the
   *     shell with parameters given as additional shell arguments.
   * @param timeoutMs Optional, destroys the executing subprocess if it runs longer than this
   *     timeout.
   * @return {@link String} representing the contents of the shell output of the command.
   * @throws IOException if cannot execute command on executor service.
   */
  String executeShellCommandSync(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell,
      long timeoutMs)
      throws ClientNotConnected, IOException, RemoteException;

  /**
   * Execute a command with elevated permissions and block.
   *
   * @param command The shell command to be executed.
   * @param parameters A {@link Map} parameters to be given to the shell command
   * @param shellEnv A {@link Map} of shell environment variables to be set
   * @param executeThroughShell If set to true, the command string will be executed through the
   *     shell with parameters given as additional shell arguments.
   * @return {@link String} representing the contents of the shell output of the command.
   * @throws IOException if cannot execute command on executor service.
   */
  String executeShellCommandSync(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell)
      throws ClientNotConnected, IOException, RemoteException;

  /**
   * Execute a command with elevated permissions and return immediately.
   *
   * @param command The shell command to be executed.
   * @param parameters A {@link Map} parameters to be given to the shell command
   * @param shellEnv A {@link Map} of shell environment variables to be set
   * @param executeThroughShell If set to true, the command string will be executed through the
   *     shell with parameters given as additional shell arguments.
   * @param timeoutMs Optional, destroys the executing subprocess if it runs longer than this
   *     timeout.
   * @return {@link java.io.InputStream} representing the shell output of the command.
   * @throws IOException if cannot execute command on executor service.
   */
  InputStream executeShellCommand(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell,
      long timeoutMs)
      throws ClientNotConnected, IOException, RemoteException;

  /**
   * Execute a command with elevated permissions and return immediately.
   *
   * @param command The shell command to be executed.
   * @param parameters A {@link Map} parameters to be given to the shell command
   * @param shellEnv A {@link Map} of shell environment variables to be set
   * @param executeThroughShell If set to true, the command string will be executed through the
   *     shell with parameters given as additional shell arguments.
   * @return {@link java.io.InputStream} representing the shell output of the command.
   * @throws IOException if cannot execute command on executor service.
   */
  InputStream executeShellCommand(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell)
      throws ClientNotConnected, IOException, RemoteException;
}