原生设备

public class NativeDevice
extends Object implements IManagedTestDevice, IConfigurationReceiver, ITestLoggerReceiver

java.lang.Object
   ↳ com.android.tradefed.device.NativeDevice


ITestDevice 非全栈 Android 设备的默认实现。

摘要

嵌套类

class NativeDevice.AdbAction

用于运行操作系统“adb ....”命令的 ERROR(DeviceAction/com.android.tradefed.device.NativeDevice.DeviceAction DeviceAction)。 

class NativeDevice.AdbShellAction

 

class NativeDevice.RebootDeviceAction

ERROR(DeviceAction/com.android.tradefed.device.NativeDevice.DeviceAction DeviceAction)(用于重新启动设备)。 

常量

int INVALID_USER_ID

针对任何无效/未找到的用户 ID 返回的值:UserHandle 定义了 -10000 值

long MAX_HOST_DEVICE_TIME_OFFSET

int MAX_RETRY_ATTEMPTS

尝试执行命令的默认重试次数

字段

public static final String DEBUGFS_PATH

protected static final String SD_CARD

protected static final String STORAGE_EMULATED

protected TestDeviceOptions mOptions

protected final IDeviceStateMonitor mStateMonitor

公共构造函数

NativeDevice(IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)

创建 TestDevice

公共方法

void batchPrefetchStartupBuildProps()

通过预取我们需要的所有属性(而不是为每个属性调用“adb getprop”)进行微优化(大约 400 毫秒)。

boolean canSwitchToHeadlessSystemUser()

返回是否允许切换到无头 SYSTEM 用户。

boolean checkApiLevelAgainstNextRelease(int strictMinLevel)

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

boolean checkConnectivity()

检查设备是否已连接到网络。

boolean clearErrorDialogs()

尝试关闭设备界面上当前显示的所有错误对话框。

void clearLastConnectedWifiNetwork()

清除上次连接的 Wi-Fi 网络。

void clearLogcat()

删除任何累积的 logcat 数据。

boolean connectToWifiNetwork( wifiSsidToPsk, boolean scanSsid)

连接到 Wi-Fi 网络。

boolean connectToWifiNetwork(String wifiSsid, String wifiPsk)

连接到 Wi-Fi 网络。

boolean connectToWifiNetwork( wifiSsidToPsk)

连接到 WLAN 网络。f

boolean connectToWifiNetwork(String wifiSsid, String wifiPsk, boolean scanSsid)

连接到 Wi-Fi 网络。

boolean connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk, boolean scanSsid)

connectToWifiNetwork(String, String) 的变体,仅在设备当前没有网络连接时才进行连接。

boolean connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk)

connectToWifiNetwork(String, String) 的变体,仅在设备当前没有网络连接时才进行连接。

int createUser(String name, boolean guest, boolean ephemeral)

使用给定名称和提供的标志创建用户

int createUser(String name, boolean guest, boolean ephemeral, boolean forTesting)

使用给定名称和提供的标志创建用户

int createUser(String name)

创建具有给定名称和默认标志 0 的用户。

int createUserNoThrow(String name)

创建具有给定名称和默认标志 0 的用户。

void deleteFile(String deviceFilePath, int userId)

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

void deleteFile(String deviceFilePath)

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

void deregisterDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)

移除已注册的 IDeviceActionReceiver

boolean deviceSoftRestarted(ProcessInfo prevSystemServerProcess)

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

boolean deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)

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

boolean disableAdbRoot()

关闭 adb root 命令。

void disableKeyguard()

尝试停用键盘锁。

boolean disableNetworkMonitor()

停用设备上的网络监控功能。

boolean disconnectFromWifi()

断开与 Wi-Fi 网络的连接。

boolean doesFileExist(String deviceFilePath, int userId)

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

boolean doesFileExist(String deviceFilePath)

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

File dumpHeap(String process, String devicePath)

尝试从 system_server 转储堆。

boolean enableAdbRoot()

开启 adb root 命令。

boolean enableNetworkMonitor()

在设备上启用网络监控功能。

String executeAdbCommand(long timeout, String... cmdArgs)

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

String executeAdbCommand(long timeout, envMap, String... cmdArgs)

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

String executeAdbCommand(String... cmdArgs)

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

CommandResult executeFastbootCommand(String... cmdArgs)

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

CommandResult executeFastbootCommand(long timeout, String... cmdArgs)

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

CommandResult executeLongFastbootCommand(String... cmdArgs)

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

CommandResult executeLongFastbootCommand( envVarMap, String... cmdArgs)

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

String executeShellCommand(String command)

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

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

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

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

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

void executeShellCommand(String command, IShellOutputReceiver receiver)

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

CommandResult executeShellV2Command(String cmd)

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

CommandResult executeShellV2Command(String cmd, OutputStream pipeToOutput)

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

CommandResult executeShellV2Command(String cmd, File pipeAsInput)

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

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

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

CommandResult executeShellV2Command(String cmd, long maxTimeoutForCommand, TimeUnit timeUnit)

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

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

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

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

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

CommandResult fastbootWipePartition(String partition)

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

getActiveApexes()

提取设备上已激活的 APEX 的相关信息。

getAllSettings(String namespace)

返回所请求命名空间的键值对。

DeviceAllocationState getAllocationState()

返回设备的当前分配状态

String getAndroidId(int userId)

查找并返回与 userId 关联的 android-id;如果未找到,则返回 null。

getAndroidIds()

创建一个映射,将找到的 Android ID 与用户 ID 匹配。

int getApiLevel()

获取设备 API 级别。

PackageInfo getAppPackageInfo(String packageName)

提取设备上安装的软件包的相关信息。

getAppPackageInfos()

提取设备上安装的软件包的相关信息。

String getBasebandVersion()

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

Integer getBattery()

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

boolean getBooleanProperty(String name, boolean defaultValue)

返回指定属性的布尔值。

getBootHistory()

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

getBootHistorySince(long utcEpochTime, TimeUnit timeUnit)

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

String getBootloaderVersion()

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

InputStreamSource getBugreport()

从设备中检索 bug 报告。

InputStreamSource getBugreportz()

从设备中检索 bugreportz。

String getBuildAlias()

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

String getBuildFlavor()

检索设备的 build 变种。

String getBuildId()

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

String getBuildSigningKeys()

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

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

DeviceDescriptor getCachedDeviceDescriptor()

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

DeviceDescriptor getCachedDeviceDescriptor(boolean shortDescriptor)

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

String[] getChildren(String path)

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

AbstractConnection getConnection()

与设备关联的当前连接。

ContentProviderHandler getContentProvider(int userId)

返回 ContentProviderHandler;如果不可用,则返回 null。

DeviceFoldableState getCurrentFoldableState()

返回设备当前的可折叠状态;如果发生某些问题,则返回 null。

int getCurrentUser()

返回当前正在运行的用户的 ID。

String getDeviceClass()

获取设备类。

long getDeviceDate()

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

DeviceDescriptor getDeviceDescriptor()

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

DeviceDescriptor getDeviceDescriptor(boolean shortDescriptor)

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

TestDeviceState getDeviceState()

获取设备的状态。

long getDeviceTimeOffset(Date date)

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

InputStreamSource getEmulatorOutput()

获取模拟器 stdout 和 stderr 的流

Process getEmulatorProcess()

返回与此模拟器对应的 Process

final File getExecuteShellCommandLog()

包含所有 executeShellCommand(String) 日志的日志。

long getExternalStoreFreeSpace()

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

String getFastbootPath()

返回正在使用的 fastboot 二进制文件的路径。

String getFastbootProductType()

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

String getFastbootProductVariant()

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

String getFastbootSerialNumber()

返回 fastboot 模式序列号。

String getFastbootVariable(String variableName)

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

String getFastbootVersion()

返回正在使用的 fastboot 二进制文件的版本字符串。

IFileEntry getFileEntry(String path)

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

IFileEntry getFileEntry(FileListingService.FileEntry entry)

用于从非根路径获取 FileEntry 的非官方帮助程序。

getFoldableStates()

返回设备上的可折叠设备状态列表。

IDevice getIDevice()

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

getInstalledPackageNames()

提取设备上存在的应用软件包名称。

long getIntProperty(String name, long defaultValue)

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

String getIpAddress()

获取设备的 IP 地址。

KeyguardControllerState getKeyguardState()

返回一个对象以获取键盘锁的当前状态,如果不受支持,则返回 null。

long getLastExpectedRebootTimeMillis()

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

int getLaunchApiLevel()

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

InputStreamSource getLogcat()

获取 logcat 数据的快照流。

InputStreamSource getLogcat(int maxBytes)

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

InputStreamSource getLogcatDump()

获取设备当前 logcat 的转储。

InputStreamSource getLogcatSince(long date)

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

String getMacAddress()

返回设备的 MAC 地址。如果无法从设备查询,则返回 null。

Integer getMainUserId()

返回主要用户 ID。

getMainlineModuleInfo()

获取设备上安装的 Mainline 模块的相关信息。

int getMaxNumberOfRunningUsersSupported()

获取支持同时运行的用户数量上限。

int getMaxNumberOfUsersSupported()

获取支持的用户数上限。

Process getMicrodroidProcess()
IDeviceStateMonitor getMonitor()

返回与设备关联的 IDeviceStateMonitor

String getMountPoint(String mountName)

返回装载点。

ITestDevice.MountPointInfo getMountPointInfo(String mountpoint)

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

getMountPointInfo()

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

TestDeviceOptions getOptions()

获取设备的测试选项。

long getPartitionFreeSpace(String partition)

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

Integer getPrimaryUserId()

返回主要用户 ID。

ProcessInfo getProcessByName(String processName)

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

String getProcessPid(String process)

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

String getProductType()

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

String getProductVariant()

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

String getProperty(String name)

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

ITestDevice.RecoveryMode getRecoveryMode()

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

InputStreamSource getScreenshot(String format)

从设备上抓取屏幕截图。

InputStreamSource getScreenshot(long displayId)

从指定显示屏 ID 的设备中获取屏幕截图。

InputStreamSource getScreenshot(String format, boolean rescale)

从设备上抓取屏幕截图。

InputStreamSource getScreenshot()

从设备上抓取屏幕截图。

String getSerialNumber()

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

String getSetting(int userId, String namespace, String key)

返回请求的设置的值。

String getSetting(String namespace, String key)

请参阅 getSetting(int, String, String) 并在系统用户上执行。

String getSimOperator()

