INativeDevice

public interface INativeDevice

com.android.tradefed.device.INativeDevice


为 ddmlib IDevice 提供可靠且级别略高的 API。

重试设备命令(具体数量可配置),并为无响应的设备提供设备恢复界面。

摘要

常量

int UNKNOWN_API_LEVEL

无法检测到 API 级别时的默认值

公共方法

abstract boolean checkApiLevelAgainstNextRelease(int strictMinLevel)

检查给定最低支持级别目前是否支持某项功能。

abstract void clearLogcat()

删除任何累积的 logcat 数据。

abstract void deleteFile(String deviceFilePath)

用于删除设备上的文件或目录的辅助方法。

abstract void deleteFile(String deviceFilePath, int userId)

用于删除设备上的文件或目录的辅助方法。

abstract boolean deviceSoftRestarted(ProcessInfo prevSystemServerProcess)

一种辅助方法,通过比较当前的 system_server 与之前的 system_server ProcessInfo 来检查设备是否软重启。

abstract boolean deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)

一种辅助方法,用于从设备及其 ERROR(/TimeUnit) 检查设备自 UTC 时间起自 UTC 时间起是否进行了软重启。

abstract boolean disableAdbRoot()

关闭 adb root 命令。

abstract boolean doesFileExist(String deviceFilePath)

用于确定设备上是否存在文件的辅助方法。

abstract boolean enableAdbRoot()

开启 adb root 命令。

abstract String executeAdbCommand(long timeout, String... commandArgs)

一种辅助方法,可在指定超时的情况下,将 adb 命令作为系统命令执行。

abstract String executeAdbCommand(String... commandArgs)

将 adb 命令作为系统命令执行的帮助程序方法。

abstract String executeAdbCommand(long timeout, envMap, String... commandArgs)

一种辅助方法,可在指定超时的情况下,将 adb 命令作为系统命令执行。

abstract CommandResult executeFastbootCommand(long timeout, String... commandArgs)

将 fastboot 命令作为系统命令执行的帮助程序方法。

abstract CommandResult executeFastbootCommand(String... commandArgs)

一种辅助方法,用于将 fastboot 命令作为系统命令执行,默认超时时间为 2 分钟。

abstract CommandResult executeLongFastbootCommand(String... commandArgs)

一种辅助方法,用于将长时间运行的 fastboot 命令作为系统命令执行。

abstract CommandResult executeLongFastbootCommand( envVarMap, String... commandArgs)

一种辅助方法,用于以带有系统环境变量的系统命令的形式执行长时间运行的 fastboot 命令。

abstract String executeShellCommand(String command)

一种辅助方法,用于执行 adb shell 命令并返回 String 形式的输出。

abstract void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeoutForCommand, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract void executeShellCommand(String command, IShellOutputReceiver receiver)

执行指定的 adb shell 命令,如果命令失败,将重试多次。

abstract CommandResult executeShellV2Command(String command)

一种辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult(已正确填充命令状态输出、stdout 和 stderr)返回结果。

abstract CommandResult executeShellV2Command(String command, OutputStream pipeToOutput)

一种辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult(已正确填充命令状态输出和 stderr)返回。

abstract CommandResult executeShellV2Command(String command, File pipeAsInput)

一种辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult(已正确填充命令状态输出、stdout 和 stderr)返回结果。

