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 executeAdbV2Command(long timeout, envMap, String... commandArgs)

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

abstract CommandResult executeAdbV2Command(String... commandArgs)

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

abstract CommandResult executeAdbV2Command(long timeout, 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 返回的辅助方法,该 CommandResult 已正确填充命令状态输出、标准输出和标准错误。

abstract CommandResult executeShellV2Command(String command, OutputStream pipeToOutput)

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

abstract CommandResult executeShellV2Command(String command, File pipeAsInput)

用于执行 adb shell 命令并将结果作为 CommandResult 返回的辅助方法,该 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)

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

abstract InputStreamSource getLogcatDump()

获取设备的当前 logcat 的 dump。

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) 的变体,可以选择性地考虑评估内容提供方的需求。

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

使设备上的 system 分区可写入。

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 boolean startTradeInModeTesting(int timeoutMs)

启用测试以旧换新模式。

abstract void stopEmulatorOutput()

关闭并删除模拟器输出。

abstract void stopLogcat()

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

abstract void stopTradeInModeTesting()

停止测试以旧换新模式。

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 sideload”状态

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) 以来是否已软重启。软重启是指在设备硬重启(例如:请求的重启)之外重新启动 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 命令的 stdout。如果命令执行失败,则为 null

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

executeAdbCommand

public abstract String executeAdbCommand (String... commandArgs)

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

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

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

返回
String 命令的 stdout。如果命令执行失败,则为 null

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

executeAdbCommand

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

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

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

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

envMap :要为命令设置的环境

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

返回
String 命令的 stdout。如果命令执行失败,则为 null

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

executeAdbV2Command

public abstract CommandResult executeAdbV2Command (long timeout, 
                 envMap, 
                String... commandArgs)

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

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

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

envMap :要为命令设置的环境

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

返回
CommandResult 包含命令输出的 CommandResult。

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

executeAdbV2Command

public abstract CommandResult executeAdbV2Command (String... commandArgs)

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

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

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

返回
CommandResult 包含命令输出的 CommandResult。

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

executeAdbV2Command

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

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

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

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

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

返回
CommandResult 包含命令输出的 CommandResult。

抛出
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 返回的辅助方法,该 CommandResult 已正确填充命令状态输出、stdout 和 stderr。

参数
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 返回的辅助方法,该 CommandResult 已正确填充命令状态输出、stdout 和 stderr。

参数
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 format 在设备上创建新的文件系统。

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

参数
partition String:要擦除的分区

返回
CommandResult 包含命令输出的 CommandResult

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

getApiLevel

public abstract int getApiLevel ()

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

返回
int 一个用于指示设备 API 级别的整数

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

getBasebandVersion

public abstract String getBasebandVersion ()

用于获取相应设备的基带(无线电)版本的便捷方法。获取无线装置版本是特定于设备的,因此可能无法返回所有设备的正确信息。此方法依赖于 gsm.version.baseband 属性来返回正确的版本信息。对于某些 CDMA 设备,此值并不准确,此处返回的版本可能与通过 fastboot 报告的版本不一致,并且可能不会返回 CDMA 无线装置的版本。 简而言之,只有当 gsm.version.baseband 属性与 fastboot getvar version-baseband 返回的版本相同时,此方法才会报告准确的版本。

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

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

getBattery

public abstract Integer getBattery ()

返回设备的当前电池电量;如果电池电量不可用,则返回 Null。

返回
Integer

getBooleanProperty

public abstract boolean getBooleanProperty (String name, 
                boolean defaultValue)

返回指定属性的布尔值。

参数
name String:属性名称

defaultValue boolean:如果属性为空或不存在,则返回的默认值。

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

抛出
DeviceNotAvailableException

getBootHistory

public abstract  getBootHistory ()

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

返回
启动时间(自纪元以来的世界协调时间,以秒为单位)和启动原因的映射

抛出
DeviceNotAvailableException

getBootHistorySince

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

timeUnit TimeUnit:时间单位 TimeUnit

返回
启动时间(自纪元以来的世界协调时间,以秒为单位)和启动原因的映射

抛出
DeviceNotAvailableException

getBootloaderVersion

public abstract String getBootloaderVersion ()

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

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

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

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

getBuildAlias

public abstract String getBuildAlias ()

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

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

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

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

getBuildFlavor

public abstract String getBuildFlavor ()

检索设备的 build 版本。

返回
String build flavor;如果无法检索,则为 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 的替代方案,有时由于权限问题,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 会知道在设备处于错误状态或无响应时将设备恢复到 fastboot。

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

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

getFastbootProductVariant

public abstract String getFastbootProductVariant ()

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

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

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

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