如果 SIM 卡运营商不可用或设备不可用,则返回 SIM 卡运营商或 null。

String getSimState()

返回 SIM 卡状态;如果 SIM 卡不可用或设备不可用,则返回 null。

getTombstones()

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

long getTotalMemory()

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

getUninstallablePackageNames()

获取可卸载的应用软件包名称。

boolean getUseFastbootErase()

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

int getUserFlags(int userId)

查找并返回指定用户的标记。

getUserInfos()

获取设备上的 useId 到 UserInfo 的映射。

int getUserSerialNumber(int userId)

如果找到,则返回与 userId 关联的序列号,在任何其他情况下返回 -10000。

IManagedTestDevice.DeviceEventResponse handleAllocationEvent(DeviceEvent event)

处理指定的 DeviceEvent。

处理 DeviceEvent,这不一定会将此设备转换到新的分配状态。

boolean hasFeature(String feature)

检查设备是否支持某项功能。

String installPackage(File packageFile, boolean reinstall, String... extraArgs)

在设备上安装 Android 软件包。

String installPackage(File packageFile, boolean reinstall, boolean grantPermissions, String... extraArgs)

在设备上安装 Android 软件包。

String installPackageForUser(File packageFile, boolean reinstall, int userId, String... extraArgs)

在设备上安装给定用户的 Android 软件包。

String installPackageForUser(File packageFile, boolean reinstall, boolean grantPermissions, int userId, String... extraArgs)

在设备上安装给定用户的 Android 软件包。

void invalidatePropertyCache()
boolean isAdbRoot()

boolean isAdbTcp()
boolean isAppEnumerationSupported()

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

boolean isBypassLowTargetSdkBlockSupported()

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

boolean isDebugfsMounted()

检查 debugfs 是否已装载。

boolean isDeviceEncrypted()

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

boolean isDirectory(String path)

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

boolean isEnableAdbRoot()
boolean isEncryptionSupported()

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

boolean isExecutable(String fullPath)

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

boolean isFastbootEnabled()

如果设备可以使用 fastboot,则返回此值。

boolean isHeadless()

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

boolean isHeadlessSystemUserMode()

返回设备是否使用无头系统用户模式。

boolean isMainUserPermanentAdmin()

返回主要用户是否为永久管理员且无法删除或降级为非管理员状态的结果。

boolean isMultiUserSupported()

确定是否支持多用户。

boolean isPackageInstalled(String packageName, String userId)

查询设备的给定软件包名称和用户 ID,以检查该用户目前是否已安装该设备。

boolean isPackageInstalled(String packageName)

查询设备以获取给定的软件包名称,检查设备当前是否已安装。

boolean isRuntimePermissionSupported()

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

boolean isStateBootloaderOrFastbootd()

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

boolean isUserRunning(int userId)

检查指定用户是否正在运行。

boolean isUserSecondary(int userId)

根据其标记返回指定用户是否为次要用户。

boolean isUserVisible(int userId)

检查指定用户是否可见。

boolean isUserVisibleOnDisplay(int userId, int displayId)

检查指定用户是否在指定显示屏中可见。

boolean isVisibleBackgroundUsersOnDefaultDisplaySupported()

返回设备是否允许在 ERROR(/java.android.view.Display#DEFAULT_DISPLAY) 中在后台启动用户。

boolean isVisibleBackgroundUsersSupported()

返回设备是否允许用户在后台启动。

boolean isWifiEnabled()

测试 Wi-Fi 是否已启用。

listDisplayIds()

收集设备上由“dumpsys SurfaceFlinger”报告的可用屏幕 ID 的列表。

listDisplayIdsForStartingVisibleBackgroundUsers()

获取可用于 start a user visible in the background 的屏幕的列表。

listUsers()

获取设备上的用户列表。

boolean logAnrs(ITestLogger logger)

从设备收集并记录 ANR。

boolean logBugreport(String dataName, ITestLogger listener)

用于生成 bug 报告并将其记录给报告者的辅助方法。

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

在设备的 logcat 中记录消息。

void mountDebugfs()

装载 debugfs。

void nonBlockingReboot()

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

void postAdbRootAction()

如果设备需要在 adb root 之后、设备恢复在线状态之前执行某些特定操作,请替换。

void postAdbUnrootAction()

如果设备需要在 adb unroot 之后、设备恢复在线状态之前执行某些特定操作,请替换。

void postBootSetup()

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

void postInvocationTearDown(Throwable exception)

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

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

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

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

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

boolean pullDir(String deviceFilePath, File localDir)

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

boolean pullFile(String remoteFilePath, File localFile)

从设备检索文件。

File pullFile(String remoteFilePath, int userId)

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

File pullFile(String remoteFilePath)

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

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

从设备检索文件。

String pullFileContents(String remoteFilePath)

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

File pullFileFromExternal(String remoteFilePath)

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

boolean pushDir(File localFileDir, String deviceFilePath, excludedDirectories)

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

boolean pushDir(File localFileDir, String deviceFilePath)

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

boolean pushDir(File localFileDir, String deviceFilePath, int userId)

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

boolean pushFile(File localFile, String remoteFilePath, boolean evaluateContentProviderNeeded)

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

boolean pushFile(File localFile, String remoteFilePath)

将文件推送到设备。

boolean pushFile(File localFile, String remoteFilePath, int userId)

将文件推送到设备。

boolean pushString(String contents, String remoteFilePath)

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

void reboot(String reason)

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

void reboot()

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

void rebootIntoBootloader()

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

void rebootIntoFastbootd()

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

void rebootIntoRecovery()

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

void rebootIntoSideload()

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

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

void rebootIntoSideload(boolean autoReboot)

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

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

void rebootUntilOnline()

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

void rebootUntilOnline(String reason)

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

void rebootUserspace()

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

void rebootUserspaceUntilOnline()

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

boolean recoverDevice()

尝试恢复设备通信。

void registerDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)

为此设备注册 IDeviceActionReceiver

void remountSystemReadOnly()

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

void remountSystemWritable()

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

void remountVendorReadOnly()

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

void remountVendorWritable()

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

boolean removeAdmin(String componentName, int userId)

移除指定用户的指定设备管理员,如果成功,则返回 true,否则返回 false

void removeOwners()

尽可能移除所有现有的设备配置文件所有者。

boolean removeUser(int userId)

从设备中移除指定用户。

void resetContentProviderSetup()

重置 content provider 设置的标志,以便再次触发它。

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

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

boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, listeners)

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

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)) 相同,但会针对指定用户运行测试。

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

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

void setConfiguration(IConfiguration configuration)

注入正在使用的 IConfiguration

final void setConnectionAvdInfo(GceAvdInfo avdInfo)
void setDate(Date date)

设置设备上的日期

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

boolean setDeviceOwner(String componentName, int userId)

将设备管理组件设为给定用户的设备所有者。

void setDeviceState(TestDeviceState deviceState)

更新设备的状态。

void setEmulatorOutputStream(SizeLimitedOutputStream output)

对于模拟器,设置 SizeLimitedOutputStream 以记录输出

void setEmulatorProcess(Process p)

当此设备为模拟器时,设置 Process

void setFastbootEnabled(boolean fastbootEnabled)

为设备设置 fastboot 选项。

void setFastbootPath(String fastbootPath)

设置应使用的 fastboot 二进制文件的路径。

void setIDevice(IDevice newDevice)

更新与此 ITestDevice 关联的 IDevice。

void setLogStartDelay(int delay)

设置在为在线设备启动 logcat 捕获之前等待的时间(以毫秒为单位)。

void setOptions(TestDeviceOptions options)

为设备设置 TestDeviceOptions

boolean setProperty(String propKey, String propValue)

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

void setRecovery(IDeviceRecovery recovery)

设置要用于此设备的 IDeviceRecovery

void setRecoveryMode(ITestDevice.RecoveryMode mode)

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

void setSetting(String namespace, String key, String value)

请参阅 setSetting(int, String, String, String) 并在系统用户上执行。

void setSetting(int userId, String namespace, String key, String value)

将设置值添加到给定用户的命名空间。

void setTestLogger(ITestLogger testLogger)

注入 ITestLogger 实例

void setUseFastbootErase(boolean useFastbootErase)

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

void startLogcat()

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

boolean startUser(int userId)

在后台启动指定用户(如果当前已停止)。

boolean startUser(int userId, boolean waitFlag)

在后台启动指定用户(如果当前已停止)。

boolean startVisibleBackgroundUser(int userId, int displayId, boolean waitFlag)

在后台启动指定用户,在给定显示屏中处于可见状态(即允许用户在该显示屏上启动 activity)。

void stopEmulatorOutput()

关闭并删除模拟器输出。

void stopLogcat()

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

boolean stopUser(int userId)

停止指定用户。

boolean stopUser(int userId, boolean waitFlag, boolean forceFlag)

停止指定用户。

String switchToAdbTcp()

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

boolean switchToAdbUsb()

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

boolean switchUser(int userId)

切换到具有默认超时的另一个 userId。

boolean switchUser(int userId, long timeout)

切换到另一个以所提供的超时作为截止时间的用户 ID。

boolean syncFiles(File localFileDir, String deviceFilePath)

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

Bugreport takeBugreport()

获取 bug 报告并在 Bugreport 对象内返回该报告进行处理。

String uninstallPackage(String packageName)

从设备上卸载 Android 软件包。

String uninstallPackageForUser(String packageName, int userId)

从设备中卸载给定用户的 Android 软件包。

boolean unlockDevice()

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

void unmountDebugfs()

卸载 debugfs。

boolean waitForBootComplete(long timeOut)

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

boolean waitForDeviceAvailable()

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

boolean waitForDeviceAvailable(long waitTime)

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

boolean waitForDeviceAvailableInRecoverPath(long waitTime)

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

void waitForDeviceBootloader()

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

boolean waitForDeviceInRecovery(long waitTime)

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

boolean waitForDeviceInSideload(long waitTime)

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

boolean waitForDeviceNotAvailable(long waitTime)

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

void waitForDeviceOnline()

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

void waitForDeviceOnline(long waitTime)

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

boolean waitForDeviceShell(long waitTime)

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

受保护的方法

void addExtraConnectionBuilderArgs(DefaultConnection.ConnectionBuilder builder)
String[] buildAdbShellCommand(String command, boolean forceExitStatusDetection)

针对给定的 adb shell 命令会话和参数构建操作系统命令