abstract CommandResult executeShellV2Command(String command, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract CommandResult executeShellV2Command(String command, long maxTimeoutForCommand, TimeUnit timeUnit)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract CommandResult executeShellV2Command(String command, File pipeAsInput, OutputStream pipeToOutput, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract CommandResult executeShellV2Command(String command, File pipeAsInput, OutputStream pipeToOutput, OutputStream pipeToError, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

abstract CommandResult fastbootWipePartition(String partition)

用于擦除设备分区的辅助方法。

abstract int getApiLevel()

获取设备 API 级别。

abstract String getBasebandVersion()

获取此设备的基带(无线装置)版本的便捷方法。

abstract Integer getBattery()

返回设备的当前电池电量;如果没有电池电量,则返回 Null。

abstract boolean getBooleanProperty(String name, boolean defaultValue)

返回指定属性的布尔值。

abstract getBootHistory()

辅助方法会收集包含启动时间和启动原因的启动历史记录映射。

abstract getBootHistorySince(long utcEpochTime, TimeUnit timeUnit)

辅助方法从设备收集启动历史记录映射,其中包含设备从指定时间(从新纪元开始算起)以及指定时间单位的启动时间和启动原因。

abstract String getBootloaderVersion()

用于获取此设备的引导加载程序版本的便捷方法。

abstract String getBuildAlias()

检索设备当前正在运行的 build 的别名。

abstract String getBuildFlavor()

检索设备的 build 变种。

abstract String getBuildId()

检索设备当前正在运行的 build。

abstract String getBuildSigningKeys()

返回用于为设备映像签名的密钥类型

通常,Android 设备可能会使用测试密钥(如在 AOSP 中)或发布密钥(由各设备制造商控制)进行签名

abstract DeviceDescriptor getCachedDeviceDescriptor()

如果已分配设备,则返回缓存的 DeviceDescriptor,否则返回当前的 DeviceDescriptor

abstract DeviceDescriptor getCachedDeviceDescriptor(boolean shortDescriptor)

如果已分配设备,则返回缓存的 DeviceDescriptor,否则返回当前的 DeviceDescriptor

abstract String[] getChildren(String deviceFilePath)

有时由于权限问题而无法使用 IFileEntry 的替代方法。

abstract AbstractConnection getConnection()

返回与设备关联的连接。

abstract String getDeviceClass()

获取设备类。

abstract long getDeviceDate()

返回设备的日期(以毫秒为单位,从 Epoch 起算)。

abstract DeviceDescriptor getDeviceDescriptor()

从设备信息中返回 DeviceDescriptor 以获取其相关信息,而无需传递实际的设备对象。

abstract DeviceDescriptor getDeviceDescriptor(boolean shortDescriptor)

从设备信息中返回 DeviceDescriptor 以获取其相关信息,而无需传递实际的设备对象。

abstract TestDeviceState getDeviceState()

获取设备的状态。

abstract long getDeviceTimeOffset(Date date)

用于获取设备与给定 ERROR(/Date) 之间的时差的辅助程序。

abstract InputStreamSource getEmulatorOutput()

获取模拟器 stdout 和 stderr 的流

abstract long getExternalStoreFreeSpace()

用于确定设备外部存储空间中可用空间量的辅助方法。

abstract String getFastbootProductType()

用于在设备处于 fastboot 模式时获取其产品类型的便捷方法。

abstract String getFastbootProductVariant()

用于在设备处于 fastboot 模式时获取其产品类型的便捷方法。

abstract String getFastbootSerialNumber()

返回 fastboot 模式序列号。

abstract String getFastbootVariable(String variableName)

从设备检索给定的 fastboot 变量值。

abstract IFileEntry getFileEntry(String path)

检索对设备上远程文件的引用。

abstract IDevice getIDevice()

返回对关联的 ddmlib IDevice 的引用。

abstract long getIntProperty(String name, long defaultValue)

返回设备中给定属性的整数值。

abstract long getLastExpectedRebootTimeMillis()

返回自 EPOCH 以来 Tradefed API 上次触发重新启动的时间(以毫秒为单位)。由 System.currentTimeMillis() 返回。

abstract int getLaunchApiLevel()

获取设备的第一个已发布 API 级别。

abstract InputStreamSource getLogcat()

获取 logcat 数据的快照流。

abstract InputStreamSource getLogcat(int maxBytes)

获取最近捕获的 logcat 数据 maxBytes 的快照流。

abstract InputStreamSource getLogcatDump()

获取设备当前 logcat 的转储。

abstract InputStreamSource getLogcatSince(long date)

从提供的日期开始,获取已捕获 logcat 数据的快照流。

abstract String getMountPoint(String mountName)

返回装载点。

abstract ITestDevice.MountPointInfo getMountPointInfo(String mountpoint)

返回与指定的装载点路径相对应的 MountPointInfo;如果该路径没有装载任何内容,或者该路径不会作为装载点出现在 /proc/mounts 中,则返回 null

abstract getMountPointInfo()

返回设备上的 /proc/mounts 中信息的解析版本

abstract long getPartitionFreeSpace(String partition)

用于确定设备分区上可用空间量的辅助方法。

abstract ProcessInfo getProcessByName(String processName)

辅助方法会运行“pidof”和“stat”命令,并返回 ProcessInfo 对象,其中包含给定进程的 PID 和进程开始时间。

abstract String getProcessPid(String process)

返回服务的 pid;如果出现问题,则返回 null。

abstract String getProductType()

用于获取此设备的产品类型的便捷方法。

abstract String getProductVariant()

获取此设备的商品款式/规格的便捷方法。

abstract String getProperty(String name)

从设备检索给定的属性值。

abstract ITestDevice.RecoveryMode getRecoveryMode()

获取设备当前使用的恢复模式。

abstract String getSerialNumber()

获取此设备序列号的便捷方法。

abstract getTombstones()

从设备提取并返回 Tombstone 列表。

abstract long getTotalMemory()

返回总物理内存大小(以字节为单位),如果出现内部错误,则返回 -1

abstract boolean getUseFastbootErase()

了解是使用 fastboot 清空还是 fastboot 格式来擦除设备上的分区。

abstract boolean isAdbRoot()
abstract boolean isAdbTcp()
abstract boolean isAppEnumerationSupported()

检查设备上的平台是否支持应用枚举

abstract boolean isBypassLowTargetSdkBlockSupported()

检查设备上的平台是否支持在应用安装时绕过低目标 SDK 代码块

abstract boolean isDebugfsMounted()

检查 debugfs 是否已装载。

abstract boolean isDeviceEncrypted()

返回设备是否已加密的指示值。

abstract boolean isDirectory(String deviceFilePath)

如果设备上的路径是目录,则返回 True,否则返回 false。

abstract boolean isEncryptionSupported()

返回设备是否支持加密的指示值。

abstract boolean isExecutable(String fullPath)

如果设备上的文件路径是可执行文件,则返回 True,否则返回 false。

abstract boolean isHeadless()

如果设备是无头设备(无屏幕),则返回 true,否则返回 false。

abstract boolean isRuntimePermissionSupported()

检查设备上的平台是否支持运行时权限授予

abstract boolean isStateBootloaderOrFastbootd()

如果设备处于 TestDeviceState#FASTBOOTTestDeviceState.FASTBOOTD 状态,则返回 true。

abstract boolean logAnrs(ITestLogger logger)

从设备收集并记录 ANR。

abstract void logOnDevice(String tag, Log.LogLevel level, String format, Object... args)

在设备的 logcat 中记录消息。

abstract void mountDebugfs()

装载 debugfs。

abstract void nonBlockingReboot()

发出重新启动设备的命令,并在命令完成且设备不再对 adb 可见时返回。

abstract void postBootSetup()

在每次启动后执行配置设备以进行测试。

default void postInvocationTearDown()

此方法已废弃。 请改用 postInvocationTearDown(Throwable)

abstract void postInvocationTearDown(Throwable invocationException)

特定于设备的额外步骤需要进行清理,这些清理将在调用完成后执行。

default void preInvocationSetup(IBuildInfo info, MultiMap<String, String> attributes)

将在调用流程之前在设备上执行的设备特定必需设置的额外步骤。

abstract boolean pullDir(String deviceFilePath, File localDir)

以递归方式从设备中提取目录内容。

abstract boolean pullDir(String deviceFilePath, File localDir, int userId)

以递归方式从设备中提取目录内容。

abstract File pullFile(String remoteFilePath, int userId)

在设备之外检索文件,将其存储在本地临时 ERROR(/File) 中,并返回该 File

abstract File pullFile(String remoteFilePath)

在设备之外检索文件,将其存储在本地临时 ERROR(/File) 中,并返回该 File

abstract boolean pullFile(String remoteFilePath, File localFile)

从设备检索文件。

abstract boolean pullFile(String remoteFilePath, File localFile, int userId)

从设备检索文件。

abstract String pullFileContents(String remoteFilePath)

从设备检索文件,并返回内容。

abstract File pullFileFromExternal(String remoteFilePath)

一种便捷方法,用于从设备的外部存储空间中检索文件,将其存储在本地临时 ERROR(/File) 中,然后返回对该 File 的引用。

abstract boolean pushDir(File localDir, String deviceFilePath, int userId)

以递归方式将目录内容推送到设备。

abstract boolean pushDir(File localDir, String deviceFilePath, excludedDirectories)

以递归方式将目录内容推送到设备,同时排除一些被滤除的目录。

abstract boolean pushDir(File localDir, String deviceFilePath)

以递归方式将目录内容推送到设备。

abstract boolean pushFile(File localFile, String deviceFilePath, boolean evaluateContentProviderNeeded)

pushFile(File, String) 的变体,可视需要考虑评估对 content provider 的需求。

abstract boolean pushFile(File localFile, String deviceFilePath)

将文件推送到设备。

abstract boolean pushFile(File localFile, String deviceFilePath, int userId)

将文件推送到设备。

abstract boolean pushString(String contents, String deviceFilePath)

将字符串创建的文件推送到设备

abstract void reboot()

重新启动设备并进入 adb 模式。

abstract void reboot(String reason)

使用指定的 reason 重新启动设备并进入 adb 模式,该模式会在重新启动后保留。

abstract void rebootIntoBootloader()

将设备重新启动为引导加载程序模式。

abstract void rebootIntoFastbootd()

将设备重新启动为 fastbootd 模式。

abstract void rebootIntoRecovery()

重新启动设备并进入 adb 恢复模式。

abstract void rebootIntoSideload(boolean autoReboot)

将设备重新启动为 adb 旁加载模式(请注意,这是恢复模式下的特殊模式)

在设备进入旁加载模式之前屏蔽

abstract void rebootIntoSideload()

将设备重新启动为 adb 旁加载模式(请注意,这是恢复模式下的特殊模式)

在设备进入旁加载模式之前屏蔽

abstract void rebootUntilOnline()

reboot() 的替代项,仅在设备在线(即对 adb 可见)之前阻塞。

abstract void rebootUntilOnline(String reason)

reboot() 的替代项,仅在设备在线(即对 adb 可见)之前阻塞。

abstract void rebootUserspace()

仅重新启动设备的用户空间部分。

abstract void rebootUserspaceUntilOnline()

rebootUserspace() ()} 的替代项,仅在设备在线(即对 adb 可见)之前阻塞。

abstract void remountSystemReadOnly()

将设备上的系统分区设为只读。

abstract void remountSystemWritable()

将设备上的系统分区设为可写入。

abstract void remountVendorReadOnly()

将设备上的 vendor 分区设为只读。

abstract void remountVendorWritable()

将设备上的 vendor 分区设为可写入。

abstract boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, ITestLifeCycleReceiver... listeners)

使用一个或多个监听器作为参数传递的便捷方法。ERROR(/#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection))

abstract boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, listeners)

运行插桩测试并提供设备恢复功能。

abstract boolean runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId, listeners)

ERROR(ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)/com.android.tradefed.device.ITestDevice#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection) ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)) 相同,但会针对指定用户运行测试。

abstract boolean runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId, ITestLifeCycleReceiver... listeners)

ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...) 相同,但会针对指定用户运行测试。

abstract void setDate(Date date)

设置设备上的日期

注意:在设备上设置日期需要 root 权限

abstract void setOptions(TestDeviceOptions options)

为设备设置 TestDeviceOptions

abstract boolean setProperty(String propKey, String propValue)

在设备上设置给定的属性值。

abstract void setRecovery(IDeviceRecovery recovery)

设置要用于此设备的 IDeviceRecovery