getFastbootSerialNumber

public abstract String getFastbootSerialNumber ()

返回 fastboot 模式序列号。

返回
String

getFastbootVariable

public abstract String getFastbootVariable (String variableName)

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

参数
variableName String:变量名称

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

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

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

    返回
    InputStreamSource

  • getLogcat

    public abstract InputStreamSource getLogcat (int maxBytes)

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

    适用于以下情况:您希望频繁捕获所捕获 logcat 数据的快照,但不想因获取整个 getLogcat() 快照而导致磁盘空间可能大幅减少。

    参数
    maxBytes int:要返回的数据量上限。应为可轻松容纳在内存中的量

    返回
    InputStreamSource

    getLogcatDump

    public abstract InputStreamSource getLogcatDump ()

    获取设备的当前 logcat 的 dump。与 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 中的缓存信息不可用,则直接查询设备。

    待办事项:将此行为移至 IDevice.getMountPoint(String)

    参数
    mountName String:挂载点的名称

    返回
    String 装载点或 null

    getMountPointInfo

    public abstract ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    返回与指定挂载点路径对应的 MountPointInfo;如果该路径未挂载任何内容,或者未以挂载点形式出现在 /proc/mounts 中,则返回 null

    参数
    mountpoint String

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

    抛出
    DeviceNotAvailableException

    getMountPointInfo

    public abstract  getMountPointInfo ()

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

    返回
    一个 ERROR(/List)MountPointInfo,其中包含“/proc/mounts”中的信息

    抛出
    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 会提前终止方法。

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

    抛出
    DeviceNotAvailableException

    另见:

    getTotalMemory

    public abstract long getTotalMemory ()

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

    返回
    long

    getTrackingSerial

    public String getTrackingSerial ()

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

    返回
    String

    getUseFastbootErase

    public abstract boolean getUseFastbootErase ()

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

    返回
    boolean 如果将使用 fastboot erase,则为 true;如果将使用 fastboot format,则为 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 如果已装载 debugfs,则为 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 ()

    执行相关说明,将设备配置为在每次启动后进行测试。

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

    在正常情况下,无需显式调用此方法,因为实现应在执行重新启动时自动执行这些步骤。

    在设备因其他事件(例如快速启动更新命令已完成)而重新启动时,可能需要调用此方法

    抛出
    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:是否检查是否需要内容提供程序

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

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

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

    remountVendorReadOnly

    public abstract void remountVendorReadOnly ()

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

    抛出
    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 如果测试命令已完成,则为 true。如果因设备通信异常而未能完成,但恢复成功,则为 false

    抛出
    DeviceNotAvailableException 如果与设备的连接丢失且无法恢复,即测试命令未能完成且恢复失败。

    runInstrumentationTestsAsUser

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

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

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners

    返回
    boolean

    抛出
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

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

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

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    返回
    boolean

    抛出
    DeviceNotAvailableException

    setDate

    public abstract void setDate (Date date)

    设置设备上的日期

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

    参数
    date Date:指定特定日期;如果为 null,则使用主机日期

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

    setOptions

    public abstract void setOptions (TestDeviceOptions options)

    为设备设置 TestDeviceOptions

    参数
    options TestDeviceOptions

    setProperty

    public abstract boolean setProperty (String propKey, 
                    String propValue)

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

    参数
    propKey String:要设置的目标键。

    propValue String:要设置的属性值。

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

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

    setRecovery

    public abstract void setRecovery (IDeviceRecovery recovery)

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

    参数
    recovery IDeviceRecoveryIDeviceRecovery

    setRecoveryMode

    public abstract void setRecoveryMode (ITestDevice.RecoveryMode mode)

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

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

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

    setTrackingSerial

    public abstract void setTrackingSerial (String trackingSerial)

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

    参数
    trackingSerial String

    setUseFastbootErase

    public abstract void setUseFastbootErase (boolean useFastbootErase)

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

    参数
    useFastbootErase boolean:如果应使用 fastboot erase,则为 true;如果应使用 fastboot format,则为 false

    startLogcat

    public abstract void startLogcat ()

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

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

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

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

    startTradeInModeTesting

    public abstract boolean startTradeInModeTesting (int timeoutMs)

    启用以旧换新测试模式。设备将被擦除并重新启动。

    参数
    timeoutMs int

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

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

    stopEmulatorOutput

    public abstract void stopEmulatorOutput ()

    关闭并删除模拟器输出。

    stopLogcat

    public abstract void stopLogcat ()

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

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

    stopTradeInModeTesting

    public abstract void stopTradeInModeTesting ()

    停止测试以旧换新模式。设备将会重启。

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

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

    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