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)

一种辅助方法,用于检查设备自 UTC 时间(从 Epoch 起算)之后是否软重启 设备及其 ERROR(/TimeUnit)

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)

一种辅助方法,用于通过 system 将长时间运行的 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()

返回 Tradefed API 自纪元以来上次触发重新启动的时间(以毫秒为单位),如下所示: 由 System.currentTimeMillis() 返回。

abstract int getLaunchApiLevel()

获取设备首次发布的 API 级别。

abstract InputStreamSource getLogcat()

获取 logcat 数据的快照流。

abstract InputStreamSource getLogcat(int maxBytes)

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

abstract InputStreamSource getLogcatDump()

获取设备当前 logcat 的转储。

abstract InputStreamSource getLogcatSince(long date)

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

abstract String getMountPoint(String mountName)

返回装载点。

abstract ITestDevice.MountPointInfo getMountPointInfo(String mountpoint)

返回与指定装载点路径对应的 MountPointInfo,或 null(如果该路径未装载任何内容或未出现在该路径中) /proc/mounts 作为装载点。

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

default String getTrackingSerial()

出于设备管理目的,请获取用于跟踪设备的序列号。

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) 的变体,可视需要考虑评估需求 。

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 setTrackingSerial(String trackingSerial)

出于设备管理目的,请跟踪我们用于引用设备的序列号。

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)

一种辅助方法,用于检查设备自 UTC 时间(从 Epoch 起算)之后是否软重启 设备及其 ERROR(/TimeUnit)。软重启是指 system_server 在 设备硬重启(例如:请求重新启动)。当前设备 utcEpochTime 为 可以通过 getDeviceDate() 方法获取 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:表示设备处于无响应状态之前经过的时间(以毫秒为单位);对于 无超时

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:表示设备处于无响应状态之前经过的时间(以毫秒为单位);对于 无超时

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)

一种辅助方法,用于通过 system 将长时间运行的 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 无线装置的版本。 要点 与 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",则为 true"on";如果属性的值为 "0",则为 "true"false"n""no""off""false"defaultValue 否则。

抛出
DeviceNotAvailableException

getBootHistory

public abstract  getBootHistory ()

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

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

抛出
DeviceNotAvailableException

getBootHistorySince

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

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

参数
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 如果设备处于错误状态或处于 无响应。

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

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

getFastbootProductVariant

public abstract String getFastbootProductVariant ()

在 fastboot 模式下获取此设备的产品类型的便捷方法。

只有在设备应处于 fastboot 模式时,才应使用此方法。它的变体更安全 与在本例中使用通用 getProductType() 方法相比,因为 ITestDevice 如果设备处于错误状态或处于 无响应。

返回
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 的引用。

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

返回
IDevice IDevice

getIntProperty

public abstract long getIntProperty (String name, 
                long defaultValue)

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

参数
name String:属性名称

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

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

抛出
DeviceNotAvailableException

getLastexpectedRebootTimeMillis

public abstract long getLastExpectedRebootTimeMillis ()

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

    返回
    InputStreamSource

  • 获取 Logcat

    public abstract InputStreamSource getLogcat (int maxBytes)

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

    在您想要捕获已捕获 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,或 null(如果该路径未装载任何内容或未出现在该路径中) /proc/mounts 作为装载点。

    参数
    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

    getTrackingSerial

    public String getTrackingSerial ()

    出于设备管理目的,请获取用于跟踪设备的序列号。

    返回
    String

    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,则为 truefalse 否则。

    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 update 命令已完成)

    抛出
    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) 的变体,可视需要考虑评估需求 。

    参数
    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 如果与设备的连接已断开且无法连接 已恢复。

    重新启动

    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 如果测试命令已完成,则为 truefalse(如果未能更新) 已完成,但恢复成功

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

    runInstrumentationTest

    public abstract boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

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

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

    如果在测试运行完成之前与设备的连接断开,并且恢复失败, 系统会向监听器告知 testRunFailed,并抛出 DeviceNotAvailableException。

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

    listeners :测试结果监听器

    返回
    boolean 如果测试命令已完成,则为 truefalse(如果未能更新) 因设备通信异常而完成,但恢复成功

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

    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:是否“仅恢复至在线状态”模式。

    setTrackingSerial

    public abstract void setTrackingSerial (String trackingSerial)

    出于设备管理目的,请跟踪我们用于引用设备的序列号。

    参数
    trackingSerial String

    setUseFastbootErase

    public abstract void setUseFastbootErase (boolean useFastbootErase)

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

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

    启动 Logcat

    public abstract void startLogcat ()

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

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

    当设备不再处于使用状态时,必须调用 stopLogcat()

    在以下情况下,通常不需要调用 startLogcat()stopLogcat(): 在 TF 调用上下文中运行,因为 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