abstract void setRecoveryMode(ITestDevice.RecoveryMode mode)

设置要用于设备的当前恢复模式。

abstract void setUseFastbootErase(boolean useFastbootErase)

设置是使用 fastboot 清空还是使用 fastboot 格式擦除设备上的分区。

abstract void startLogcat()

开始在后台捕获设备的 logcat 输出。

abstract void stopEmulatorOutput()

关闭并删除模拟器输出。

abstract void stopLogcat()

停止从设备捕获 logcat 输出,并舍弃当前保存的 logcat 数据。

abstract String switchToAdbTcp()

将设备切换到 adb-over-tcp 模式。

abstract boolean switchToAdbUsb()

通过 USB 模式将设备切换到 adb。

abstract boolean syncFiles(File localFileDir, String deviceFilePath)

将本地文件目录的内容逐步同步到设备。

abstract boolean unlockDevice()

如果设备处于加密状态,则将其解锁。

abstract void unmountDebugfs()

卸载 debugfs。

abstract boolean waitForBootComplete(long timeOut)

阻止,直到设置了设备的启动完成标志。

abstract boolean waitForDeviceAvailable()

等待设备响应迅速并可供测试。

abstract boolean waitForDeviceAvailable(long waitTime)

等待设备响应迅速并可供测试。

abstract boolean waitForDeviceAvailableInRecoverPath(long waitTime)

等待设备响应且可用,而不考虑恢复路径。

abstract void waitForDeviceBootloader()

屏蔽,直到设备可通过 fastboot 可见。

abstract boolean waitForDeviceInRecovery(long waitTime)

使设备处于“adb recovery”状态的块(请注意,这与 IDeviceRecovery 不同)。

abstract boolean waitForDeviceInSideload(long waitTime)

使设备处于“adb 旁加载”状态的块

abstract boolean waitForDeviceNotAvailable(long waitTime)

导致设备不可用(即 adb 中缺失)的块

abstract void waitForDeviceOnline()

屏蔽,直到设备通过 adb 可见。

abstract void waitForDeviceOnline(long waitTime)

屏蔽,直到设备通过 adb 可见。

abstract boolean waitForDeviceShell(long waitTime)

等待设备响应基本 adb shell 命令。

常量

未知 API 级别

public static final int UNKNOWN_API_LEVEL

无法检测到 API 级别时的默认值

常量值: -1 (0xffffffff)

公共方法

checkApiLevelAgainstNextRelease 介绍

public abstract boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

根据最低支持级别,检查目前是否支持某项功能。此方法考虑在提高 API 级别之前尚未发布的功能。

参数
strictMinLevel int:支持相应功能的严格最低级别。

返回
boolean 如果该级别受支持,则为“true”。否则为 false。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

ClearLogcat

public abstract void clearLogcat ()

删除所有累积的 logcat 数据。

如果您想确保 ITestDevice#getLogcat() 仅返回在特定时间点(例如刷写新的设备 build 后等)后生成的日志数据,这会非常有用。

deleteFile

public abstract void deleteFile (String deviceFilePath)

用于删除设备上的文件或目录的辅助方法。

参数
deviceFilePath String:设备上文件的绝对路径。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

deleteFile

public abstract void deleteFile (String deviceFilePath, 
                int userId)

用于删除设备上的文件或目录的辅助方法。

参数
deviceFilePath String:设备上文件的绝对路径。

userId int:要删除的用户 ID

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

已软重启设备

public abstract boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

一种辅助方法,用于通过比较当前的 system_server 与之前的 system_server ProcessInfo 来检查设备是否软重启。使用 getProcessByName(String) 可获享 ProcessInfo 存储空间。

参数
prevSystemServerProcess ProcessInfo:之前的 system_server 进程 ProcessInfo

返回
boolean true(如果设备软重启)

抛出
RuntimeException 如果设备启动原因异常
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

deviceSoftRestartedAccounts 设备

public abstract boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

一种辅助方法,用于从设备及其 ERROR(/TimeUnit) 检查设备自 UTC 时间起自新纪元起是否已软重启。软重启是指 system_server 在设备硬重启(例如请求重启)后重启。可通过 getDeviceDate() 方法获取当前设备 utcEpochTime(以 Milliseccond 表示)。

参数
utcEpochTime long:自纪元开始的设备时间(以秒为单位)。

timeUnit TimeUnit:给定 utcEpochTime 的时间单位 TimeUnit

返回
boolean true(如果设备软重启)

抛出
RuntimeException 如果设备启动原因异常
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

停用 AdbRoot

public abstract boolean disableAdbRoot ()

关闭 adb root。

停用 adb root 可能会导致设备与 adb 断开连接。此方法将阻塞,直到设备可用。

返回
boolean 如果成功,则为 true

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

doFileExist

public abstract boolean doesFileExist (String deviceFilePath)

用于确定设备上是否存在文件的辅助方法。

参数
deviceFilePath String:要检查的设备上文件的绝对路径

返回
boolean 如果文件存在,则返回 true,否则返回 false

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

启用 AdbRoot

public abstract boolean enableAdbRoot ()

开启 adb root。如果“enable-root”设置为“false”,系统将记录一条消息并返回,但不会启用 root。

启用 adb root 可能会导致设备与 adb 断开连接。此方法将阻塞,直到设备可用。

返回
boolean 如果成功,则为 true

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 AdbCommand

public abstract String executeAdbCommand (long timeout, 
                String... commandArgs)

一种辅助方法,可在指定超时的情况下,将 adb 命令作为系统命令执行。

应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。

参数
timeout long:表示设备无响应的时间(以毫秒为单位),0L 表示无超时

commandArgs String:要运行的 adb 命令和参数

返回
String 标准输出。如果命令执行失败,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 AdbCommand

public abstract String executeAdbCommand (String... commandArgs)

将 adb 命令作为系统命令执行的帮助程序方法。

应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。

参数
commandArgs String:要运行的 adb 命令和参数

返回
String 标准输出。如果命令执行失败,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 AdbCommand

public abstract String executeAdbCommand (long timeout, 
                 envMap, 
                String... commandArgs)

一种辅助方法,可在指定超时的情况下,将 adb 命令作为系统命令执行。

应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。

参数
timeout long:表示设备无响应的时间(以毫秒为单位),0L 表示无超时

envMap :要为命令设置的环境

commandArgs String:要运行的 adb 命令和参数

返回
String 标准输出。如果命令执行失败,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeFastbootCommand

public abstract CommandResult executeFastbootCommand (long timeout, 
                String... commandArgs)

一种辅助方法,用于将 fastboot 命令作为系统命令执行。

预计在设备已处于 fastboot 模式时使用。

参数
timeout long:命令过期前的时间(以毫秒为单位)

commandArgs String:要运行的 fastboot 命令和参数

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeFastbootCommand

public abstract CommandResult executeFastbootCommand (String... commandArgs)

一种辅助方法,用于将 fastboot 命令作为系统命令执行,默认超时时间为 2 分钟。

预计在设备已处于 fastboot 模式时使用。

参数
commandArgs String:要运行的 fastboot 命令和参数

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeLongFastbootCommand

public abstract CommandResult executeLongFastbootCommand (String... commandArgs)

一种辅助方法,用于将长时间运行的 fastboot 命令作为系统命令执行。

除了使用更长的超时之外,与 executeFastbootCommand(String) 基本相同。

参数
commandArgs String:要运行的 fastboot 命令和参数

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeLongFastbootCommand

public abstract CommandResult executeLongFastbootCommand ( envVarMap, 
                String... commandArgs)

一种辅助方法,用于以带有系统环境变量的系统命令的形式执行长时间运行的 fastboot 命令。

除了使用更长的超时之外,与 executeFastbootCommand(String) 基本相同。

参数
envVarMap :fastboot 命令运行时所在的系统环境变量

commandArgs String:要运行的 fastboot 命令和参数

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeShellCommand

public abstract String executeShellCommand (String command)

