public final class

ShellExecutorImpl

extends java.lang.Object

implements ShellExecutor

 java.lang.Object

↳androidx.test.services.shellexecutor.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

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)

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)

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)

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)

public java.lang.StringgetBinderKey()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

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)

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)

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)

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)

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.content.Context;
import android.os.RemoteException;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/** {@inheritDoc} */
public final class ShellExecutorImpl implements ShellExecutor {
  private static final String TAG = "ShellExecutorImpl";

  private final Context context;
  private final String binderKey;

  ShellExecutorImpl(Context context, String binderKey) {
    if (null == context) {
      throw new NullPointerException("context, cannot be null!");
    }
    this.context = context;

    if (null == binderKey) {
      Log.e(TAG, "Unable to find the binder key from the instrumentation registry.");
      throw new NullPointerException("binderKey, cannot be null!");
    }
    this.binderKey = binderKey;
  }

  /** {@inheritDoc} */
  @Override
  public String getBinderKey() {
    return binderKey;
  }

  /** {@inheritDoc} */
  @Override
  public String executeShellCommandSync(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell,
      long timeoutMs)
      throws IOException {
    try {
      return ShellCommandClient.execOnServerSync(
          context, binderKey, command, parameters, shellEnv, executeThroughShell, timeoutMs);
    } catch (ClientNotConnected e) {
      Log.e(TAG, "ShellCommandClient not connected. Is ShellCommandExecutor service started?", e);
      throw new RuntimeException(e);
    } catch (IOException | RemoteException e) {
      Log.e(
          TAG, "ShellCommandClient connection failed. Is ShellCommandExecutor service started?", e);
      throw new RuntimeException(e);
    }
  }

  /** {@inheritDoc} */
  @Override
  public String executeShellCommandSync(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell)
      throws IOException {
    return executeShellCommandSync(command, parameters, shellEnv, executeThroughShell, 0L);
  }

  /** {@inheritDoc} */
  @Override
  public InputStream executeShellCommand(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell,
      long timeoutMs)
      throws IOException, RemoteException {
    try {
      return ShellCommandClient.execOnServer(
          context, binderKey, command, parameters, shellEnv, executeThroughShell, timeoutMs);
    } catch (ClientNotConnected e) {
      Log.e(TAG, "ShellCommandClient not connected. Is ShellCommandExecutor service started?", e);
      throw new RuntimeException(e);
    } catch (IOException | RemoteException e) {
      Log.e(
          TAG, "ShellCommandClient connection failed. Is ShellCommandExecutor service started?", e);
      throw new RuntimeException(e);
    }
  }

  /** {@inheritDoc} */
  @Override
  public InputStream executeShellCommand(
      String command,
      List<String> parameters,
      Map<String, String> shellEnv,
      boolean executeThroughShell)
      throws IOException, RemoteException {
    return executeShellCommand(command, parameters, shellEnv, executeThroughShell, 0L);
  }
}