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 时间起是否已软重启的辅助方法。

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 返回,其中包含已正确填充的命令状态输出、标准输出和标准错误输出。

abstract CommandResult executeShellV2Command(String command, OutputStream pipeToOutput)

辅助方法,用于执行 adb shell 命令,并将结果作为 CommandResult 返回,其中包含正确填充的命令状态输出和 stderr。

abstract CommandResult executeShellV2Command(String command, File pipeAsInput)

辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult 返回,其中包含已正确填充的命令状态输出、标准输出和标准错误输出。

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()

返回设备的日期(以自公元纪年起算的毫秒数表示)。

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)

抓取所捕获 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”命令,并返回包含给定进程的 PID 和进程启动时间的 ProcessInfo 对象。

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()

从设备提取并返回墓碑列表。

abstract long getTotalMemory()

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

default String getTrackingSerial()

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

abstract boolean getUseFastbootErase()

获取是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。

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)

将设备重新启动到 adb 模式,并提供要跨重新启动保留的给定 reason

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()

将设备上的供应商分区设为只读。

abstract void remountVendorWritable()

将设备上的供应商分区设为可写入。

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 erase 还是 fastboot format 来擦除设备上的分区。

abstract void startLogcat()

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

abstract void stopEmulatorOutput()

关闭并删除模拟器输出。

abstract void stopLogcat()

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

abstract String switchToAdbTcp()

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

abstract boolean switchToAdbUsb()

将设备切换到 adb over usb 模式。

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 命令。

常量

UNKNOWN_API_LEVEL

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

deviceSoftRestarted

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

deviceSoftRestartedSince

public abstract boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

用于检查设备自从设备及其 ERROR(/TimeUnit) 的纪元以来的 UTC 时间以来是否已软重启的辅助方法。软重启是指在设备硬重启之外重启 system_server(例如:请求重启)。您可以通过 getDeviceDate() 方法获取当前设备的 utcEpochTime(以毫秒为单位)。

参数
utcEpochTime long:设备时间(自公元纪年起算,以秒为单位)。

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

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

抛出
RuntimeException 设备是否存在异常启动原因
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

disableAdbRoot

public abstract boolean disableAdbRoot ()

关闭 adb root。

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

返回
boolean 如果成功,则为 true

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

doesFileExist

public abstract boolean doesFileExist (String deviceFilePath)

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

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

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

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

enableAdbRoot

public abstract boolean enableAdbRoot ()

开启 adb root。如果“enable-root”设置为“false”,则会记录消息并返回,而不会启用 root。

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

返回
boolean 如果成功,则为 true

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

executeAdbCommand

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

辅助方法,用于将 adb 命令作为系统命令以指定的超时执行。

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

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

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

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

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

executeAdbCommand

public abstract String executeAdbCommand (String... commandArgs)

将 adb 命令作为系统命令执行的辅助方法。

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

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

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

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

executeAdbCommand

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

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command)

辅助方法,用于执行 adb shell 命令,并将结果作为 CommandResult 返回,其中包含已正确填充的命令状态输出、标准输出和标准错误输出。

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

返回
CommandResult CommandResult 中的结果。

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

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                OutputStream pipeToOutput)

辅助方法,用于执行 adb shell 命令,并将结果作为 CommandResult 返回,其中包含已正确填充的命令状态输出和 stderr。stdout 会定向到指定的流。

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

pipeToOutput OutputStream:将重定向标准输出的 ERROR(/OutputStream),或 null。

返回
CommandResult CommandResult 中的结果。

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

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput)

辅助方法,用于执行 adb shell 命令并将结果作为 CommandResult 返回,其中包含已正确填充的命令状态输出、标准输出和标准错误输出。

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

pipeAsInput File:将作为输入管道传递给命令的 ERROR(/File),或 null。

返回
CommandResult CommandResult 中的结果。

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

executeShellV2Command

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