一种辅助方法,用于执行 adb shell 命令并返回 String 形式的输出。

参数
command String:要运行的 adb shell 命令

返回
String shell 输出

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputShellResponse, 
                TimeUnit timeUnit, 
                int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

receiver IShellOutputReceiver:要将 shell 输出定向到的 IShellOutputReceiver

maxTimeToOutputShellResponse long:允许命令不输出任何响应的最长时间;单位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

retryAttempts int:命令因异常而失败时的最大重试次数。如果 retryAttempts 执行失败,系统会抛出 DeviceNotResponsiveException。

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeoutForCommand, 
                long maxTimeToOutputShellResponse, 
                TimeUnit timeUnit, 
                int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

receiver IShellOutputReceiver:要将 shell 输出定向到的 IShellOutputReceiver

maxTimeoutForCommand long:要完成的命令的最长超时时间;单位为 timeUnit 中指定的

maxTimeToOutputShellResponse long:允许命令不输出任何响应的最长时间;单位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

retryAttempts int:命令因异常而失败时的最大重试次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

执行指定的 adb shell 命令,如果命令失败,将重试多次。

具有默认值的更简单的 executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, long, TimeUnit, int) 形式。

参数
command String:要运行的 adb shell 命令

receiver IShellOutputReceiver:要将 shell 输出定向到的 IShellOutputReceiver

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command)

一种辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult(已正确填充命令状态输出、stdout 和 stderr)返回结果。

参数
command String:应运行的命令。

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                OutputStream pipeToOutput)

一种辅助方法,用于执行 adb shell 命令并返回结果为 CommandResult(已正确填充命令状态输出和 stderr)。stdout 将被定向到指定的流。

参数
command String:应运行的命令。

pipeToOutput OutputStreamERROR(/OutputStream)(系统将在其中重定向 std 输出)或 null。

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput)

一种辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult(已正确填充命令状态输出、stdout 和 stderr)返回结果。

参数
command String:应运行的命令。

pipeAsInput File:将作为命令输入的 ERROR(/File) 或 null。

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit, 
                int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

maxTimeoutForCommand long:要完成的命令的最长超时时间;单位为 timeUnit 中指定的

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

retryAttempts int:命令因异常而失败时的最大重试次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。

返回
CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

maxTimeoutForCommand long:要完成的命令的最长超时时间;单位为 timeUnit 中指定的

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

返回
CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput, 
                OutputStream pipeToOutput, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit, 
                int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

pipeAsInput File:将作为命令输入的 ERROR(/File) 或 null。

pipeToOutput OutputStreamERROR(/OutputStream)(系统将在其中重定向 std 输出)或 null。

maxTimeoutForCommand long:要完成的命令的最长超时时间;单位为 timeUnit 中指定的

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

retryAttempts int:命令因异常而失败时的最大重试次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。

返回
CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

执行 ShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput, 
                OutputStream pipeToOutput, 
                OutputStream pipeToError, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit, 
                int retryAttempts)

执行 adb shell 命令,并使用更多参数来控制命令行为。

参数
command String:要运行的 adb shell 命令

pipeAsInput File:将作为命令输入的 ERROR(/File) 或 null。

pipeToOutput OutputStreamERROR(/OutputStream)(系统将在其中重定向 std 输出)或 null。

pipeToError OutputStream:将重定向 std 错误的 ERROR(/OutputStream) 或 null。

maxTimeoutForCommand long:要完成的命令的最长超时时间;单位为 timeUnit 中指定的

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

retryAttempts int:命令因异常而失败时的最大重试次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。

返回
CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

fastbootWipePartition

public abstract CommandResult fastbootWipePartition (String partition)

用于擦除设备分区的辅助方法。

如果 getUseFastbootErase()true,则将使用 fastboot 清空功能擦除分区。然后,设备必须在下次启动时创建文件系统。否则,将使用 fastboot 格式,这将在设备上创建一个新的文件系统。

预计在设备已处于 fastboot 模式时使用。

参数
partition String:要擦除的分区

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getApiLevel

public abstract int getApiLevel ()

获取设备 API 级别。默认为 UNKNOWN_API_LEVEL

返回
int 一个整数,表示设备的 API 级别

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBasebandVersion

public abstract String getBasebandVersion ()

获取此设备的基带(无线装置)版本的便捷方法。获取无线装置版本的操作因设备而异,因此不一定会返回所有设备的正确信息。此方法依赖于 gsm.version.baseband 属性返回正确的版本信息。这对于某些 CDMA 设备来说并不准确,而且此处返回的版本可能与 fastboot 报告的版本不一致,并且可能不会返回 CDMA 无线装置的版本。 要点:只有在 gsm.version.baseband 属性与 fastboot getvar version-baseband 返回的版本相同时,此方法才会报告准确的版本。

返回
String String 基带版本;如果无法确定,则为 null(设备没有无线装置或版本字符串无法读取)

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getBattery

public abstract Integer getBattery ()

返回设备的当前电池电量;如果没有电池电量,则返回 Null。

返回
Integer

getBooleanProperty

public abstract boolean getBooleanProperty (String name, 
                boolean defaultValue)

返回指定属性的布尔值。

参数
name String:属性名称

defaultValue boolean:属性为空或不存在时返回的默认值。

返回
boolean 如果属性的值为 "1""y""yes""on""true",则为 true;如果属性的值为 "0""n""no""off""false",则为 defaultValue,则为 false

抛出
DeviceNotAvailableException

getBootHistory

public abstract  getBootHistory ()

辅助方法会收集包含启动时间和启动原因的启动历史记录映射。

返回
启动时间(自纪元以来经过的秒数)和启动原因的映射

抛出
DeviceNotAvailableException

getBootHistorySince

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

辅助方法从设备和指定的时间单位中收集自设备纪元以来的给定时间以来的启动历史记录映射,其中包含启动时间和启动原因。可通过 getDeviceDate() 方法获取当前设备 utcEpochTime(以毫秒为单位)。

参数
utcEpochTime long:自 Epoch 以来的设备时间。

timeUnit TimeUnit:时间单位 TimeUnit

返回
启动时间(自纪元以来经过的秒数)和启动原因的映射

抛出
DeviceNotAvailableException

getBootloaderVersion

public abstract String getBootloaderVersion ()

用于获取此设备的引导加载程序版本的便捷方法。

将尝试从设备的当前状态中检索引导加载程序版本。(即,如果设备处于 fastboot 模式,它将尝试从 fastboot 检索版本)

返回
String String 引导加载程序版本;如果找不到,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getBuildAlias

public abstract String getBuildAlias ()

检索设备当前正在运行的 build 的别名。

build 别名通常比 build ID(通常是 Nexus build 的数字)可读性更强。例如,最终的 Android 4.2 版本的 build 别名 JDQ39,build ID 为 573038

返回
String build 别名;如果无法检索,则回退到 build ID

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildFlavor

public abstract String getBuildFlavor ()

检索设备的 build 变种。

返回
String build 变种;如果无法检索到,则为 null

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildId

public abstract String getBuildId ()

检索设备当前正在运行的 build。

返回
String build ID,或 IBuildInfo#UNKNOWN_BUILD_ID(如果无法检索)

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildSigningKeys

public abstract String getBuildSigningKeys ()

返回用于为设备映像签名的密钥类型

通常,Android 设备可能会使用测试密钥(如在 AOSP 中)或发布密钥(由各设备制造商控制)签名

返回
String 签名密钥(如果找到),否则为 null。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getCachedDeviceDescriptor

public abstract DeviceDescriptor getCachedDeviceDescriptor ()

如果已分配设备,则返回缓存的 DeviceDescriptor,否则返回当前的 DeviceDescriptor

返回
DeviceDescriptor

getCachedDeviceDescriptor

public abstract DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

如果已分配设备,则返回缓存的 DeviceDescriptor,否则返回当前的 DeviceDescriptor

参数
shortDescriptor boolean:是否将描述符限制为最低限度信息