void checkApiLevelAgainst(String feature, int strictMinLevel)
NativeDevice.RebootDeviceAction createRebootDeviceAction(NativeDevice.RebootMode rebootMode, String reason)

创建要在执行重新启动操作时使用的 RebootDeviceAction

IRunUtil createRunUtil()
void doAdbReboot(NativeDevice.RebootMode rebootMode, String reason)

执行 adb 重新启动。

void ensureRuntimePermissionSupported()

运行时权限不受支持时抛出异常的辅助方法

int getApiLevelSafe()
ITestLogger getLogger()
IRunUtil getRunUtil()

获取要使用的 RunUtil 实例。

void initializeConnection(IBuildInfo info, MultiMap<String, String> attributes)
String internalGetProperty(String propName, String fastbootVar, String description)

默认从 ddmlib 缓存中提取设备属性,并根据设备是否处于 Fastboot 模式,回退到“adb shell getprop”或“fastboot getvar”。

boolean isInRebootCallback()

返回是否正在执行重新启动回调。

boolean isNewer(File localFile, IFileEntry entry)

如果本地文件比远程文件新,则返回 true

void notifyRebootEnded()

将重新启动结束事件通知给所有 IDeviceActionReceiver

void notifyRebootStarted()

向所有 IDeviceActionReceiver 通知重新启动开始事件。

boolean performDeviceAction(String actionDescription, NativeDevice.DeviceAction action, int retryAttempts)

在此设备上执行操作。

void postAdbReboot()

重新启动后可能执行的其他操作。

void prePostBootSetup()

允许每种设备类型(AndroidNativeDevice、TestDevice)针对特定启动后设置替换此方法。

boolean pullFileInternal(String remoteFilePath, File localFile)
void setClock(Clock clock)

设置要使用的时钟实例。

void setMicrodroidProcess(Process process)

将 TestDevice 标记为 Microdroid,并设置其 CID。

void setTestDeviceOptions( deviceOptions)
CommandResult simpleFastbootCommand(long timeout, envVarMap, String[] fullCmd)

执行包含环境变量的简单 fastboot 命令并报告该命令的状态。

CommandResult simpleFastbootCommand(long timeout, String[] fullCmd)

执行一个简单的 fastboot 命令并报告该命令的状态。

boolean waitForDeviceNotAvailable(String operationDesc, long time)

等待设备不可用(停止向 adb 报告)。

常量

INVALID_USER_ID

public static final int INVALID_USER_ID

针对任何无效/未找到的用户 ID 返回的值:UserHandle 定义了 -10000 值

常量值: -10000 (0xffffd8f0)

MAX_HOST_DEVICE_TIME_OFFSET

protected static final long MAX_HOST_DEVICE_TIME_OFFSET

常量值: 5000 (0x0000000000001388)

MAX_RETRY_ATTEMPTS 次

protected static final int MAX_RETRY_ATTEMPTS

尝试执行的命令重试的默认次数

常量值: 2 (0x00000002)

字段

DEBUGFS_PATH

public static final String DEBUGFS_PATH

SD_CARD

protected static final String SD_CARD

STORAGE_EMULATED

protected static final String STORAGE_EMULATED

mOptions

protected TestDeviceOptions mOptions

mStateMonitor

protected final IDeviceStateMonitor mStateMonitor

公共构造函数

原生设备

public NativeDevice (IDevice device, 
                IDeviceStateMonitor stateMonitor, 
                IDeviceMonitor allocationMonitor)

创建 TestDevice

参数
device IDevice:关联的 IDevice

stateMonitor IDeviceStateMonitor:要使用的 IDeviceStateMonitor 机制

allocationMonitor IDeviceMonitor:用于通知分配状态变化的 IDeviceMonitor。可以为 null

公共方法

batchPrefetchStartupBuildProps

public void batchPrefetchStartupBuildProps ()

通过预取我们需要的所有属性(而不是每个属性调用“adb getprop”)进行微优化(大约 400 毫秒)。也就是说,获取所有属性的速度与提取一个属性一样快。device.getApiLevel()、checkApiLevelAgainstNextRelease 和 getBuildAlias 等工具在后台都会调用“adb getprop”。我们在一次调用中提取它们,然后调用 NativeDevice.setProperty。即使我们不这样做,NativeDevice 本身也会调用 setProperty 并缓存结果,以备将来调用。我们只是稍稍提前了一下。如果设备处于恢复状态,或者提取属性时发生了其他错误,我们会忽略它们。

canSwitchToHeadlessSystemUser

public boolean canSwitchToHeadlessSystemUser ()

返回是否允许切换到无头 SYSTEM 用户。

返回
boolean

抛出
DeviceNotAvailableException

checkApiLevelAgainstNextRelease 介绍

public boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

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

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

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

抛出
DeviceNotAvailableException

checkConnectivity

public boolean checkConnectivity ()

检查设备是否已连接到网络。

返回
boolean 如果设备具有有效的网络连接,则为 true,对于后者,则为 false

抛出
DeviceNotAvailableException

ClearErrorDialogs

public boolean clearErrorDialogs ()

尝试关闭设备界面上当前显示的任何错误对话框。

返回
boolean 如果不存在对话框或对话框已成功清除,则为 true。 否则为 false

抛出
DeviceNotAvailableException

ClearLastConnectedWifiNetwork

public void clearLastConnectedWifiNetwork ()

清除上次连接的 Wi-Fi 网络。应在开始新的调用时调用此方法,以避免在设备重新启动后连接到上一次测试中使用的 Wi-Fi 网络。

ClearLogcat

public void clearLogcat ()

删除所有累积的 logcat 数据。

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

连接到 Wifi 网络

public boolean connectToWifiNetwork ( wifiSsidToPsk, 
                boolean scanSsid)

连接到 Wi-Fi 网络。

开启 Wi-Fi 并阻止,直到与 wifiSsidToPsk 映射中提供的其中一个 Wi-Fi 网络成功建立连接。建立连接后,实例将在每次重新启动后尝试恢复连接,直到调用 ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork()

参数
wifiSsidToPsk :Wi-Fi SSID 到密码的映射。

scanSsid boolean:是否扫描此网络的隐藏 SSID。

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

连接到 Wifi 网络

public boolean connectToWifiNetwork (String wifiSsid, 
                String wifiPsk)

连接到 Wi-Fi 网络。

开启 Wi-Fi 并阻止,直到成功连接到指定的 Wi-Fi 网络。 建立连接后,实例将在每次重新启动后尝试恢复连接,直到调用 ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork() 为止。

参数
wifiSsid String:要连接的 Wi-Fi SSSID

wifiPsk String:PSK 密码;如果未加密,则为 null

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

连接到 Wifi 网络

public boolean connectToWifiNetwork ( wifiSsidToPsk)

连接到 Wi-Fi 网络。

开启 Wi-Fi 并阻止,直到与 wifiSsidToPsk 映射中提供的其中一个 Wi-Fi 网络成功建立连接。建立连接后,实例将在每次重新启动后尝试恢复连接,直到调用 ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork()

参数
wifiSsidToPsk :Wi-Fi SSID 到密码的映射。

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

连接到 Wifi 网络

public boolean connectToWifiNetwork (String wifiSsid, 
                String wifiPsk, 
                boolean scanSsid)

连接到 Wi-Fi 网络。

开启 Wi-Fi 并阻止,直到成功连接到指定的 Wi-Fi 网络。 建立连接后,实例将在每次重新启动后尝试恢复连接,直到调用 ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork() 为止。

参数
wifiSsid String:要连接的 Wi-Fi SSSID

wifiPsk String:PSK 密码;如果未加密,则为 null

scanSsid boolean:是否扫描此网络的隐藏 SSID。

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

connectToWifiNetworkIfNeeded

public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk, 
                boolean scanSsid)

connectToWifiNetwork(String, String) 的变体,仅在设备当前没有网络连接时才进行连接。

参数
scanSsid boolean:是否扫描此网络的隐藏 SSID

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

connectToWifiNetworkIfNeeded

public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk)

connectToWifiNetwork(String, String) 的变体,仅在设备当前没有网络连接时才进行连接。

返回
boolean true(如果已成功连接到 Wi-Fi 网络)。false 否则

抛出
DeviceNotAvailableException

createUser

public int createUser (String name, 
                boolean guest, 
                boolean ephemeral)

使用给定名称和提供的标志创建用户

参数
name String:在设备上创建的用户的级别

guest boolean:在创建期间启用用户标志 --guest

ephemeral boolean:在创建期间启用用户标志 --Temporary

返回
int 已创建用户的 ID

抛出
DeviceNotAvailableException

createUser

public int createUser (String name, 
                boolean guest, 
                boolean ephemeral, 
                boolean forTesting)

使用给定名称和提供的标志创建用户

参数
name String:在设备上创建的用户的级别

guest boolean:在创建期间启用用户标志 --guest

ephemeral boolean:在创建期间启用用户标志 --Temporary

forTesting boolean:在创建期间启用测试标志 --for-testing

返回
int 已创建用户的 ID

抛出
DeviceNotAvailableException

createUser

public int createUser (String name)

使用给定名称和默认标志 0 创建用户。

参数
name String:在设备上创建的用户的级别

返回
int 创建的用户 ID 的整数

抛出
DeviceNotAvailableException

createUserNoThrow

public int createUserNoThrow (String name)

使用给定名称和默认标志 0 创建用户。

参数
name String:在设备上创建的用户的级别

返回
int 创建的用户 ID 的整数,或 -1 表示出错。

抛出
DeviceNotAvailableException

deleteFile

public void deleteFile (String deviceFilePath, 
                int userId)

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

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

userId int:要删除的用户 ID

抛出
DeviceNotAvailableException

deleteFile

public void deleteFile (String deviceFilePath)

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

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

抛出
DeviceNotAvailableException

deregisterDeviceActionReceiver

public void deregisterDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

移除已注册的 IDeviceActionReceiver

参数
deviceActionReceiver IDeviceActionReceiver:将被移除的 IDeviceActionReceiver

已软重启设备

public boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

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

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

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

抛出
DeviceNotAvailableException

deviceSoftRestartedAccounts 设备

public boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

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

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

抛出
DeviceNotAvailableException

停用 AdbRoot

public boolean disableAdbRoot ()

关闭 adb root。

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

返回
boolean 如果成功,则为 true

抛出
DeviceNotAvailableException

停用键盘锁

public void disableKeyguard ()

尝试停用键盘锁。