executeShellV2Command

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

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

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

maxTimeoutForCommand long:命令完成的超时上限;单位为 timeUnit 中指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

返回
CommandResult

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

executeShellV2Command

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 OutputStream:要将标准输出重定向到的 ERROR(/OutputStream),或 null。

maxTimeoutForCommand long:命令完成的超时上限;单位为 timeUnit 中指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

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

返回
CommandResult

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

executeShellV2Command

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 OutputStream:要将标准输出重定向到的 ERROR(/OutputStream),或 null。

pipeToError OutputStream:要将标准错误重定向到的 ERROR(/OutputStream),或 null。

maxTimeoutForCommand long:命令完成的超时上限;单位为 timeUnit 中指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

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

返回
CommandResult

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

fastbootWipePartition

public abstract CommandResult fastbootWipePartition (String partition)

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

如果 getUseFastbootErase()true,则系统会使用 fastboot erase 擦除分区。然后,设备必须在下次启动时创建文件系统。否则,系统会使用 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;否则为 true

抛出
DeviceNotAvailableException

getBootHistory

public abstract  getBootHistory ()

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

返回
启动时间(自公元纪年起算的世界协调时间,以秒为单位)与启动原因的映射

抛出
DeviceNotAvailableException

getBootHistorySince

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

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

参数
utcEpochTime long:自公元纪年以来的设备时间。

timeUnit TimeUnit:时间单位 TimeUnit

返回
启动时间(自公元纪年起算的世界协调时间,以秒为单位)与启动原因的映射

抛出
DeviceNotAvailableException

getBootloaderVersion

public abstract String getBootloaderVersion ()

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

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

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

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

getBuildAlias

public abstract String getBuildAlias ()

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

与 build ID(对于 Nexus build 通常为数字)相比,build 别名通常更易于阅读。例如,最终的 Android 4.2 版本具有 build 别名 JDQ39 和 build ID 573038

返回
String build 别名,如果无法检索到 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 ()

返回设备的日期(以从纪元算起的毫秒数为单位)。

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

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

getDeviceDescriptor

public abstract DeviceDescriptor getDeviceDescriptor ()

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

返回
DeviceDescriptor

getDeviceDescriptor

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

抛出
UnsupportedOperationException
DeviceNotAvailableException

getFileEntry

public abstract IFileEntry getFileEntry (String path)

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

参数
path String:要检索的文件路径。可以是绝对路径,也可以是相对于“/”的路径。即,系统支持“/system”和“system”语法

返回
IFileEntry 如果找不到给定 path 中的文件,则为 IFileEntrynull

抛出
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 ()

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

返回
long

getLaunchApiLevel

public abstract int getLaunchApiLevel ()

获取设备的首次启动 API 级别。默认为 UNKNOWN_API_LEVEL

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

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

getLogcat

public abstract InputStreamSource getLogcat ()

抓取 Logcat 数据的快照流。