返回
DeviceDescriptor

getChildren

public abstract String[] getChildren (String deviceFilePath)

有时由于权限问题而无法使用 IFileEntry 的替代方案。

参数
deviceFilePath String:设备上要执行搜索的路径

返回
String[] 包含设备路径中所有文件的字符串数组。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getConnection

public abstract AbstractConnection getConnection ()

返回与设备关联的连接。

返回
AbstractConnection

getDeviceClass

public abstract String getDeviceClass ()

获取设备类。

返回
String String 设备类。

getDeviceDate

public abstract long getDeviceDate ()

返回设备的日期(以毫秒为单位,从 Epoch 起算)。

返回
long 设备的日期(采用纪元格式)。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

获取设备描述符

public abstract DeviceDescriptor getDeviceDescriptor ()

从设备信息中返回 DeviceDescriptor 以获取其相关信息,而无需传递实际的设备对象。

返回
DeviceDescriptor

获取设备描述符

public abstract DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

从设备信息中返回 DeviceDescriptor 以获取其相关信息,而无需传递实际的设备对象。

参数
shortDescriptor boolean:是否将描述符限制为最低限度信息

返回
DeviceDescriptor

getDeviceState

public abstract TestDeviceState getDeviceState ()

获取设备的状态。

返回
TestDeviceState

getDeviceTimeOffset

public abstract long getDeviceTimeOffset (Date date)

帮助获取设备与给定 ERROR(/Date) 之间的时差。在内部使用纪元时间。

参数
date Date

返回
long 以毫秒计的差值

抛出
DeviceNotAvailableException

getEmulatorOutput

public abstract InputStreamSource getEmulatorOutput ()

获取模拟器 stdout 和 stderr 的流

返回
InputStreamSource 模拟器输出

getExternalStoreFreeSpace

public abstract long getExternalStoreFreeSpace ()

用于确定设备外部存储空间中可用空间量的辅助方法。

返回
long 可用空间量(以 KB 为单位)

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getFastbootProductType

public abstract String getFastbootProductType ()

用于在设备处于 fastboot 模式时获取其产品类型的便捷方法。

只有在设备应处于 fastboot 模式时,才应使用此方法。在这种情况下,它的变体比通用 getProductType() 方法更安全,因为 ITestDevice 知道在设备处于错误状态或无响应时将设备恢复到 fastboot 中。

返回
String String 产品类型名称;如果无法确定,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getFastbootProductVariant

public abstract String getFastbootProductVariant ()

用于在设备处于 fastboot 模式时获取其产品类型的便捷方法。

只有在设备应处于 fastboot 模式时,才应使用此方法。在这种情况下,它的变体比通用 getProductType() 方法更安全,因为 ITestDevice 知道在设备处于错误状态或无响应时将设备恢复到 fastboot 中。

返回
String String 产品类型名称;如果无法确定,则为 null

抛出
DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

getFastbootSerialNumber

public abstract String getFastbootSerialNumber ()

返回 fastboot 模式序列号。

返回
String

getFastbootVariable

public abstract String getFastbootVariable (String variableName)

从设备检索给定的 fastboot 变量值。

参数
variableName String:变量名称

返回
String 属性值;如果不存在,则返回 null

抛出
不支持操作异常
DeviceNotAvailableException

getFileEntry

public abstract IFileEntry getFileEntry (String path)

检索对设备上远程文件的引用。

参数
path String:要检索的文件路径。可以是绝对路径或相对于“/”的路径。(即“/system”和“system”语法均受支持)

返回
IFileEntry IFileEntrynull(如果找不到指定 path 的文件)

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getIDevice

public abstract IDevice getIDevice ()

返回对关联的 ddmlib IDevice 的引用。

每次设备与 adb 断开连接并重新连接时,DDMS 都可能会分配新的 IDevice。因此,调用方不应保留对 IDevice 的引用,因为该引用可能会过时。

返回
IDevice IDevice

getIntProperty

public abstract long getIntProperty (String name, 
                long defaultValue)

返回设备中给定属性的整数值。

参数
name String:属性名称

defaultValue long:属性为空或不存在时返回的默认值。

返回
long 属性值;如果属性为空、不存在或没有整数值,则返回 defaultValue

抛出
DeviceNotAvailableException

getLastexpectedRebootTimeMillis

public abstract long getLastExpectedRebootTimeMillis ()

返回自 EPOCH 以来 Tradefed API 上次触发重新启动的时间(以毫秒为单位),由 System.currentTimeMillis() 返回。

返回
long

getLaunchApiLevel

public abstract int getLaunchApiLevel ()

获取设备首次发布的 API 级别。默认为 UNKNOWN_API_LEVEL

返回
int 一个整数,表示设备最初发布的 API 级别

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

获取 Logcat

public abstract InputStreamSource getLogcat ()

获取 logcat 数据的快照流。