首先等待输入调度准备就绪,大约在设备报告 BOOT_COMPLETE 时也会发生这种情况,这明显是异步的,因为当前的框架实现偶尔会出现竞态条件。然后发送命令以关闭键盘锁(仅适用于非安全键盘)

抛出
DeviceNotAvailableException

停用网络监控器

public boolean disableNetworkMonitor ()

停用设备上的网络监控功能。

返回
boolean 如果已成功停用监控功能,则为 true。如果失败,则为 false

抛出
DeviceNotAvailableException

断开 Wi-Fi 连接

public boolean disconnectFromWifi ()

断开与 Wi-Fi 网络的连接。

从已知网络列表中移除所有网络并停用 Wi-Fi。

返回
boolean true(如果成功断开与 Wi-Fi 网络的连接)。如果断开连接失败,则为 false

抛出
DeviceNotAvailableException

doFileExist

public boolean doesFileExist (String deviceFilePath, 
                int userId)

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

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

userId int:用于检查文件是否存在的用户 ID

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

抛出
DeviceNotAvailableException

doFileExist

public boolean doesFileExist (String deviceFilePath)

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

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

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

抛出
DeviceNotAvailableException

转储堆

public File dumpHeap (String process, 
                String devicePath)

尝试从 system_server 转储堆。调用方负责清理转储文件。

参数
process String:要转储堆的设备进程的名称。

devicePath String:设备上的转储路径。这必须是权限允许的位置。

返回
File 包含报告的 ERROR(/File)。如果操作失败,则为 null。

抛出
DeviceNotAvailableException

启用 AdbRoot

public boolean enableAdbRoot ()

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

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

返回
boolean 如果成功,则为 true

抛出
DeviceNotAvailableException

启用网络监控器

public boolean enableNetworkMonitor ()

启用设备上的网络监控功能。

返回
boolean 如果已成功启用监控,则为 true。如果失败,则为 false

抛出
DeviceNotAvailableException

执行 AdbCommand

public String executeAdbCommand (long timeout, 
                String... cmdArgs)

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

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

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

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

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

抛出
DeviceNotAvailableException

执行 AdbCommand

public String executeAdbCommand (long timeout, 
                 envMap, 
                String... cmdArgs)

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

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

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

envMap :要为命令设置的环境

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

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

抛出
DeviceNotAvailableException

执行 AdbCommand

public String executeAdbCommand (String... cmdArgs)

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

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

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

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

抛出
DeviceNotAvailableException

executeFastbootCommand

public CommandResult executeFastbootCommand (String... cmdArgs)

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

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

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

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException

executeFastbootCommand

public CommandResult executeFastbootCommand (long timeout, 
                String... cmdArgs)

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

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

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

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

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException

executeLongFastbootCommand

public CommandResult executeLongFastbootCommand (String... cmdArgs)

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

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

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

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException

executeLongFastbootCommand

public CommandResult executeLongFastbootCommand ( envVarMap, 
                String... cmdArgs)

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

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

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

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

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException

executeShellCommand

public String executeShellCommand (String command)

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

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

返回
String shell 输出

抛出
DeviceNotAvailableException

executeShellCommand

public 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 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 void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

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

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

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

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

抛出
DeviceNotAvailableException

执行 ShellV2Command

public CommandResult executeShellV2Command (String cmd)

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

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

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException

执行 ShellV2Command

public CommandResult executeShellV2Command (String cmd, 
                OutputStream pipeToOutput)

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

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

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

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException

执行 ShellV2Command

public CommandResult executeShellV2Command (String cmd, 
                File pipeAsInput)

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

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

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

返回
CommandResult CommandResult 中的结果。

抛出
DeviceNotAvailableException

执行 ShellV2Command

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

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

返回
CommandResult

抛出
DeviceNotAvailableException

执行 ShellV2Command

public CommandResult executeShellV2Command (String cmd, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit)

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

返回
CommandResult

抛出
DeviceNotAvailableException

执行 ShellV2Command

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

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

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

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

返回
CommandResult

抛出
DeviceNotAvailableException

执行 ShellV2Command

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

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

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

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的单位

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

返回
CommandResult

抛出
DeviceNotAvailableException

fastbootWipePartition

public CommandResult fastbootWipePartition (String partition)

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

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

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

参数
partition String:要擦除的分区

返回
CommandResult 包含命令输出的 CommandResult

抛出
DeviceNotAvailableException

getActiveApexes

public  getActiveApexes ()

提取设备上已激活的 APEX 的相关信息。

返回
设备上目前已激活 ERROR(/Set) 个(共 ApexInfo 个)

抛出
DeviceNotAvailableException

getAllSettings

public  getAllSettings (String namespace)

返回所请求命名空间的键值对。

参数
namespace String:必须是 {"system", "secure", "global"} 之一

返回
键值对的映射。如果不支持命名空间,则为 null。

抛出
DeviceNotAvailableException

getAllocationState

public DeviceAllocationState getAllocationState ()

返回设备的当前分配状态

返回
DeviceAllocationState

获取 Android ID

public String getAndroidId (int userId)

查找并返回与 userId 关联的 android-id;如果未找到,则返回 null。

参数
userId int

返回
String

抛出
DeviceNotAvailableException

getAndroidId

public  getAndroidIds ()

针对找到的 Android ID 创建与用户 ID 匹配的映射。无法保证每个用户 ID 都能找到与此函数关联的 Android ID,因此某些用户 ID 可能会与 null 匹配。

返回
找到了与用户 ID 匹配的 Android ID 映射。

抛出
DeviceNotAvailableException

getApiLevel

public int getApiLevel ()

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

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

抛出
DeviceNotAvailableException

getAppPackageInfo

public PackageInfo getAppPackageInfo (String packageName)

提取设备上安装的软件包的相关信息。

参数
packageName String

返回
PackageInfo PackageInfonull(如果无法检索信息)

抛出
DeviceNotAvailableException

getAppPackageInfos

public  getAppPackageInfos ()

提取设备上安装的软件包的相关信息。

返回
设备上已安装 ERROR(/List) 个(共 PackageInfo 个)。

抛出
DeviceNotAvailableException

getBasebandVersion

public String getBasebandVersion ()

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

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

抛出
DeviceNotAvailableException

getBattery

public Integer getBattery ()

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

返回
Integer

getBooleanProperty

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

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

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

抛出
DeviceNotAvailableException

getBootHistorySince

public  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

timeUnit TimeUnit:时间单位 TimeUnit

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

抛出
DeviceNotAvailableException

getBootloaderVersion

public String getBootloaderVersion ()

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

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

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

抛出
DeviceNotAvailableException

获取错误报告

public InputStreamSource getBugreport ()

从设备中检索 bug 报告。

此实现保证可在没有 SD 卡(或尚未装载 SD 卡)的设备上继续正常运行。

返回
InputStreamSource 一个 InputStreamSource,用于按需生成 bug 报告内容。如果失败,InputStreamSource 将生成一个空的 ERROR(/InputStream)

getBugreportz

public InputStreamSource getBugreportz ()

从设备中检索 bugreportz。ZIP 格式的 bug 报告包含主 bug 报告和其他对调试有用的日志文件。

仅适用于高于 1.0.36 的“adb 版本”

返回
InputStreamSource 包含 bugreportz 的 zip 文件的 InputStreamSource,如果失败,则返回 null。

getBuildAlias

public String getBuildAlias ()

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

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

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

抛出
DeviceNotAvailableException

getBuildFlavor

public String getBuildFlavor ()

检索设备的 build 变种。

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

抛出
DeviceNotAvailableException

getBuildId

public String getBuildId ()

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

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

抛出
DeviceNotAvailableException

getBuildSigningKeys

public String getBuildSigningKeys ()

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

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

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

抛出
DeviceNotAvailableException

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor ()

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

返回
DeviceDescriptor

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

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

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

返回
DeviceDescriptor

getChildren

public String[] getChildren (String path)

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

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

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

抛出
DeviceNotAvailableException

getConnection

public AbstractConnection getConnection ()

与设备关联的当前连接。

返回
AbstractConnection

getContentProvider

public ContentProviderHandler getContentProvider (int userId)

返回 ContentProviderHandler;如果不可用,则返回 null。

如果内容提供程序之前使用相同的 userId 构建而成,则可以重复使用。

参数
userId int:用于初始化 content provider 的用户 ID。

返回
ContentProviderHandler

抛出
DeviceNotAvailableException

getCurrentFoldableState

public DeviceFoldableState getCurrentFoldableState ()

返回设备当前的可折叠状态;如果发生某些问题,则返回 null。

返回
DeviceFoldableState

抛出
DeviceNotAvailableException

获取当前用户

public int getCurrentUser ()

返回当前正在运行的用户的 ID。如果发生错误,则返回 -10000。

返回
int

抛出
DeviceNotAvailableException

getDeviceClass

public String getDeviceClass ()

获取设备类。

返回
String String 设备类。

getDeviceDate

public long getDeviceDate ()

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

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

抛出
DeviceNotAvailableException

获取设备描述符

public DeviceDescriptor getDeviceDescriptor ()

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

返回
DeviceDescriptor

获取设备描述符

public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

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

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

返回
DeviceDescriptor

getDeviceState

public TestDeviceState getDeviceState ()

获取设备的状态。

返回
TestDeviceState

getDeviceTimeOffset

public long getDeviceTimeOffset (Date date)

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

参数
date Date

返回
long 以毫秒计的差值

抛出
DeviceNotAvailableException

getEmulatorOutput

public InputStreamSource getEmulatorOutput ()

获取模拟器 stdout 和 stderr 的流

返回
InputStreamSource 模拟器输出

getEmulatorProcess

public Process getEmulatorProcess ()

返回与此模拟器对应的 Process

返回
Process Processnull

getExecuteShellCommandLog

public final File getExecuteShellCommandLog ()

包含所有 executeShellCommand(String) 日志的日志。

返回
File

getExternalStoreFreeSpace

public long getExternalStoreFreeSpace ()

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

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

抛出
DeviceNotAvailableException

getFastbootPath

public String getFastbootPath ()

返回正在使用的 fastboot 二进制文件的路径。仍需要 isFastbootEnabled() 为 true,才能启用 fastboot 函数。

返回
String

getFastbootProductType

public String getFastbootProductType ()

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

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

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

抛出
DeviceNotAvailableException

getFastbootProductVariant

public String getFastbootProductVariant ()

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

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

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

抛出
DeviceNotAvailableException

