IShellEnabledDevice

public interface IShellEnabledDevice

com.android.ddmlib.IShellEnabledDevice


可接收 shell 命令的抽象设备。

摘要

公共方法

abstract void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)

在设备上执行 shell 命令,并将结果发送到 receiver

abstract void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)

在设备上执行 shell 命令,并将结果发送到 receiver

abstract String getName()

返回此设备的(人性化)名称。

abstract ListenableFuture<String> getSystemProperty(String name)

针对系统属性执行潜在的异步查询。

公共方法

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits)

在设备上执行 shell 命令,并将结果发送到 receiver

maxTimeToOutputResponse 用作预期设备输出命令时的最长等待时间。
在任何时候,如果 shell 命令在超过 maxTimeToOutputResponse 的时间内未输出任何内容,该方法将抛出 ShellCommandUnresponsiveException

对于日志输出等命令,应使用 maxTimeToOutputResponse 值为 0,这意味着该方法永远不会抛出异常,并且会阻塞,直到接收方的 IShellOutputReceiver.isCancelled() 返回 true

参数
command String:要执行的 shell 命令

receiver IShellOutputReceiver:将接收 shell 命令输出的 IShellOutputReceiver

maxTimeToOutputResponse long:允许命令在最长多长时间内不输出任何响应。值为 0 表示该方法将无限期等待(直到 receiver 取消执行)命令输出,并且永远不会抛出异常。

maxTimeUnits TimeUnit:非零 maxTimeToOutputResponse 值的单位。

抛出
TimeoutException 在发送命令时连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令。
ShellCommandUnresponsiveException 以防 shell 命令在超过 maxTimeToOutputResponse 的时间内未发送任何输出。
如果连接出现 I/O 错误,则为 true。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits)

在设备上执行 shell 命令,并将结果发送到 receiver

maxTimeToOutputResponse 用作预期设备输出命令时的最长等待时间。
在任何时候,如果 shell 命令在超过 maxTimeToOutputResponse 的时间内未输出任何内容,该方法将抛出 ShellCommandUnresponsiveException

对于日志输出等命令,应使用 maxTimeToOutputResponse 值为 0,这意味着该方法永远不会抛出异常,并且会阻塞,直到接收方的 IShellOutputReceiver.isCancelled() 返回 true

参数
command String:要执行的 shell 命令

receiver IShellOutputReceiver:将接收 shell 命令输出的 IShellOutputReceiver

maxTimeout long:命令返回的最长超时时间。值为 0 表示不会应用最大超时时间。

maxTimeToOutputResponse long:允许命令在最长多长时间内不输出任何响应。值为 0 表示该方法将无限期等待(直到 receiver 取消执行)命令输出,并且永远不会抛出异常。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的单位。

抛出
TimeoutException 在发送命令时连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令。
ShellCommandUnresponsiveException 以防 shell 命令在超过 maxTimeToOutputResponse 的时间内未发送任何输出。
如果连接出现 I/O 错误,则为 true。

getName

public abstract String getName ()

返回相应设备的(人性化)名称。对于 AVD,通常是 AVD 名称;对于设备,则是制造商名称、型号名称和序列号的组合。

返回
String

getSystemProperty

public abstract ListenableFuture<String> getSystemProperty (String name)

针对系统属性执行潜在的异步查询。

参数
name String:要返回的值的名称。

返回
ListenableFuture<String> ListenableFuture. ERROR(get/Future#get() get) 可能会返回 null。