可通过以下两种模式运行:

  • 如果当前正在在后台捕获 logcat,则最多会返回后台 logcat 捕获的当前内容的 TestDeviceOptions.getMaxLogcatDataSize() 字节
  • 否则,如果设备当前正在响应,则返回 logcat 数据的静态转储

    返回
    InputStreamSource

  • 获取 Logcat

    public abstract InputStreamSource getLogcat (int maxBytes)

    获取最近捕获的 logcat 数据 maxBytes 的快照流。

    适用于以下情形:您想要捕获已捕获的 logcat 数据频繁的快照,而又不因获取整个 getLogcat() 快照而造成磁盘空间巨大损失。

    参数
    maxBytes int:要返回的数据量上限。应是一个适合内存大小的数值

    返回
    InputStreamSource

    getLogcatDump

    public abstract InputStreamSource getLogcatDump ()

    获取设备当前 logcat 的转储。与 getLogcat() 不同,此方法将始终返回 logcat 的静态转储。

    缺点是,如果设备无法访问,将不会返回任何内容。

    返回
    InputStreamSource logcat 数据的 InputStreamSource。如果未能捕获 logcat 数据,则返回空流。

    getLogcatLogcat

    public abstract InputStreamSource getLogcatSince (long date)

    从提供的日期开始,获取已捕获 logcat 数据的快照流。设备上的时间应使用 getDeviceDate()

    参数
    date long:从新纪元格式开始截取快照的时间(以毫秒为单位)。(可使用“日期 +%s”获得)

    返回
    InputStreamSource

    getMountPoint

    public abstract String getMountPoint (String mountName)

    返回装载点。

    如果 IDevice 中的缓存信息不可用,则直接查询设备。

    TODO:将此行为移至 IDevice#getMountPoint(String)

    参数
    mountName String:装载点的名称

    返回
    String 装载点或 null

    getMountPointInfo

    public abstract ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    返回与指定的装载点路径相对应的 MountPointInfo;如果该路径未装载任何内容,或者不会作为装载点出现在 /proc/mounts 中,则返回 null

    参数
    mountpoint String

    返回
    ITestDevice.MountPointInfo MountPointInfoERROR(/List),其中包含“/proc/mounts”中的信息

    抛出
    DeviceNotAvailableException

    getMountPointInfo

    public abstract  getMountPointInfo ()

    返回设备上 /proc/mounts 中信息的解析版本

    返回
    MountPointInfoERROR(/List),其中包含“/proc/mounts”中的信息

    抛出
    DeviceNotAvailableException

    getPartitionFreeSpace

    public abstract long getPartitionFreeSpace (String partition)

    用于确定设备分区上可用空间量的辅助方法。

    参数
    partition String

    返回
    long 可用空间量(以 KB 为单位)

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    getProcessByName

    public abstract ProcessInfo getProcessByName (String processName)

    辅助方法会运行“pidof”和“stat”命令,并返回 ProcessInfo 对象,其中包含给定进程的 PID 和进程开始时间。

    参数
    processName String:进程名称字符串。

    返回
    ProcessInfo 给定 processName 的 ProcessInfo

    抛出
    DeviceNotAvailableException

    getProcessPid

    public abstract String getProcessPid (String process)

    返回服务的 pid;如果出现问题,则返回 null。

    参数
    process String:进程名称字符串。

    返回
    String

    抛出
    DeviceNotAvailableException

    getProductType

    public abstract String getProductType ()

    用于获取此设备的产品类型的便捷方法。

    如果设备处于 adb 或 fastboot 模式,此方法将适用。

    返回
    String String 产品类型名称。将不会为 null

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复,或者无法确定产品类型

    getProductVariant

    public abstract String getProductVariant ()

    获取此设备的产品款式/规格的便捷方法。

    如果设备处于 adb 或 fastboot 模式,此方法将适用。

    返回
    String String 商品款式/规格名称或 null(如果无法确定)

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    getProperty

    public abstract String getProperty (String name)

    从设备检索给定的属性值。

    参数
    name String:属性名称

    返回
    String 属性值;如果不存在,则返回 null

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    getRecoveryMode

    public abstract ITestDevice.RecoveryMode getRecoveryMode ()

    获取设备当前使用的恢复模式。

    返回
    ITestDevice.RecoveryMode 设备当前使用的恢复模式。

    getSerialNumber

    public abstract String getSerialNumber ()

    获取此设备序列号的便捷方法。

    返回
    String String 序列号

    getTombstone

    public abstract  getTombstones ()

    从设备提取并返回 Tombstone 列表。需要 root 权限。

    方法是尽其所能,因此如果由于某种原因未能提取一个 Tombstone,它便会从列表中消失。只有 DeviceNotAvailableException 会提前终止该方法。

    返回
    Tombstone 文件列表,如果没有 Tombstone,则为空。

    抛出
    DeviceNotAvailableException

    另见:

    getTotalMemory

    public abstract long getTotalMemory ()

    返回总物理内存大小(以字节为单位),如果出现内部错误,则返回 -1

    返回
    long

    getUseFastbootErase

    public abstract boolean getUseFastbootErase ()

    了解是否使用 fastboot 清空或 fastboot 格式擦除设备上的分区。

    返回
    boolean 如果使用 fastboot 清空,则为 true;如果使用 fastboot 格式,则为 false

    isAdbRoot

    public abstract boolean isAdbRoot ()

    返回
    boolean 如果设备当前具有 adb root,则为 true,否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    isAdbTcp

    public abstract boolean isAdbTcp ()

    返回
    boolean 如果设备已连接到 adb-over-tcp,则为 true,否则为 false

    isAppEnumerationSupported

    public abstract boolean isAppEnumerationSupported ()

    检查设备上的平台是否支持应用枚举

    返回
    boolean 如果支持应用枚举,则为 true,否则为 false

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isBypassLowTargetSdkBlockSupported

    public abstract boolean isBypassLowTargetSdkBlockSupported ()

    检查设备上的平台是否支持在应用安装时绕过低目标 SDK 代码块

    返回
    boolean 如果支持绕过低目标 SDK 块,则为 true,否则为 false

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    已装载

    public abstract boolean isDebugfsMounted ()

    检查 debugfs 是否已装载。

    返回
    boolean true(如果已装载 debugfs)

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isDeviceEncrypted

    public abstract boolean isDeviceEncrypted ()

    如果设备经过加密,则返回 。

    返回
    boolean true(如果设备已加密)。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    isDirectory

    public abstract boolean isDirectory (String deviceFilePath)

    如果设备上的路径是目录,则返回 True,否则返回 false。

    参数
    deviceFilePath String

    返回
    boolean

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isEncryptionSupported

    public abstract boolean isEncryptionSupported ()

    返回设备是否支持加密的指示值。

    返回
    boolean true(如果设备支持加密)。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    可执行

    public abstract boolean isExecutable (String fullPath)

    如果设备上的文件路径是可执行文件,则返回 True,否则返回 false。

    参数
    fullPath String

    返回
    boolean

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    无头

    public abstract boolean isHeadless ()

    如果设备是无头设备(无屏幕),则返回 true,否则返回 false。

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public abstract boolean isRuntimePermissionSupported ()

    检查设备上的平台是否支持授予运行时权限

    返回
    boolean 如果支持运行时权限,则为 true,否则为 false。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public abstract boolean isStateBootloaderOrFastbootd ()

    如果设备处于 TestDeviceState#FASTBOOTTestDeviceState.FASTBOOTD,则返回 true。

    返回
    boolean

    logAnrs

    public abstract boolean logAnrs (ITestLogger logger)

    从设备收集并记录 ANR。

    参数
    logger ITestLogger:用于记录 ANR 的 ITestLogger

    返回
    boolean 如果记录成功,则为 true,否则为 false。

    抛出
    DeviceNotAvailableException

    在设备上登录

    public abstract void logOnDevice (String tag, 
                    Log.LogLevel level, 
                    String format, 
                    Object... args)

    在设备的 logcat 中记录消息。这是安全调用,即使日志记录失败,也不会抛出。

    参数
    tag String:我们在 logcat 中记录消息的标记。

    level Log.LogLevel:logcat 中消息的调试级别。

    format String:消息格式。

    args Object:要通过 String.format() 替换的参数。

    mountDebugfs

    public abstract void mountDebugfs ()

    装载 debugfs。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    非阻塞重新启动

    public abstract void nonBlockingReboot ()

    发出重新启动设备的命令,并在命令完成且设备不再对 adb 可见时返回。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    postBootSetup

    public abstract void postBootSetup ()

    在每次启动后执行配置设备以进行测试。

    应在设备完全启动/可用后调用

    在正常情况下,不需要明确调用此方法,因为实现应该会在执行重新启动时自动执行这些步骤。

    当设备因其他事件而重新启动时(例如,当 fastboot 更新命令完成时),可能需要调用该函数时

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    postInvocationTearDown

    public void postInvocationTearDown ()

    此方法已废弃。
    改用 postInvocationTearDown(Throwable)

    特定于设备的额外步骤需要进行清理,这些清理将在调用完成后执行。

    postInvocationTearDown

    public abstract void postInvocationTearDown (Throwable invocationException)

    特定于设备的额外步骤需要进行清理,这些清理将在调用完成后执行。

    参数
    invocationException Throwable:如果有,则为调用失败引发的最终异常。

    preInvocationSetup

    public void preInvocationSetup (IBuildInfo info, 
                    MultiMap<String, String> attributes)

    将在调用流程之前在设备上执行的设备特定必需设置的额外步骤。

    参数
    info IBuildInfo:设备的 IBuildInfo

    attributes MultiMap:存储在调用上下文中的属性

    抛出
    com.android.tradefed.targetprep.TargetSetupError
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException
    TargetSetupError

    pullDir

    public abstract boolean pullDir (String deviceFilePath, 
                    File localDir)

    以递归方式从设备中提取目录内容。

    参数
    deviceFilePath String:远程来源的绝对文件路径

    localDir File:用于拉取文件的本地目录

    返回
    boolean 如果文件已成功拉取,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullDir

    public abstract boolean pullDir (String deviceFilePath, 
                    File localDir, 
                    int userId)

    以递归方式从设备中提取目录内容。

    参数
    deviceFilePath String:远程来源的绝对文件路径

    localDir File:用于拉取文件的本地目录

    userId int:要从中提取的用户 ID

    返回
    boolean 如果文件已成功拉取,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullFile

    public abstract File pullFile (String remoteFilePath, 
                    int userId)

    从设备检索文件,将其存储在本地临时 ERROR(/File) 中,并返回该 File

    参数
    remoteFilePath String:设备上文件的绝对路径。

    userId int:要从中提取的用户 ID

    返回
    File 包含设备文件内容的 ERROR(/File);如果复制因任何原因(包括主机文件系统的问题)失败,则为 null

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullFile

    public abstract File pullFile (String remoteFilePath)

    从设备检索文件,将其存储在本地临时 ERROR(/File) 中,并返回该 File

    参数
    remoteFilePath String:设备上文件的绝对路径。

    返回
    File 包含设备文件内容的 ERROR(/File);如果复制因任何原因(包括主机文件系统的问题)失败,则为 null

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullFile

    public abstract boolean pullFile (String remoteFilePath, 
                    File localFile)

    从设备检索文件。

    参数
    remoteFilePath String:设备上文件的绝对路径。

    localFile File:用于存储内容的本地文件。如果为非空值,则内容将被替换。

    返回
    boolean 如果文件检索成功,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullFile

    public abstract boolean pullFile (String remoteFilePath, 
                    File localFile, 
                    int userId)

    从设备检索文件。

    参数
    remoteFilePath String:设备上文件的绝对路径。

    localFile File:用于存储内容的本地文件。如果为非空值,则内容将被替换。

    userId int:要从中提取的用户 ID

    返回
    boolean 如果文件检索成功,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pullFileContents

    public abstract String pullFileContents (String remoteFilePath)

    从设备检索文件,并返回内容。

    参数
    remoteFilePath String:设备上文件的绝对路径。

    返回
    String 包含设备文件内容的 String;如果复制因任何原因(包括主机文件系统的问题)失败,则为 null

    抛出
    DeviceNotAvailableException

    从外部拉取文件

    public abstract File pullFileFromExternal (String remoteFilePath)

    一种便捷方法,用于从设备的外部存储空间中检索文件,将其存储在本地临时 ERROR(/File) 中,然后返回对该 File 的引用。

    参数
    remoteFilePath String:设备上的文件路径(相对于设备外部存储装载点)

    返回
    File 包含设备文件内容的 ERROR(/File);如果复制因任何原因(包括主机文件系统的问题)失败,则为 null

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    推送目录

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath, 
                    int userId)

    以递归方式将目录内容推送到设备。

    参数
    localDir File:要推送的本地目录

    deviceFilePath String:远程目的地的绝对文件路径

    userId int:要推送到的用户 ID

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    推送目录

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath, 
                     excludedDirectories)

    以递归方式将目录内容推送到设备,同时排除一些被滤除的目录。

    参数
    localDir File:要推送的本地目录

    deviceFilePath String:远程目的地的绝对文件路径

    excludedDirectories :一组不应推送的排除目录名称。

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    推送目录

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath)

    以递归方式将目录内容推送到设备。

    参数
    localDir File:要推送的本地目录

    deviceFilePath String:远程目的地的绝对文件路径

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath, 
                    boolean evaluateContentProviderNeeded)

    pushFile(File, String) 的变体,可视需要考虑评估对 content provider 的需求。

    参数
    localFile File:要推送的本地文件

    deviceFilePath String:远程目标的绝对文件路径

    evaluateContentProviderNeeded boolean:是否检查我们是否需要 content provider

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath)

    将文件推送到设备。默认使用 content provider。

    参数
    localFile File:要推送的本地文件

    deviceFilePath String:远程目标的绝对文件路径

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath, 
                    int userId)

    将文件推送到设备。默认使用 content provider。

    参数
    localFile File:要推送的本地文件

    deviceFilePath String:远程目标的绝对文件路径

    userId int:要推送到的用户 ID

    返回
    boolean 如果文件已成功推送,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    推送字符串

    public abstract boolean pushString (String contents, 
                    String deviceFilePath)

    将字符串创建的文件推送到设备

    参数
    contents String:要推送的文件的内容

    deviceFilePath String:远程目标的绝对文件路径

    返回
    boolean 如果字符串推送成功,则为 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    重新启动

    public abstract void reboot ()

    重新启动设备并进入 adb 模式。

    在设备可用之前屏蔽。

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    重新启动

    public abstract void reboot (String reason)

    使用给定的 reason 重新启动设备并进入 adb 模式,以便在重新启动后保留。

    屏蔽,直到设备可用。

    可以通过查询 sys.boot.reason 属性获取上次重新启动的原因。

    参数
    reason String:此次重新启动的原因;如果未指定原因,则为 null

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    重新启动

    public abstract void rebootIntoBootloader ()

    将设备重新启动为引导加载程序模式。

    屏蔽,直到设备进入引导加载程序模式。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    重新启动进入 Fastbootd

    public abstract void rebootIntoFastbootd ()

    将设备重新启动为 fastbootd 模式。

    在设备处于 fastbootd 模式之前屏蔽。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    重新启动进入恢复模式

    public abstract void rebootIntoRecovery ()

    重新启动设备并进入 adb 恢复模式。

    在设备进入恢复模式之前屏蔽

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    重新启动

    public abstract void rebootIntoSideload (boolean autoReboot)

    将设备重新启动为 adb 旁加载模式(请注意,这是恢复模式下的特殊模式)

    在设备进入旁加载模式之前屏蔽

    参数
    autoReboot boolean:是否在旁加载后自动重新启动设备

    抛出
    DeviceNotAvailableException 如果设备在重新启动后未处于旁加载状态

    重新启动

    public abstract void rebootIntoSideload ()

    将设备重新启动为 adb 旁加载模式(请注意,这是恢复模式下的特殊模式)

    在设备进入旁加载模式之前屏蔽

    抛出
    DeviceNotAvailableException 如果设备在重新启动后未处于旁加载状态

    重新启动到在线状态

    public abstract void rebootUntilOnline ()

    reboot() 的替代项,仅在设备在线(即对 adb 可见)之前阻塞。

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    重新启动到在线状态

    public abstract void rebootUntilOnline (String reason)

    reboot() 的替代项,仅在设备在线(即对 adb 可见)之前阻塞。

    参数
    reason String:此次重新启动的原因;如果未指定原因,则为 null

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    另见:

    重新启动用户空间

    public abstract void rebootUserspace ()

    仅重新启动设备的用户空间部分。

    屏蔽,直到设备可用。

    警告。用户空间重新启动目前正在积极开发中,使用时请自行承担风险。

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    重新启动用户空间至在线状态

    public abstract void rebootUserspaceUntilOnline ()

    rebootUserspace() ()} 的替代名称,仅在设备在线(即对 adb 可见)之前阻塞。

    抛出
    DeviceNotAvailableException 如果设备在重新启动后不可用

    remountSystemReadOnly

    public abstract void remountSystemReadOnly ()

    将设备上的系统分区设为只读。可能会重新启动设备。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountSystemWritable

    public abstract void remountSystemWritable ()

    使设备上的系统分区可写入。可能会重新启动设备。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    重新装载供应商只读

    public abstract void remountVendorReadOnly ()

    将设备上的 vendor 分区设为只读。可能会重新启动设备。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    可重新装载供应商可写

    public abstract void remountVendorWritable ()

    使设备上的 vendor 分区可写入。可能会重新启动设备。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    runInstrumentationTest

    public abstract boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                    ITestLifeCycleReceiver... listeners)

    使用一个或多个监听器作为参数传递的便捷方法。ERROR(/#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection))

    参数
    runner IRemoteAndroidTestRunner:用于运行测试的 IRemoteAndroidTestRunner

    listeners ITestLifeCycleReceiver:测试结果监听器

    返回
    boolean 如果测试命令已完成,则为 true。如果未能完成,但恢复成功,则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。例如,测试命令未完成且恢复失败。

    runInstrumentationTest

    public abstract boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

    运行插桩测试并提供设备恢复功能。

    如果在测试运行完成之前与设备的连接中断,并且恢复成功,系统将通知所有监听器 testRunFailed,并返回“false”。该测试命令不会重新运行。由调用方在必要时重试。

    如果在测试运行完成之前与设备的连接断开,并且恢复失败,则所有监听器都将获知 testRunFailed 并抛出 DeviceNotAvailableException。

    参数
    runner IRemoteAndroidTestRunner:用于运行测试的 IRemoteAndroidTestRunner

    listeners :测试结果监听器

    返回
    boolean 如果测试命令已完成,则为 true。如果因设备通信异常而未能完成,则为 false,但恢复成功了

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。例如,测试命令未完成且恢复失败。

    runInstrumentationTestsAsUser

    public abstract boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, 
                    int userId, 
                     listeners)

    ERROR(ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)/com.android.tradefed.device.ITestDevice#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection) ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)) 相同,但会针对指定用户运行测试。

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners

    返回
    boolean

    抛出
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

    public abstract boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, 
                    int userId, 
                    ITestLifeCycleReceiver... listeners)

    ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...) 相同,但会针对指定用户运行测试。

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    返回
    boolean

    抛出
    DeviceNotAvailableException

    setDate

    public abstract void setDate (Date date)

    设置设备上的日期

    注意:在设备上设置日期需要 root 权限

    参数
    date Date:指定特定日期;如果 null,将使用托管日期

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setOptions

    public abstract void setOptions (TestDeviceOptions options)

    为设备设置 TestDeviceOptions

    参数
    options TestDeviceOptions

    setProperty

    public abstract boolean setProperty (String propKey, 
                    String propValue)

    在设备上设置给定的属性值。需要 adb root 为 true。

    参数
    propKey String:要设置的键。

    propValue String:要设置的属性值。

    返回
    boolean 如果 setprop 命令成功,则返回 True,否则返回 False。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setRecovery

    public abstract void setRecovery (IDeviceRecovery recovery)

    设置要用于此设备的 IDeviceRecovery。应在首次分配设备时设置。

    参数
    recovery IDeviceRecoveryIDeviceRecovery

    setRecoveryMode

    public abstract void setRecoveryMode (ITestDevice.RecoveryMode mode)

    设置要用于设备的当前恢复模式。

    用于控制遇到设备通信问题时要使用的恢复方法。建议仅在需要时(例如,框架出现故障等)时谨慎使用此方法

    参数
    mode ITestDevice.RecoveryMode:是否开启“仅恢复在线状态”模式。

    setUseFastbootErase

    public abstract void setUseFastbootErase (boolean useFastbootErase)

    设置是使用 fastboot 清空还是使用 fastboot 格式擦除设备上的分区。

    参数
    useFastbootErase boolean:如果应该使用 fastboot 清空,则为 true;如果应使用 fastboot 格式,则为 false

    启动 Logcat

    public abstract void startLogcat ()

    开始在后台捕获设备的 logcat 输出。

    如果已捕获 logcat 输出,则不会产生任何影响。 您稍后可以通过 getLogcat 检索数据。

    当设备不再使用时,必须调用 stopLogcat()

    在 TF 调用上下文中,通常不需要调用 startLogcat()stopLogcat(),因为 TF 框架会启动和停止 logcat。

    stopEmulatorOutput

    public abstract void stopEmulatorOutput ()

    关闭并删除模拟器输出。

    停止 Logcat

    public abstract void stopLogcat ()

    停止从设备捕获 logcat 输出,并舍弃当前保存的 logcat 数据。

    如果未捕获 logcat 输出,则不会产生任何影响。

    switchToAdbTcp

    public abstract String switchToAdbTcp ()

    将设备切换到 adb-over-tcp 模式。

    返回
    String TCP 序列号或 null(如果设备无法切换)

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    switchToAdbUsb

    public abstract boolean switchToAdbUsb ()

    通过 USB 模式将设备切换到 adb。

    返回
    boolean 如果切换成功,则为 true,否则为 false

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    syncFiles

    public abstract boolean syncFiles (File localFileDir, 
                    String deviceFilePath)

    将本地文件目录的内容逐步同步到设备。

    通过比较本地文件的时间戳与其远程等效文件的时间戳,确定要推送的文件。系统只会将“更新”或不存在的文件推送到设备。因此,如果在设备上设置的文件已经是最新的,开销应该相对较小。

    系统会忽略隐藏文件(名称以“.”开头的文件)。

    用法示例:syncFiles("/tmp/files", "/sdcard") 会创建一个 /sdcard/files 目录(如果尚不存在),并以递归方式将 /tmp/files 内容推送到 /sdcard/files。

    参数
    localFileDir File:包含要以递归方式推送的文件的本地文件目录。

    deviceFilePath String:远程目标的绝对文件路径根目录。该文件路径中的所有目录都必须是可读的。例如,如果 adb 不是 root 权限,则推送到 /data/local/tmp 将会失败

    返回
    boolean 如果文件已成功同步,则返回 true。否则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    解锁设备

    public abstract boolean unlockDevice ()

    如果设备处于加密状态,则将其解锁。

    此方法可能会重启框架,但不会调用 postBootSetup()。因此,在此方法返回时,设备可能还没有完全准备好接受测试。

    返回
    boolean 如果成功或设备未加密,则为 true

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。
    UnsupportedOperationException

    unmountDebugfs

    public abstract void unmountDebugfs ()

    卸载 debugfs。

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    waitForBootComplete

    public abstract boolean waitForBootComplete (long timeOut)

    阻止,直到设置了设备的启动完成标志。

    参数
    timeOut long:等待标志设置的时间(以毫秒为单位)

    返回
    boolean 如果在超时时限内设置了设备的启动完成标志,则为 true

    抛出
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable ()

    等待设备做出响应并可供测试。使用默认超时。

    返回
    boolean 如果设备可用,则为 true;如果恢复功能已停用且不可用,则为 false。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable (long waitTime)

    等待设备做出响应并可供测试。

    参数
    waitTime long:等待的时间(以毫秒为单位)

    返回
    boolean 如果设备可用,则为 true;如果恢复功能已停用且不可用,则为 false。

    抛出
    DeviceNotAvailableException 如果设备在 waitTime 后仍然无响应,则会发生该错误。

    waitForDeviceAvailableInRecoverPath

    public abstract boolean waitForDeviceAvailableInRecoverPath (long waitTime)

    等待设备响应且可用,而不考虑恢复路径。

    参数
    waitTime long

    返回
    boolean 如果设备可用,则为 true;如果不可用,则为 false。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    waitForDeviceBootloader

    public abstract void waitForDeviceBootloader ()

    屏蔽,直到设备通过 fastboot 显示。使用默认超时。

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    等待设备恢复

    public abstract boolean waitForDeviceInRecovery (long waitTime)

    使设备处于“adb recovery”状态的块(请注意,这与 IDeviceRecovery 不同)。

    参数
    waitTime long:等待的时间(以毫秒为单位)

    返回
    boolean 如果设备在时间到期之前启动到恢复模式,则为 true。否则为 false

    waitForDeviceInSideload

    public abstract boolean waitForDeviceInSideload (long waitTime)

    阻止设备处于“adb 旁加载”状态的块

    参数
    waitTime long:等待的时间(以毫秒为单位)

    返回
    boolean 如果设备在时间到期之前启动到旁加载,则为 true。否则为 false

    waitForDeviceNotAvailable

    public abstract boolean waitForDeviceNotAvailable (long waitTime)

    导致设备不可用(即 adb 中缺失)的块

    参数
    waitTime long:等待的时间(以毫秒为单位)

    返回
    boolean 如果设备在时间到期之前变为不可用状态,则为 true。 否则为 false

    等待设备在线

    public abstract void waitForDeviceOnline ()

    屏蔽,直到设备通过 adb 可见。使用默认超时

    请注意,设备未必能在完成后对命令做出响应。请改用 waitForDeviceAvailable()

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    等待设备在线

    public abstract void waitForDeviceOnline (long waitTime)

    屏蔽,直到设备通过 adb 可见。

    请注意,设备未必能在完成后对命令做出响应。请改用 waitForDeviceAvailable()

    参数
    waitTime long:等待的时间(以毫秒为单位)

    抛出
    DeviceNotAvailableException 如果与设备的连接已断开且无法恢复。

    waitForDeviceShell

    public abstract boolean waitForDeviceShell (long waitTime)

    等待设备响应基本 adb shell 命令。

    参数
    waitTime long:等待的时间(以毫秒为单位)

    返回
    boolean 如果设备在 waitTime 期间开始响应,则为 true