getFastbootSerialNumber

public String getFastbootSerialNumber ()

返回 fastboot 模式序列号。

返回
String

getFastbootVariable

public String getFastbootVariable (String variableName)

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

参数
variableName String:变量名称

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

抛出
DeviceNotAvailableException

getFastbootVersion

public String getFastbootVersion ()

返回正在使用的 fastboot 二进制文件的版本字符串。如果出现问题,则返回 null。

返回
String

getFileEntry

public IFileEntry getFileEntry (String path)

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

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

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

抛出
DeviceNotAvailableException

getFileEntry

public IFileEntry getFileEntry (FileListingService.FileEntry entry)

非官方帮助程序,用于从非根路径获取 FileEntry。修复:重构 FileEntry 系统,使其可从任何路径使用。(即使是非 root 用户)。

参数
entry FileListingService.FileEntryFileEntry 不一定是 Ddmlib 所需的 root。

返回
IFileEntry 表示 FileEntry 的 FileEntryWrapper。

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

getFoldableStates

public  getFoldableStates ()

返回设备上的可折叠设备状态列表。可通过“cmd device_state print-states”获取。

返回

抛出
DeviceNotAvailableException

getIDevice

public IDevice getIDevice ()

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

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

返回
IDevice IDevice

getInstallPackageNames

public  getInstalledPackageNames ()

提取设备上存在的应用软件包名称。

返回
设备上目前安装的软件包名称为 ERROR(/Set) 个(共 String 个)。

抛出
DeviceNotAvailableException

getIntProperty

public long getIntProperty (String name, 
                long defaultValue)

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

参数
name String:属性名称

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

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

抛出
DeviceNotAvailableException

getIpAddress

public String getIpAddress ()

获取设备的 IP 地址。

返回
String 设备的 IP 地址,或者 null(如果设备没有 IP 地址)

抛出
DeviceNotAvailableException

getKeyguardState

public KeyguardControllerState getKeyguardState ()

返回一个对象以获取键盘锁的当前状态,如果不受支持,则返回 null。

返回
KeyguardControllerState 包含键盘锁状态快照的 KeyguardControllerState,如果不支持键盘锁查询,则返回 Null。

抛出
DeviceNotAvailableException

getLastexpectedRebootTimeMillis

public long getLastExpectedRebootTimeMillis ()

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

返回
long

getLaunchApiLevel

public int getLaunchApiLevel ()

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

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

抛出
DeviceNotAvailableException

获取 Logcat

public InputStreamSource getLogcat ()