可在两种模式下运行:

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

    返回
    InputStreamSource

  • getLogcat

    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 数据,则返回空串流。

    getLogcatSince

    public abstract InputStreamSource getLogcatSince (long date)

    从所提供的日期开始抓取捕获的 Logcat 数据的快照流。应使用设备上的时区 getDeviceDate()

    参数
    date long:以自纪元以来的毫秒数表示,从开始截取快照到当前时间。 (可使用“date +%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 中信息的解析版本

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

    抛出
    DeviceNotAvailableException

    getPartitionFreeSpace

    public abstract long getPartitionFreeSpace (String partition)

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

    参数
    partition String

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

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

    getProcessByName

    public abstract ProcessInfo getProcessByName (String processName)

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

    参数
    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 序列号

    getTombstones

    public abstract  getTombstones ()

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

    方法是尽力而为的,因此如果因任何原因而无法拉取某个墓碑,该墓碑将不会出现在列表中。只有 DeviceNotAvailableException 会提前终止该方法。

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

    抛出
    DeviceNotAvailableException

    另见:

    getTotalMemory

    public abstract long getTotalMemory ()

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

    返回
    long

    getTrackingSerial

    public String getTrackingSerial ()

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

    返回
    String

    getUseFastbootErase

    public abstract boolean getUseFastbootErase ()

    获取是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。

    返回
    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

    isDebugfsMounted

    public abstract boolean isDebugfsMounted ()

    检查 debugfs 是否已挂载。

    返回
    boolean true(如果已挂载调试文件系统)

    抛出
    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

    isExecutable

    public abstract boolean isExecutable (String fullPath)

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

    参数
    fullPath String

    返回
    boolean

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

    isHeadless

    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

    logOnDevice

    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

    nonBlockingReboot

    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

    pullFileFromExternal

    public abstract File pullFileFromExternal (String remoteFilePath)

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

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

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

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

    pushDir

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

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

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

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

    userId int:要推送到的用户 ID

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

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

    pushDir

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

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

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

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

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

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

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

    pushDir

    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:要推送到的 userId

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

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

    pushString

    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)

    将设备重新启动到 adb 模式,并提供要跨重新启动保留的给定 reason

    阻塞,直到设备可用。

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

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

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

    rebootIntoBootloader

    public abstract void rebootIntoBootloader ()

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

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

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

    rebootIntoFastbootd

    public abstract void rebootIntoFastbootd ()

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

    会阻塞,直到设备进入 fastbootd 模式。

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

    rebootIntoRecovery

    public abstract void rebootIntoRecovery ()

    将设备重新启动为 adb 恢复模式。

    阻塞,直到设备进入恢复模式

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

    rebootIntoSideload

    public abstract void rebootIntoSideload (boolean autoReboot)

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

    阻塞,直到设备进入旁加载模式

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

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

    rebootIntoSideload

    public abstract void rebootIntoSideload ()

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

    阻塞,直到设备进入旁加载模式

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

    rebootUntilOnline

    public abstract void rebootUntilOnline ()

    reboot() 的替代方案,仅会阻塞到设备处于在线状态(即对 adb 可见)为止。

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

    rebootUntilOnline

    public abstract void rebootUntilOnline (String reason)

    reboot() 的替代方案,仅会阻塞到设备处于在线状态(即对 adb 可见)为止。

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

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

    另见:

    rebootUserspace

    public abstract void rebootUserspace ()

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

    阻塞,直到设备可用。

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

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

    rebootUserspaceUntilOnline

    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

    remountVendorReadOnly

    public abstract void remountVendorReadOnly ()

    将设备上的供应商分区设为只读。可能会重启设备。

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

    remountVendorWritable

    public abstract void remountVendorWritable ()

    将设备上的供应商分区设为可写入。可能会重启设备。

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

    runInstrumentationTests

    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 如果与设备的连接中断且无法恢复。例如,测试命令未能完成且恢复失败。

    runInstrumentationTests

    public abstract boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

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

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

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

    参数
    runner IRemoteAndroidTestRunner:运行测试的 IRemoteAndroidTestRunner

    listeners :测试结果监听器

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

    抛出
    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)

    在设备上设置给定属性值。Requires 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 erase 还是 fastboot format 来擦除设备上的分区。

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

    startLogcat

    public abstract void startLogcat ()

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

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

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

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

    stopEmulatorOutput

    public abstract void stopEmulatorOutput ()

    关闭并删除模拟器输出。

    stopLogcat

    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 ()

    将设备切换到 adb over usb 模式。

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

    unlockDevice

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

    waitForDeviceInRecovery

    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

    waitForDeviceOnline

    public abstract void waitForDeviceOnline ()

    阻塞,直到设备可通过 adb 看到。使用默认超时时间

    请注意,设备在完成后不一定会响应命令。请改用 waitForDeviceAvailable()

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

    waitForDeviceOnline

    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