获取 logcat 数据的快照流。

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

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

    返回
    InputStreamSource

  • 获取 Logcat

    public InputStreamSource getLogcat (int maxBytes)

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

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

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

    返回
    InputStreamSource

    getLogcatDump

    public InputStreamSource getLogcatDump ()

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

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

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

    getLogcatLogcat

    public InputStreamSource getLogcatSince (long date)

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

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

    返回
    InputStreamSource

    getMacAddress

    public String getMacAddress ()

    返回设备的 MAC 地址。如果无法从设备查询,则返回 null。

    返回
    String

    getMainUserId

    public Integer getMainUserId ()

    返回主要用户 ID。

    返回
    Integer 主要用户的 userId(如果有);如果没有主要用户,则返回 null。

    抛出
    DeviceNotAvailableException

    getMainlineModuleInfo

    public  getMainlineModuleInfo ()

    获取设备上安装的 Mainline 模块的相关信息。

    返回
    设备上目前已安装 ERROR(/Set) 个 Mainline 模块(共 String 个)。

    抛出
    DeviceNotAvailableException

    支持运行的用户数达到上限

    public int getMaxNumberOfRunningUsersSupported ()

    获取支持同时运行的用户数量上限。默认设置为 0。

    返回
    int 一个整数,表示同时运行的用户数

    抛出
    DeviceNotAvailableException

    支持的最大用户数

    public int getMaxNumberOfUsersSupported ()

    获取支持的用户数上限。默认设置为 0。

    返回
    int 一个整数,表示支持的用户数

    抛出
    DeviceNotAvailableException

    getMicrodroidProcess

    public Process getMicrodroidProcess ()

    返回
    Process 返回 Microdroid 虚拟机的进程。如果 TestDevice 不是 Microdroid,则返回 null。

    getMonitor

    public IDeviceStateMonitor getMonitor ()

    返回与设备关联的 IDeviceStateMonitor

    返回
    IDeviceStateMonitor

    getMountPoint

    public String getMountPoint (String mountName)

    返回装载点。

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

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

    参数
    mountName String:装载点的名称

    返回
    String 装载点或 null

    getMountPointInfo

    public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

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

    参数
    mountpoint String

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

    抛出
    DeviceNotAvailableException

    getMountPointInfo

    public  getMountPointInfo ()

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

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

    抛出
    DeviceNotAvailableException

    getOptions

    public TestDeviceOptions getOptions ()

    获取设备的测试选项。

    返回
    TestDeviceOptions TestDeviceOptions 与被测设备相关。

    getPartitionFreeSpace

    public long getPartitionFreeSpace (String partition)

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

    参数
    partition String

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

    抛出
    DeviceNotAvailableException

    getPrimaryUserId

    public Integer getPrimaryUserId ()

    返回主要用户 ID。

    返回
    Integer 主要用户的 userId(如果有);如果没有主要用户,则返回 null。

    抛出
    DeviceNotAvailableException

    getProcessByName

    public ProcessInfo getProcessByName (String processName)

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

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

    返回
    ProcessInfo 给定 processName 的 ProcessInfo

    抛出
    DeviceNotAvailableException

    getProcessPid

    public String getProcessPid (String process)

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

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

    返回
    String

    抛出
    DeviceNotAvailableException

    getProductType

    public String getProductType ()

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

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

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

    抛出
    DeviceNotAvailableException

    getProductVariant

    public String getProductVariant ()

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

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

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

    抛出
    DeviceNotAvailableException

    getProperty

    public String getProperty (String name)

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

    参数
    name String:属性名称

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

    抛出
    DeviceNotAvailableException

    getRecoveryMode

    public ITestDevice.RecoveryMode getRecoveryMode ()

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

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

    获取屏幕截图

    public InputStreamSource getScreenshot (String format)

    从设备上抓取屏幕截图。 建议在尺寸较小时使用 getScreenshot(format) 并采用 JPEG 编码

    参数
    format String:支持的 PNG、JPEG

    返回
    InputStreamSource 屏幕截图的 InputStreamSource(格式);如果屏幕截图失败,则返回 null

    抛出
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot (long displayId)

    从指定显示屏 ID 的设备中获取屏幕截图。格式为 PNG。

    TODO:扩展上述实现以支持“format”和“rescale”

    参数
    displayId long:要从中获取屏幕截图的屏幕的显示 ID。

    返回
    InputStreamSource 屏幕截图的 InputStreamSource(格式);如果屏幕截图失败,则返回 null

    抛出
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot (String format, 
                    boolean rescale)

    从设备上抓取屏幕截图。建议将 getScreenshot(String) 与 JPEG 编码一起使用,以减小文件大小。

    参数
    format String:支持的 PNG、JPEG

    rescale boolean:是否应重新缩放屏幕截图以减小所生成图片的大小

    返回
    InputStreamSource 屏幕截图的 InputStreamSource(格式);如果屏幕截图失败,则返回 null

    抛出
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot ()

    从设备上抓取屏幕截图。

    返回
    InputStreamSource png 格式的屏幕截图的 InputStreamSource,如果屏幕截图失败,则返回 null

    抛出
    DeviceNotAvailableException

    getSerialNumber

    public String getSerialNumber ()

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

    返回
    String String 序列号

    getSetting

    public String getSetting (int userId, 
                    String namespace, 
                    String key)

    返回所请求设置的值。 命名空间必须为以下项之一:{"system", "secure", "global"}

    参数
    userId int

    namespace String

    key String

    返回
    String 与用户的 namespace:key 相关联的值。如果未找到,则为 Null。

    抛出
    DeviceNotAvailableException

    getSetting

    public String getSetting (String namespace, 
                    String key)

    请参阅 getSetting(int, String, String) 并在系统用户上执行。

    参数
    namespace String

    key String

    返回
    String

    抛出
    DeviceNotAvailableException

    getSimOperator

    public String getSimOperator ()

    如果 SIM 卡运营商不可用或设备不可用,则返回 SIM 卡运营商或 null。

    返回
    String

    getSimState

    public String getSimState ()

    如果 SIM 卡不可用或设备不可用,则返回 SIM 卡状态或 null。

    返回
    String

    getTombstone

    public  getTombstones ()

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

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

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

    抛出
    DeviceNotAvailableException

    getTotalMemory

    public long getTotalMemory ()

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

    返回
    long

    getUninstallablePackageNames

    public  getUninstallablePackageNames ()

    获取可卸载的应用软件包名称。目前,它被定义为非系统软件包和已更新的系统软件包。

    返回
    ERROR(/Set),表示设备上当前安装的可卸载 String 软件包名称。

    抛出
    DeviceNotAvailableException

    getUseFastbootErase

    public boolean getUseFastbootErase ()

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

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

    getUserFlags

    public int getUserFlags (int userId)

    查找并返回指定用户的标志。 标志在 Android 开源项目的“android.content.pm.UserInfo”类中定义。

    参数
    userId int

    返回
    int 与提供的 userId 关联的标记(如果找到),在任何其他情况下为 -10000。

    抛出
    DeviceNotAvailableException

    getUserInfo

    public  getUserInfos ()

    获取设备上的 useId 到 UserInfo 的映射。如果设备的输出不符合预期,则会抛出 DeviceRuntimeException

    返回
    UserInfo 对象的列表。

    抛出
    DeviceNotAvailableException

    getUserSerialNumber

    public int getUserSerialNumber (int userId)

    如果找到,则返回与 userId 关联的序列号,在任何其他情况下返回 -10000。

    参数
    userId int

    返回
    int

    抛出
    DeviceNotAvailableException

    handleAllocationEvent

    public IManagedTestDevice.DeviceEventResponse handleAllocationEvent (DeviceEvent event)

    处理指定的 DeviceEvent。可能会将设备转换为新状态。如有任何状态转换,将通知 IDeviceMonitor

    处理 DeviceEvent,这不一定会将此设备转换到新的分配状态。

    参数
    event DeviceEvent

    返回
    IManagedTestDevice.DeviceEventResponse

    hasFeature

    public boolean hasFeature (String feature)

    检查设备是否支持某项功能。

    参数
    feature String:格式应为“feature:”或“”。

    返回
    boolean 如果找到特征,则为 true,否则为 false。

    抛出
    DeviceNotAvailableException

    installPackage

    public String installPackage (File packageFile, 
                    boolean reinstall, 
                    String... extraArgs)

    在设备上安装 Android 软件包。

    参数
    packageFile File:要安装的 APK 文件

    reinstall boolean:如果应执行重新安装,则为 true

    extraArgs String:要传递的额外参数(可选)。如需了解可用选项,请参阅“adb shell pm -h”。

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    installPackage

    public String installPackage (File packageFile, 
                    boolean reinstall, 
                    boolean grantPermissions, 
                    String... extraArgs)

    在设备上安装 Android 软件包。

    注意:只有需要在安装时明确控制授予运行时权限的用例才应调用此函数。

    参数
    packageFile File:要安装的 APK 文件

    reinstall boolean:如果应执行重新安装,则为 true

    grantPermissions boolean:如果应在安装时授予所有运行时权限

    extraArgs String:要传递的额外参数(可选)。如需了解可用选项,请参阅“adb shell pm -h”。

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    installPackageForUser

    public String installPackageForUser (File packageFile, 
                    boolean reinstall, 
                    int userId, 
                    String... extraArgs)

    在设备上安装给定用户的 Android 软件包。

    参数
    packageFile File:要安装的 APK 文件

    reinstall boolean:如果应执行重新安装,则为 true

    userId int:要安装的整数用户 ID。

    extraArgs String:要传递的额外参数(可选)。如需了解可用选项,请参阅“adb shell pm -h”。

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    installPackageForUser

    public String installPackageForUser (File packageFile, 
                    boolean reinstall, 
                    boolean grantPermissions, 
                    int userId, 
                    String... extraArgs)

    在设备上安装给定用户的 Android 软件包。

    注意:只有需要在安装时明确控制授予运行时权限的用例才应调用此函数。

    参数
    packageFile File:要安装的 APK 文件

    reinstall boolean:如果应执行重新安装,则为 true

    grantPermissions boolean:如果应在安装时授予所有运行时权限

    userId int:要安装的整数用户 ID。

    extraArgs String:要传递的额外参数(可选)。如需了解可用选项,请参阅“adb shell pm -h”。

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    invalidatePropertyCache

    public void invalidatePropertyCache ()

    isAdbRoot

    public boolean isAdbRoot ()

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isAdbTcp

    public boolean isAdbTcp ()

    返回
    boolean

    isAppEnumerationSupported

    public boolean isAppEnumerationSupported ()

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

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

    抛出
    DeviceNotAvailableException

    isBypassLowTargetSdkBlockSupported

    public boolean isBypassLowTargetSdkBlockSupported ()

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

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

    抛出
    DeviceNotAvailableException

    已装载

    public boolean isDebugfsMounted ()

    检查 debugfs 是否已装载。

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

    抛出
    DeviceNotAvailableException

    isDeviceEncrypted

    public boolean isDeviceEncrypted ()

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

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

    抛出
    DeviceNotAvailableException

    isDirectory

    public boolean isDirectory (String path)

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

    参数
    path String

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isEnableAdbRoot

    public boolean isEnableAdbRoot ()

    返回
    boolean true(如果应在设备上启用 adb root 命令)

    isEncryptionSupported

    public boolean isEncryptionSupported ()

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

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

    抛出
    DeviceNotAvailableException

    可执行

    public boolean isExecutable (String fullPath)

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

    参数
    fullPath String

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isFastbootEnabled

    public boolean isFastbootEnabled ()

    返回 fastboot 适用于设备。

    返回
    boolean

    无头

    public boolean isHeadless ()

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

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isHeadlessSystemUserMode

    public boolean isHeadlessSystemUserMode ()

    返回设备是否使用无头系统用户模式的指示值。

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isMainUserPermanentAdmin

    public boolean isMainUserPermanentAdmin ()

    返回主要用户是否为永久管理员且无法删除或降级为非管理员状态的结果。

    返回
    boolean

    抛出
    DeviceNotAvailableException

    支持多用户

    public boolean isMultiUserSupported ()

    确定是否支持多用户。

    返回
    boolean 如果支持多用户,则为 true,否则为 false

    抛出
    DeviceNotAvailableException

    isPackageInstall

    public boolean isPackageInstalled (String packageName, 
                    String userId)

    查询设备的给定软件包名称和用户 ID,以检查该用户目前是否已安装该设备。

    参数
    packageName String:要检查其是否已安装的软件包。

    userId String:我们正在检查软件包的安装情况的用户 ID。如果为 null,将使用主要用户 0。

    返回
    boolean 如果软件包报告为已安装,则为 true。否则为 false。

    抛出
    DeviceNotAvailableException

    isPackageInstall

    public boolean isPackageInstalled (String packageName)

    查询设备以获取给定的软件包名称,检查设备当前是否已安装。

    参数
    packageName String

    返回
    boolean 如果软件包报告为已安装,则为 true。否则为 false。

    抛出
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public boolean isRuntimePermissionSupported ()

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

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

    抛出
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public boolean isStateBootloaderOrFastbootd ()

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

    返回
    boolean

    isUserRunning

    public boolean isUserRunning (int userId)

    检查指定用户是否正在运行。

    参数
    userId int

    返回
    boolean 如果用户正在运行,则为 true;在所有其他情况下,则为 false。

    抛出
    DeviceNotAvailableException

    是次要用户

    public boolean isUserSecondary (int userId)

    根据其标记返回指定用户是否为次要用户。

    参数
    userId int

    返回
    boolean 如果用户为次要用户,则为 true,否则为 false。

    抛出
    DeviceNotAvailableException

    isUserVisible(用户可见)

    public boolean isUserVisible (int userId)

    检查指定用户是否可见。

    “可见”用户是指与“人类”用户互动,因此能够启动启动 activity(通常在默认显示屏中)的用户。

    参数
    userId int

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isUserVisibleOnDisplay

    public boolean isUserVisibleOnDisplay (int userId, 
                    int displayId)

    检查指定用户是否在给定显示屏中可见。

    “可见”用户是指与“人类”用户互动,因此能够在该显示屏中启动 activity 的用户。

    参数
    userId int

    displayId int

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isVisibleBackgroundUsersOnDefaultDisplaySupported

    public boolean isVisibleBackgroundUsersOnDefaultDisplaySupported ()

    返回设备是否允许在 ERROR(/java.android.view.Display#DEFAULT_DISPLAY) 中在后台启动用户。

    如果支持,您可以调用 startVisibleBackgroundUser(int, int, boolean),并传递 listDisplayIdsForStartingVisibleBackgroundUsers()(其中应包含 ERROR(/java.android.view.Display#DEFAULT_DISPLAY))返回的屏幕。

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isVisibleBackgroundUsersSupported 支持

    public boolean isVisibleBackgroundUsersSupported ()

    返回设备是否允许用户在后台启动。

    如果支持,您可以调用 startVisibleBackgroundUser(int, int, boolean),并传递 listDisplayIdsForStartingVisibleBackgroundUsers() 返回的屏幕。

    返回
    boolean

    抛出
    DeviceNotAvailableException

    isWifiEnabled

    public boolean isWifiEnabled ()

    测试 Wi-Fi 是否已启用。

    检查设备是否启用了 Wi-Fi。用于在不应使用 WLAN 运行的测试(例如移动数据测试)之前断言 WLAN 状态。

    返回
    boolean true(如果已启用 Wi-Fi)。false(如果已停用)

    抛出
    DeviceNotAvailableException

    listDisplayIds

    public  listDisplayIds ()

    收集设备上由“dumpsys SurfaceFlinger”报告的可用屏幕 ID 的列表。

    返回
    显示设备列表。Default 始终返回默认显示屏 0。

    抛出
    DeviceNotAvailableException

    listDisplayIdsForStartingVisibleBackgroundUsers

    public  listDisplayIdsForStartingVisibleBackgroundUsers ()

    获取可用于 start a user visible in the background 的屏幕的列表。

    返回

    抛出
    DeviceNotAvailableException

    listUsers

    public  listUsers ()

    获取设备上的用户列表。如果设备的输出不符合预期,将抛出 DeviceRuntimeException

    返回
    用户 ID 列表。

    抛出
    DeviceNotAvailableException

    logAnrs

    public boolean logAnrs (ITestLogger logger)

    从设备收集并记录 ANR。

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

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

    抛出
    DeviceNotAvailableException

    logBugreport

    public boolean logBugreport (String dataName, 
                    ITestLogger listener)

    用于生成 bug 报告并将其记录给报告者的辅助方法。

    参数
    dataName String:用于报告 bug 报告的名称。

    listener ITestLogger:用于记录 bug 报告的 ITestLogger

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

    在设备上登录

    public 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 void mountDebugfs ()

    装载 debugfs。

    抛出
    DeviceNotAvailableException

    非阻塞重新启动

    public void nonBlockingReboot ()

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

    抛出
    DeviceNotAvailableException

    postAdbRootAction

    public void postAdbRootAction ()

    如果设备需要在 adb root 之后、设备恢复在线状态之前执行某些特定操作,请替换。 默认实现不包含任何添加操作。不保证在此阶段启用 adb root。

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

    postAdbUnrootAction

    public void postAdbUnrootAction ()

    如果设备需要在 adb unroot 之后、设备恢复在线状态之前执行某些特定操作,请替换。 默认实现不包含任何额外操作。不保证在此阶段会停用 adb root。

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

    postBootSetup

    public void postBootSetup ()

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

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

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

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

    抛出
    DeviceNotAvailableException

    postInvocationTearDown

    public void postInvocationTearDown (Throwable exception)

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

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

    preInvocationSetup

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

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

    参数
    info IBuildInfo:设备的 IBuildInfo

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

    抛出
    DeviceNotAvailableException
    TargetSetupError

    pullDir

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

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

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

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

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

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

    抛出
    DeviceNotAvailableException

    pullDir

    public boolean pullDir (String deviceFilePath, 
                    File localDir)

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

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

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

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

    抛出
    DeviceNotAvailableException

    pullFile

    public boolean pullFile (String remoteFilePath, 
                    File localFile)

    从设备检索文件。

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

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

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

    抛出
    DeviceNotAvailableException

    pullFile

    public File pullFile (String remoteFilePath, 
                    int userId)

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

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

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

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

    抛出
    DeviceNotAvailableException

    pullFile

    public File pullFile (String remoteFilePath)

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

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

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

    抛出
    DeviceNotAvailableException

    pullFile

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

    从设备检索文件。

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

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

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

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

    抛出
    DeviceNotAvailableException

    pullFileContents

    public String pullFileContents (String remoteFilePath)

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

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

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

    抛出
    DeviceNotAvailableException

    从外部拉取文件

    public File pullFileFromExternal (String remoteFilePath)

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

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

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

    抛出
    DeviceNotAvailableException

    推送目录

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath, 
                     excludedDirectories)

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

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

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

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

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

    抛出
    DeviceNotAvailableException

    推送目录

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath)

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

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

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

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

    抛出
    DeviceNotAvailableException

    推送目录

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath, 
                    int userId)

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

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

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

    userId int:要推送到的用户 ID

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

    抛出
    DeviceNotAvailableException

    pushFile

    public boolean pushFile (File localFile, 
                    String remoteFilePath, 
                    boolean evaluateContentProviderNeeded)

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

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

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

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

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

    抛出
    DeviceNotAvailableException

    pushFile

    public boolean pushFile (File localFile, 
                    String remoteFilePath)

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

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

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

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

    抛出
    DeviceNotAvailableException

    pushFile

    public boolean pushFile (File localFile, 
                    String remoteFilePath, 
                    int userId)

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

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

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

    userId int:要推送到的用户 ID

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

    抛出
    DeviceNotAvailableException

    推送字符串

    public boolean pushString (String contents, 
                    String remoteFilePath)

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

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

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

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

    抛出
    DeviceNotAvailableException

    重新启动

    public void reboot (String reason)

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

    屏蔽,直到设备可用。

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

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

    抛出
    DeviceNotAvailableException

    重新启动

    public void reboot ()

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

    在设备可用之前屏蔽。

    抛出
    DeviceNotAvailableException

    重新启动

    public void rebootIntoBootloader ()

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

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

    抛出
    DeviceNotAvailableException

    重新启动进入 Fastbootd

    public void rebootIntoFastbootd ()

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

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

    抛出
    DeviceNotAvailableException

    重新启动进入恢复模式

    public void rebootIntoRecovery ()

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

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

    抛出
    DeviceNotAvailableException

    重新启动

    public void rebootIntoSideload ()

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

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

    抛出
    DeviceNotAvailableException

    重新启动

    public void rebootIntoSideload (boolean autoReboot)

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

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

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

    抛出
    DeviceNotAvailableException

    重新启动到在线状态

    public void rebootUntilOnline ()

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

    抛出
    DeviceNotAvailableException

    重新启动到在线状态

    public void rebootUntilOnline (String reason)

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

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

    抛出
    DeviceNotAvailableException

    重新启动用户空间

    public void rebootUserspace ()

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

    屏蔽,直到设备可用。

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

    抛出
    DeviceNotAvailableException

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

    public void rebootUserspaceUntilOnline ()

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

    抛出
    DeviceNotAvailableException

    恢复设备

    public boolean recoverDevice ()

    尝试恢复设备通信。

    返回
    boolean 如果尝试恢复且成功,则为 true;如果跳过恢复,则返回 False

    抛出
    DeviceNotAvailableException 如果设备不再可用

    registerDeviceActionReceiver

    public void registerDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

    为此设备注册 IDeviceActionReceiver

    在设备操作开始前以及设备操作结束之后,所有已注册的 IDeviceActionReceiver 都会收到通知。

    参数
    deviceActionReceiver IDeviceActionReceiver:将注册的 IDeviceActionReceiver

    remountSystemReadOnly

    public void remountSystemReadOnly ()

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

    抛出
    DeviceNotAvailableException

    remountSystemWritable

    public void remountSystemWritable ()

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

    抛出
    DeviceNotAvailableException

    重新装载供应商只读

    public void remountVendorReadOnly ()

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

    抛出
    DeviceNotAvailableException

    可重新装载供应商可写

    public void remountVendorWritable ()

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

    抛出
    DeviceNotAvailableException

    移除管理员

    public boolean removeAdmin (String componentName, 
                    int userId)

    移除指定用户的指定设备管理员,如果操作成功,则返回 true,否则返回 false

    参数
    componentName String:要移除的设备管理员。

    userId int:设备管理员所在用户的用户。

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

    抛出
    DeviceNotAvailableException

    移除所有者

    public void removeOwners ()

    尽可能移除所有现有的设备配置文件所有者。

    抛出
    DeviceNotAvailableException

    移除用户

    public boolean removeUser (int userId)

    从设备中移除指定用户。

    参数
    userId int:要移除的用户

    返回
    boolean 如果成功移除了用户,则为 true,否则为 false。

    抛出
    DeviceNotAvailableException

    resetContentProviderSetup(重置内容提供程序设置)

    public void resetContentProviderSetup ()

    请重置 content provider 设置的标志,以便再次触发此操作。

    runInstrumentationTest

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

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

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

    listeners ITestLifeCycleReceiver:测试结果监听器

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

    抛出
    DeviceNotAvailableException

    runInstrumentationTest

    public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

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

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

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

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

    listeners :测试结果监听器

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

    抛出
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

    public 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 boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, 
                    int userId, 
                    ITestLifeCycleReceiver... listeners)

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

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    返回
    boolean

    抛出
    DeviceNotAvailableException

    setConfiguration

    public void setConfiguration (IConfiguration configuration)

    注入正在使用的 IConfiguration

    参数
    configuration IConfiguration

    setConnectionAvdInfo

    public final void setConnectionAvdInfo (GceAvdInfo avdInfo)

    参数
    avdInfo GceAvdInfo

    setDate

    public void setDate (Date date)

    设置设备上的日期

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

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

    抛出
    DeviceNotAvailableException

    setDeviceOwner

    public boolean setDeviceOwner (String componentName, 
                    int userId)

    将设备管理组件设为指定用户的设备所有者。

    参数
    componentName String:由设备管理员担任设备所有者。

    userId int:设备所有者所在用户的名称。

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

    抛出
    DeviceNotAvailableException

    setDeviceState

    public void setDeviceState (TestDeviceState deviceState)

    更新设备的状态。

    参数
    deviceState TestDeviceStateTestDeviceState

    setEmulatorOutputStream

    public void setEmulatorOutputStream (SizeLimitedOutputStream output)

    对于模拟器,设置 SizeLimitedOutputStream 以记录输出

    参数
    output SizeLimitedOutputStream:用于记录输出

    setEmulatorProcess

    public void setEmulatorProcess (Process p)

    当此设备为模拟器时,设置 Process

    参数
    p Process

    setFastbootEnabled

    public void setFastbootEnabled (boolean fastbootEnabled)

    为设备设置 fastboot 选项。应在首次分配设备时设置。

    参数
    fastbootEnabled boolean:设备是否支持 fastboot

    setFastbootPath

    public void setFastbootPath (String fastbootPath)

    设置应使用的 fastboot 二进制文件的路径。仍需要 isFastbootEnabled() 为 true,才能启用 fastboot 函数。

    参数
    fastbootPath String

    setIDevice

    public void setIDevice (IDevice newDevice)

    更新与此 ITestDevice 关联的 IDevice。

    新 IDevice 必须引用与当前参考相同的实体设备。如果 DDMS 分配了新的 IDevice,则会调用此方法

    参数
    newDevice IDeviceIDevice

    setLogStartDelay

    public void setLogStartDelay (int delay)

    设置在启动在线设备的 logcat 捕获之前等待的时间(以毫秒为单位)。

    参数
    delay int:延迟(以毫秒为单位)

    setOptions

    public void setOptions (TestDeviceOptions options)

    为设备设置 TestDeviceOptions

    参数
    options TestDeviceOptions

    setProperty

    public boolean setProperty (String propKey, 
                    String propValue)

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

    参数
    propKey String:要设置的键。

    propValue String:要设置的属性值。

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

    抛出
    DeviceNotAvailableException

    setRecovery

    public void setRecovery (IDeviceRecovery recovery)

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

    参数
    recovery IDeviceRecoveryIDeviceRecovery

    setRecoveryMode

    public void setRecoveryMode (ITestDevice.RecoveryMode mode)

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

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

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

    setSetting

    public void setSetting (String namespace, 
                    String key, 
                    String value)

    请参阅 setSetting(int, String, String, String) 并在系统用户上执行。

    参数
    namespace String

    key String

    value String

    抛出
    DeviceNotAvailableException

    setSetting

    public void setSetting (int userId, 
                    String namespace, 
                    String key, 
                    String value)

    将设置值添加到指定用户的命名空间。某些设置只有在重新启动后才可用。 命名空间必须为以下项之一:{"system", "secure", "global"}

    参数
    userId int

    namespace String

    key String

    value String

    抛出
    DeviceNotAvailableException

    setTestLogger

    public void setTestLogger (ITestLogger testLogger)

    注入 ITestLogger 实例

    参数
    testLogger ITestLogger

    setUseFastbootErase

    public void setUseFastbootErase (boolean useFastbootErase)

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

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

    启动 Logcat

    public void startLogcat ()

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

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

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

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

    startUser

    public boolean startUser (int userId)

    在后台启动指定用户(如果当前已停止)。如果用户已在后台运行,则此方法为 NOOP。

    参数
    userId int:要在后台启动的用户

    返回
    boolean 如果用户在后台成功启动,则为 true。

    抛出
    DeviceNotAvailableException

    startUser

    public boolean startUser (int userId, 
                    boolean waitFlag)

    在后台启动指定用户(如果当前已停止)。如果用户已在后台运行,则此方法为 NOOP。可以提供额外的标记以等待操作生效。

    参数
    userId int:要在后台启动的用户

    waitFlag boolean:会使该命令等待用户启动并解锁。

    返回
    boolean 如果用户在后台成功启动,则为 true。

    抛出
    DeviceNotAvailableException

    startVisibleBackgroundUser

    public boolean startVisibleBackgroundUser (int userId, 
                    int displayId, 
                    boolean waitFlag)

    在后台启动指定用户,在给定显示屏中处于可见状态(即允许用户在该显示屏上启动 activity)。

    注意 :此命令不会检查用户是否存在、显示可用、device supports such feature 等。

    参数
    userId int:要在后台启动的用户

    displayId int:用于启动用户可见的显示屏

    waitFlag boolean:会使该命令等待用户启动并解锁。

    返回
    boolean 如果用户成功启动,则在后台可见,值为 true

    抛出
    DeviceNotAvailableException

    stopEmulatorOutput

    public void stopEmulatorOutput ()

    关闭并删除模拟器输出。

    停止 Logcat

    public void stopLogcat ()

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

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

    stopUser

    public boolean stopUser (int userId)

    停止指定用户。如果用户已停止,则此方法为 NOOP。无法停止当前用户和系统用户。

    参数
    userId int:要停止的用户。

    返回
    boolean 如果用户被成功停止,则为 true。

    抛出
    DeviceNotAvailableException

    stopUser

    public boolean stopUser (int userId, 
                    boolean waitFlag, 
                    boolean forceFlag)

    停止指定用户。可以提供额外的标记以等待操作生效,并强制终止用户。无法停止当前用户和系统用户。

    参数
    userId int:要停止的用户。

    waitFlag boolean:会使该命令等待用户停止。

    forceFlag boolean:会强行停止用户。

    返回
    boolean 如果用户被成功停止,则为 true。

    抛出
    DeviceNotAvailableException

    switchToAdbTcp

    public String switchToAdbTcp ()

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

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

    抛出
    DeviceNotAvailableException

    switchToAdbUsb

    public boolean switchToAdbUsb ()

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

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

    抛出
    DeviceNotAvailableException

    切换用户

    public boolean switchUser (int userId)

    切换到具有默认超时的另一个 userId。switchUser(int, long).

    参数
    userId int

    返回
    boolean 如果新的 userId 与 userId 提供方匹配,则返回 true。否则为 false。

    抛出
    DeviceNotAvailableException

    切换用户

    public boolean switchUser (int userId, 
                    long timeout)

    切换到另一个以所提供的超时作为截止时间的用户 ID。 更改用户成功后尝试停用键盘锁。

    参数
    userId int

    timeout long:在切换用户失败后返回 false。

    返回
    boolean 如果新的 userId 与 userId 提供方匹配,则返回 true。否则为 false。

    抛出
    DeviceNotAvailableException

    syncFiles

    public 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

    takeBugreport

    public Bugreport takeBugreport ()

    获取 bug 报告并在 Bugreport 对象内返回该报告进行处理。如果出现问题,则返回 null。Bugreport 对象中引用的文件需要通过 Bugreport.close() 进行清理。

    返回
    Bugreport

    removePackage

    public String uninstallPackage (String packageName)

    从设备上卸载 Android 软件包。

    参数
    packageName String:要卸载的 Android 软件包

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    downloadPackageForUser

    public String uninstallPackageForUser (String packageName, 
                    int userId)

    从设备中卸载指定用户的 Android 软件包。

    参数
    packageName String:要卸载的 Android 软件包

    userId int:要卸载的整数用户 ID。

    返回
    String 包含错误代码的 String,如果成功,则为 null

    抛出
    DeviceNotAvailableException

    解锁设备

    public boolean unlockDevice ()

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

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

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

    抛出
    DeviceNotAvailableException

    unmountDebugfs

    public void unmountDebugfs ()

    卸载 debugfs。

    抛出
    DeviceNotAvailableException

    waitForBootComplete

    public boolean waitForBootComplete (long timeOut)

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

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

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

    抛出
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable ()

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

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

    抛出
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable (long waitTime)

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

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

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

    抛出
    DeviceNotAvailableException

    waitForDeviceAvailableInRecoverPath

    public boolean waitForDeviceAvailableInRecoverPath (long waitTime)

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

    参数
    waitTime long

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

    抛出
    DeviceNotAvailableException

    waitForDeviceBootloader

    public void waitForDeviceBootloader ()

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

    抛出
    DeviceNotAvailableException

    等待设备恢复

    public boolean waitForDeviceInRecovery (long waitTime)

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

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

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

    waitForDeviceInSideload

    public boolean waitForDeviceInSideload (long waitTime)

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

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

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

    waitForDeviceNotAvailable

    public boolean waitForDeviceNotAvailable (long waitTime)

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

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

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

    等待设备在线

    public void waitForDeviceOnline ()

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

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

    抛出
    DeviceNotAvailableException

    等待设备在线

    public void waitForDeviceOnline (long waitTime)

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

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

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

    抛出
    DeviceNotAvailableException

    waitForDeviceShell

    public boolean waitForDeviceShell (long waitTime)

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

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

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

    受保护的方法

    addExtraConnectionBuilderArgs

    protected void addExtraConnectionBuilderArgs (DefaultConnection.ConnectionBuilder builder)

    参数
    builder DefaultConnection.ConnectionBuilder

    buildAdbShellCommand

    protected String[] buildAdbShellCommand (String command, 
                    boolean forceExitStatusDetection)

    针对给定的 adb shell 命令会话和参数构建操作系统命令

    参数
    command String

    forceExitStatusDetection boolean

    返回
    String[]

    checkApiLevelAgainst

    protected void checkApiLevelAgainst (String feature, 
                    int strictMinLevel)

    参数
    feature String

    strictMinLevel int

    createRebootDeviceAction

    protected NativeDevice.RebootDeviceAction createRebootDeviceAction (NativeDevice.RebootMode rebootMode, 
                    String reason)

    创建要在执行重新启动操作时使用的 RebootDeviceAction

    参数
    rebootMode NativeDevice.RebootMode:此重新启动的一种模式。

    reason String:用于此次重新启动。

    返回
    NativeDevice.RebootDeviceAction 创建的 RebootDeviceAction

    createRunUtil

    protected IRunUtil createRunUtil ()

    返回
    IRunUtil

    doAdb 重新启动

    protected void doAdbReboot (NativeDevice.RebootMode rebootMode, 
                    String reason)

    执行 adb 重新启动。

    参数
    rebootMode NativeDevice.RebootMode:此重新启动的一种模式。

    reason String:用于此次重新启动。

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

    确保运行时权限受支持

    protected void ensureRuntimePermissionSupported ()

    在不支持运行时权限的情况下抛出异常的辅助方法

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

    getApiLevelSafe

    protected int getApiLevelSafe ()

    返回
    int

    getLogger

    protected ITestLogger getLogger ()

    返回
    ITestLogger

    getRunUtil

    protected IRunUtil getRunUtil ()

    获取要使用的 RunUtil 实例。

    返回
    IRunUtil

    initializeConnection

    protected void initializeConnection (IBuildInfo info, 
                    MultiMap<String, String> attributes)

    参数
    info IBuildInfo

    attributes MultiMap

    抛出
    DeviceNotAvailableException
    TargetSetupError

    internalGetProperty

    protected String internalGetProperty (String propName, 
                    String fastbootVar, 
                    String description)

    默认从 ddmlib 缓存中提取设备属性,并根据设备是否处于 Fastboot 模式,回退到“adb shell getprop”或“fastboot getvar”。

    参数
    propName String:“adb shell getprop”返回的设备属性的名称

    fastbootVar String:要查询的等效 fastboot 变量的名称。如果为 null,则不会尝试 fastboot 查询

    description String:变量的简单说明。第一个字母应大写。

    返回
    String 一个字符串,可能为 null 或为空,包含指定属性的值

    抛出
    DeviceNotAvailableException

    isInRebootCallback(处于重新启动状态)

    protected boolean isInRebootCallback ()

    返回是否正在执行重新启动回调。如果为 true,应停用所有用于重新启动的公共 API。

    返回
    boolean

    较新

    protected boolean isNewer (File localFile, 
                    IFileEntry entry)

    如果本地文件比远程文件更新,则返回 trueIFileEntry 精确到分钟,在相同时间的情况下,文件将被视为较新的文件。

    参数
    localFile File

    entry IFileEntry

    返回
    boolean

    NotificationsRebootEnded(通知重新启动结束)

    protected void notifyRebootEnded ()

    将重新启动结束事件通知给所有 IDeviceActionReceiver

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

    已通知重新启动

    protected void notifyRebootStarted ()

    向所有 IDeviceActionReceiver 通知重新启动开始事件。

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

    执行设备操作

    protected boolean performDeviceAction (String actionDescription, 
                    NativeDevice.DeviceAction action, 
                    int retryAttempts)

    在此设备上执行操作。尝试恢复设备,并可以选择在操作失败时重试命令。

    参数
    actionDescription String:要执行的操作的简短说明。仅用于日志记录目的。

    action NativeDevice.DeviceAction:要执行的操作

    retryAttempts int:如果操作失败但恢复成功,则重新尝试执行操作

    返回
    boolean 如果操作成功,则为 true

    抛出
    DeviceNotAvailableException 在恢复尝试失败或失败次数达到上限后返回

    Adb 重新启动后

    protected void postAdbReboot ()

    重新启动后可能执行的其他操作。

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

    prePostBootSetup

    protected void prePostBootSetup ()

    允许每种设备类型(AndroidNativeDevice、TestDevice)针对特定启动后设置替换此方法。

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

    pullFileInternal

    protected boolean pullFileInternal (String remoteFilePath, 
                    File localFile)

    参数
    remoteFilePath String

    localFile File

    返回
    boolean

    抛出
    DeviceNotAvailableException

    setClock

    protected void setClock (Clock clock)

    设置要使用的时钟实例。

    参数
    clock Clock

    setMicrodroidProcess

    protected void setMicrodroidProcess (Process process)

    将 TestDevice 标记为 Microdroid,并设置其 CID。

    参数
    process Process:Microdroid 虚拟机的进程。

    setTestDeviceOptions

    protected void setTestDeviceOptions ( deviceOptions)

    参数
    deviceOptions

    SimpleFastbootCommand

    protected CommandResult simpleFastbootCommand (long timeout, 
                     envVarMap, 
                    String[] fullCmd)

    执行包含环境变量的简单 fastboot 命令并报告该命令的状态。

    参数
    timeout long

    envVarMap

    fullCmd String

    返回
    CommandResult

    SimpleFastbootCommand

    protected CommandResult simpleFastbootCommand (long timeout, 
                    String[] fullCmd)

    执行一个简单的 fastboot 命令并报告该命令的状态。

    参数
    timeout long

    fullCmd String

    返回
    CommandResult

    waitForDeviceNotAvailable

    protected boolean waitForDeviceNotAvailable (String operationDesc, 
                    long time)

    等待设备不可用(停止向 adb 报告)。

    参数
    operationDesc String:正在等待不可用的操作的名称。

    time long:等待出现不可用的时间。

    返回
    boolean 如果设备变得不可用,则为 true。