NativeDevice
public
class
NativeDevice
extends Object
implements
IConfigurationReceiver,
IManagedTestDevice,
ITestLoggerReceiver
| java.lang.Object | |
| ↳ | com.android.tradefed.device.NativeDevice |
ITestDevice 非全栈 Android 设备的默认实现。
摘要
常量 | |
|---|---|
String |
DEBUGFS_PATH
|
int |
INVALID_USER_ID
针对任何无效/未找到的用户 ID 返回的值:UserHandle 定义了 -10000 值 |
long |
MAX_HOST_DEVICE_TIME_OFFSET
|
int |
MAX_RETRY_ATTEMPTS
要执行的命令重试尝试的默认次数 |
String |
SD_CARD
|
String |
STORAGE_EMULATED
|
字段 | |
|---|---|
protected
TestDeviceOptions |
mOptions
|
protected
final
IDeviceStateMonitor |
mStateMonitor
|
公共构造函数 | |
|---|---|
NativeDevice(IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)
创建 |
|
公共方法 | |
|---|---|
String
|
adbInstallPackage(File packageFile, boolean reinstall, String... extraArgs)
使用 adb 命令在设备上安装 Android 软件包。 |
String
|
adbInstallPackage(File packageFile, boolean reinstall, boolean grantPermissions, String... extraArgs)
使用 adb 命令在设备上安装 Android 软件包。 |
void
|
batchPrefetchStartupBuildProps()
通过预提取所需的所有属性(而不是为每个属性调用“adb getprop”)进行微优化(约 400 毫秒)。 |
boolean
|
canSwitchToHeadlessSystemUser()
返回是否允许切换到无头系统用户。 |
boolean
|
checkApiLevelAgainstNextRelease(int strictMinLevel)
检查在给定的最低支持级别下,某项功能当前是否受支持。 |
boolean
|
checkConnectivity()
检查设备是否已连接到网络。 |
boolean
|
clearErrorDialogs()
尝试关闭当前显示在设备界面上的所有错误对话框。 |
void
|
clearLastConnectedWifiNetwork()
清除上次连接的 WLAN 网络。 |
void
|
clearLogcat()
删除所有累积的 logcat 数据。 |
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkIfNeededWithResult(String wifiSsid, String wifiPsk, boolean scanSsid)
|
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkIfNeededWithResult(String wifiSsid, String wifiPsk)
|
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkWithResult(String wifiSsid, String wifiPsk, boolean scanSsid)
连接到 WLAN 网络。 |
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkWithResult(Map<String, String> wifiSsidToPsk)
连接到 WLAN 网络。 |
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkWithResult(Map<String, String> wifiSsidToPsk, boolean scanSsid)
连接到 WLAN 网络。 |
IWifiHelper.WifiConnectionResult
|
connectToWifiNetworkWithResult(String wifiSsid, String wifiPsk)
连接到 WLAN 网络。 |
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 创建用户。 |
DeviceInspectionResult
|
debugDeviceNotAvailable()
检查设备并在设备变为不可用时返回详细信息。 |
void
|
deleteFile(String deviceFilePath, int userId)
用于删除设备上的文件或目录的辅助方法。 |
void
|
deleteFile(String deviceFilePath)
用于删除设备上的文件或目录的辅助方法。 |
void
|
deregisterDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)
移除已注册的 |
boolean
|
deviceSoftRestarted(ProcessInfo prevSystemServerProcess)
用于通过比较当前 system_server 与之前的 system_server |
boolean
|
deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)
用于检查设备自纪元以来的 UTC 时间(从设备及其 |
boolean
|
disableAdbRoot()
关闭 adb root。 |
void
|
disableKeyguard()
尝试停用锁屏。 |
boolean
|
disableNetworkMonitor()
停用设备上的网络监控。 |
boolean
|
disconnectFromWifi()
断开与 WLAN 网络的连接。 |
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(String... cmdArgs)
一种辅助方法,用于将 adb 命令作为系统命令执行。 |
String
|
executeAdbCommand(long timeout, Map<String, String> envMap, String... cmdArgs)
辅助方法,用于以指定超时时间将 adb 命令作为系统命令执行。 |
CommandResult
|
executeAdbV2Command(String... cmdArgs)
一种辅助方法,用于将 adb 命令作为系统命令执行。 |
CommandResult
|
executeAdbV2Command(long timeout, String... cmdArgs)
辅助方法,用于以指定超时时间将 adb 命令作为系统命令执行。 |
CommandResult
|
executeAdbV2Command(long timeout, Map<String, String> envMap, String... cmdArgs)
辅助方法,用于以指定超时时间将 adb 命令作为系统命令执行。 |
CommandResult
|
executeAdbV2Command(long timeout, Map<String, String> envMap, int retryAttempts, String... cmdArgs)
辅助方法,用于以指定超时时间将 adb 命令作为系统命令执行。 |
CommandResult
|
executeFastbootCommand(String... cmdArgs)
一种辅助方法,用于以系统命令的形式执行 fastboot 命令,默认超时时间为 2 分钟。 |
CommandResult
|
executeFastbootCommand(long timeout, String... cmdArgs)
一种辅助方法,用于以系统命令的形式执行 fastboot 命令。 |
CommandResult
|
executeLongFastbootCommand(String... cmdArgs)
一种辅助方法,用于以系统命令的形式执行长时间运行的 fastboot 命令。 |
CommandResult
|
executeLongFastbootCommand(Map<String, String> envVarMap, String... cmdArgs)
辅助方法,用于以系统命令形式执行长时间运行的 fastboot 命令,并使用系统环境变量。 |
String
|
executeShellCommand(String command)
执行 adb shell 命令并将输出作为 |
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
|
executeShellV2Command(String cmd, File pipeAsInput, OutputStream pipeToOutput, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。 |
CommandResult
|
executeShellV2Command(String cmd, long maxTimeoutForCommand, TimeUnit timeUnit)
执行 adb shell 命令,并使用更多参数来控制命令行为。 |
CommandResult
|
executeShellV2Command(String cmd, File pipeAsInput)
用于执行 adb shell 命令并将结果作为 |
CommandResult
|
executeShellV2Command(String cmd, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。 |
CommandResult
|
executeShellV2Command(String cmd, OutputStream pipeToOutput)
用于执行 adb shell 命令并将结果作为 |
CommandResult
|
executeShellV2Command(String cmd, File pipeAsInput, OutputStream pipeToOutput, OutputStream pipeToError, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。 |
CommandResult
|
executeShellV2Command(String cmd, File pipeAsInput, OutputStream pipeToOutput, OutputStream pipeToError, long maxTimeoutForCommand, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。 |
CommandResult
|
executeShellV2Command(String cmd, IShellOutputReceiver receiver)
用于执行 adb shell 命令并将结果作为 |
CommandResult
|
fastbootOemRamdumpNow()
一种辅助方法,用于从 fastboot 模式触发 ramdump。 |
CommandResult
|
fastbootWipePartition(String partition)
用于擦除设备分区的辅助方法。 |
Set<ITestDevice.ApexInfo>
|
getActiveApexes()
获取有关设备上已激活 APEX 的信息。 |
String
|
getAdbPath()
返回所用 adb 二进制文件的路径。 |
Map<String, String>
|
getAllSettings(String namespace)
返回所请求命名空间的键值对。 |
DeviceAllocationState
|
getAllocationState()
返回设备的当前分配状态 |
String
|
getAndroidId(int userId)
查找并返回与 userId 关联的 android-id,如果未找到,则返回 null。 |
Map<Integer, String>
|
getAndroidIds()
创建了 Android ID 与匹配的用户 ID 的映射。 |
int
|
getApiLevel()
获取设备 API 级别。 |
int
|
getApiLevelFull()
与 |
PackageInfo
|
getAppPackageInfo(String packageName)
提取设备上安装的软件包的相关信息。 |
List<PackageInfo>
|
getAppPackageInfos()
提取设备上安装的软件包的信息。 |
String
|
getBasebandVersion()
用于获取相应设备的基带(无线)版本的便捷方法。 |
Integer
|
getBattery()
返回设备的当前电池电量,如果电池电量不可用,则返回 Null。 |
boolean
|
getBooleanProperty(String name, boolean defaultValue)
返回指定属性的布尔值。 |
Map<Long, String>
|
getBootHistory()
辅助方法,用于收集包含启动时间和启动原因的启动历史记录映射。 |
Map<Long, String>
|
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
|
getCachedDeviceDescriptor(boolean shortDescriptor)
如果设备已分配,则返回缓存的 |
String[]
|
getChildren(String path)
替代方案:使用 |
AbstractConnection
|
getConnection()
与设备关联的当前连接。 |
ContentProviderHandler
|
getContentProvider(int userId)
返回 |
DeviceFoldableState
|
getCurrentFoldableState()
返回设备的当前可折叠状态,如果出现某些问题,则返回 null。 |
int
|
getCurrentUser()
返回当前正在运行的用户的 ID。 |
String
|
getDeviceClass()
获取设备类。 |
long
|
getDeviceDate()
返回设备的日期(以自纪元以来的毫秒数表示)。 |
DeviceDescriptor
|
getDeviceDescriptor()
从设备信息返回 |
DeviceDescriptor
|
getDeviceDescriptor(boolean shortDescriptor)
从设备信息返回 |
TestDeviceState
|
getDeviceState()
获取设备的状态。 |
long
|
getDeviceTimeOffset(Date date)
用于获取设备与指定 |
InputStreamSource
|
getEmulatorOutput()
获取模拟器 stdout 和 stderr 的数据流 |
Process
|
getEmulatorProcess()
返回与此模拟器对应的 |
final
File
|
getExecuteShellCommandLog()
包含所有 |
long
|
getExternalStoreFreeSpace()
用于确定设备外部存储空间可用量的辅助方法。 |
String
|
getFastbootPath()
返回所使用的 fastboot 二进制文件的路径。 |
String
|
getFastbootProductType()
一种便捷方法,用于在设备处于 Fastboot 模式 (Fastboot mode) 时获取其商品类型。 |
String
|
getFastbootProductVariant()
一种便捷方法,用于在设备处于 Fastboot 模式 (Fastboot mode) 时获取其商品类型。 |
String
|
getFastbootSerialNumber()
返回 fastboot 模式序列号。 |
String
|
getFastbootVariable(String variableName)
从设备检索给定的 fastboot 变量值。 |
String
|
getFastbootVersion()
返回所用 fastboot 二进制文件的版本字符串。 |
IFileEntry
|
getFileEntry(String path)
检索对设备上远程文件的引用。 |
IFileEntry
|
getFileEntry(FileListingService.FileEntry entry)
用于从非根路径获取 |
Set<DeviceFoldableState>
|
getFoldableStates()
返回设备上的可折叠状态列表。 |
IDevice
|
getIDevice()
返回对关联 ddmlib |
Set<String>
|
getInstalledPackageNames()
获取设备上存在的应用软件包名称。 |
long
|
getIntProperty(String name, long defaultValue)
从设备返回指定属性的整数值。 |
String
|
getIpAddress()
获取设备的 IP 地址。 |
KeyguardControllerState
|
getKeyguardState()
返回一个对象以获取密钥卫士的当前状态,如果不支持,则返回 null。 |
long
|
getLastExpectedRebootTimeMillis()
返回自纪元以来 Tradefed API 上次触发重新启动的时间(以毫秒为单位),与 |
int
|
getLaunchApiLevel()
获取设备首次发布时所采用的 API 级别。 |
InputStreamSource
|
getLogcat()
获取 logcat 数据的快照流。 |
InputStreamSource
|
getLogcat(int maxBytes)
获取最后 |
InputStreamSource
|
getLogcatDump()
获取设备的当前 logcat 的 dump。 |
InputStreamSource
|
getLogcatSince(long date)
获取从指定日期开始捕获的 logcat 数据的快照流。 |
String
|
getMacAddress()
返回设备的 MAC 地址;如果无法从设备查询,则返回 null。 |
Integer
|
getMainUserId()
返回主用户 ID。 |
Set<String>
|
getMainlineModuleInfo()
获取有关设备上安装的 Mainline 模块的信息。 |
int
|
getMaxNumberOfRunningUsersSupported()
获取支持的同时运行的用户数量上限。 |
int
|
getMaxNumberOfUsersSupported(String userType)
获取给定用户类型的支持用户数量上限。 |
int
|
getMaxNumberOfUsersSupported()
获取支持的可切换用户数量上限,不包括 Guest。 |
Process
|
getMicrodroidProcess()
|
IDeviceStateMonitor
|
getMonitor()
返回与设备关联的 |
String
|
getMountPoint(String mountName)
返回装载点。 |
ITestDevice.MountPointInfo
|
getMountPointInfo(String mountpoint)
返回与指定挂载点路径对应的 |
List<ITestDevice.MountPointInfo>
|
getMountPointInfo()
返回设备上 /proc/mounts 中信息的已解析版本 |
TestDeviceOptions
|
getOptions()
获取设备的测试选项。 |
long
|
getPartitionFreeSpace(String partition)
用于确定设备分区上可用空间量的辅助方法。 |
Integer
|
getPrimaryUserId()
返回主要用户 ID。 |
ProcessInfo
|
getProcessByName(String processName)
辅助方法运行“pidof”和“stat”命令,并返回包含给定进程的 PID 和进程启动时间的 |
String
|
getProcessPid(String process)
返回服务的 PID,如果出现问题,则返回 null。 |
String
|
getProductType()
用于获取相应设备的商品类型的便捷方法。 |
String
|
getProductVariant()
用于获取相应设备的商品款式/规格的便捷方法。 |
String
|
getProperty(String name)
从设备检索给定的属性值。 |
ITestDevice.RecoveryMode
|
getRecoveryMode()
获取设备当前使用的恢复模式。 |
int
|
getRemainingCreatableUserCount(String userType)
返回可在相应设备上创建的指定用户类型的用户数量。 |
InputStreamSource
|
getScreenshot(Long displayId, String format, boolean rescale)
以支持的格式从指定显示屏 ID 的设备中抓取屏幕截图。 |
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)
请参阅 |
String
|
getSimOperator()
返回 SIM 卡运营商;如果不可用或设备不可用,则返回 null。 |
String
|
getSimState()
返回 SIM 卡状态,如果不可用或设备不可用,则返回 null。 |
List<File>
|
getTombstones()
从设备中提取并返回墓碑列表。 |
long
|
getTotalMemory()
返回总物理内存大小(以字节为单位),如果发生内部错误,则返回 -1 |
String
|
getTrackingSerial()
出于设备管理目的,获取用于跟踪设备的序列号。 |
Set<String>
|
getUninstallablePackageNames()
获取可卸载的应用软件包名称。 |
boolean
|
getUseFastbootErase()
获取是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。 |
int
|
getUserFlags(int userId)
查找并返回指定用户的标志。 |
Map<Integer, UserInfo>
|
getUserInfos()
获取设备上 useId 到 |
int
|
getUserSerialNumber(int userId)
如果找到与 userId 关联的序列号,则返回该序列号;否则,返回 -10000。 |
int
|
getUserVisibleOnDisplay(int displayId)
获取指定显示屏上可见用户的用户 ID。 |
IManagedTestDevice.DeviceEventResponse
|
handleAllocationEvent(DeviceEvent event)
处理给定的 DeviceEvent。 处理 DeviceEvent,这可能会也可能不会将设备转换为新的分配状态。 |
boolean
|
hasFeature(String feature)
检查设备上是否提供某项功能。 |
void
|
initializeConnection(IBuildInfo info, MultiMap<String, String> attributes)
初始化与设备的连接。 |
String
|
installPackage(File packageFile, boolean reinstall, boolean grantPermissions, String... extraArgs)
在设备上安装 Android 软件包。 |
String
|
installPackage(File packageFile, boolean reinstall, String... extraArgs)
在设备上安装 Android 软件包。 |
String
|
installPackageForUser(File packageFile, boolean reinstall, boolean grantPermissions, int userId, String... extraArgs)
在设备上为指定用户安装 Android 软件包。 |
String
|
installPackageForUser(File packageFile, boolean reinstall, int userId, String... extraArgs)
在设备上为指定用户安装 Android 软件包。 |
boolean
|
installPackageWithIncrementalMode(File[] apkFiles, String[] extraArgs, String userId)
以增量模式安装 APK。 |
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,则返回 true。 |
boolean
|
isHeadless()
如果设备是无头设备(没有屏幕),则返回 true,否则返回 false。 |
boolean
|
isHeadlessSystemUserMode()
返回设备是否使用无头系统用户模式。 |
boolean
|
isMainUserPermanentAdmin()
返回主用户是否为永久管理员,且无法删除或降级为非管理员状态。 |
boolean
|
isMultiUserSupported()
返回相应设备是否支持多个可切换的用户,这些用户拥有各自的登录信息和可自定义的空间。 |
boolean
|
isPackageInstalled(String packageName, String userId)
查询设备上指定软件包名称和指定用户 ID 的应用,以检查该应用是否已安装在相应用户下。 |
boolean
|
isPackageInstalled(String packageName)
查询设备上是否存在指定软件包名称,以检查该软件包是否已安装。 |
boolean
|
isRuntimePermissionSupported()
检查设备上的平台是否支持运行时权限授予 |
boolean
|
isShellV2Support()
|
boolean
|
isStateBootloaderOrFastbootd()
如果设备处于 |
boolean
|
isUserRunning(int userId)
检查指定用户是否正在运行。 |
boolean
|
isUserSecondary(int userId)
根据指定用户的标志返回该用户是否为次要用户。 |
boolean
|
isUserVisible(int userId)
检查指定用户是否可见。 |
boolean
|
isUserVisibleOnDisplay(int userId, int displayId)
检查指定用户是否在指定显示屏中可见。 |
boolean
|
isVisibleBackgroundUsersOnDefaultDisplaySupported()
返回设备是否允许用户在 |
boolean
|
isVisibleBackgroundUsersSupported()
返回设备是否允许用户在后台启动可见的 activity。 |
boolean
|
isWifiEnabled()
测试 Wi-Fi 是否已启用。 |
Set<Long>
|
listDisplayIds()
收集设备上“dumpsys SurfaceFlinger”报告的可用显示屏 ID 列表。 |
Set<Integer>
|
listDisplayIdsForStartingVisibleBackgroundUsers()
获取可用于 |
ArrayList<Integer>
|
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
|
pullDir(String deviceFilePath, File localDir, int userId, long timeout)
以递归方式从设备拉取目录内容。 |
boolean
|
pullFile(String remoteFilePath, File localFile, int userId, long timeout)
从设备中检索文件。 |
boolean
|
pullFile(String remoteFilePath, File localFile)
从设备中检索文件。 |
File
|
pullFile(String remoteFilePath, int userId)
从设备中检索文件,将其存储在本地临时 |
File
|
pullFile(String remoteFilePath)
从设备中检索文件,将其存储在本地临时 |
boolean
|
pullFile(String remoteFilePath, File localFile, int userId)
从设备中检索文件。 |
String
|
pullFileContents(String remoteFilePath)
从设备中检索文件,并返回内容。 |
File
|
pullFileFromExternal(String remoteFilePath)
一种便捷方法,用于从设备的外部存储空间检索文件,将其存储在本地临时 |
boolean
|
pushDir(File localFileDir, String deviceFilePath, int userId)
以递归方式将目录内容推送到设备。 |
boolean
|
pushDir(File localFileDir, String deviceFilePath, Set<String> excludedDirectories)
以递归方式将目录内容推送到设备,同时排除一些已过滤的目录。 |
boolean
|
pushDir(File localFileDir, String deviceFilePath)
以递归方式将目录内容推送到设备。 |
boolean
|
pushFile(File localFile, String remoteFilePath, boolean evaluateContentProviderNeeded)
|
boolean
|
pushFile(File localFile, String remoteFilePath)
将文件推送到设备。 |
boolean
|
pushFile(File localFile, String remoteFilePath, int userId)
将文件推送到设备。 |
boolean
|
pushString(String contents, String remoteFilePath)
将从字符串创建的文件推送到设备 |
void
|
reboot(String reason)
将设备重新启动到 adb 模式,并使给定的 |
String
|
reboot(String command, String reason)
使用给定的 |
void
|
reboot()
将设备重新启动到 adb 模式。 |
void
|
rebootIntoBootloader()
将设备重新启动到引导加载程序模式。 |
void
|
rebootIntoFastbootd()
将设备重新启动到 fastbootd 模式。 |
void
|
rebootIntoRecovery()
将设备重新启动到 adb 恢复模式。 |
void
|
rebootIntoSideload()
将设备重新启动到 adb 旁加载模式(请注意,这是恢复模式下的一种特殊模式) 阻塞,直到设备进入旁加载模式 |
void
|
rebootIntoSideload(boolean autoReboot)
将设备重新启动到 adb 旁加载模式(请注意,这是恢复模式下的一种特殊模式) 阻塞,直到设备进入旁加载模式 |
void
|
rebootUntilOnline()
|
void
|
rebootUntilOnline(String reason)
|
void
|
rebootUserspace()
仅重启设备的用户空间部分。 |
void
|
rebootUserspaceUntilOnline()
|
boolean
|
recoverDevice()
尝试恢复设备通信。 |
void
|
registerDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)
为相应设备注册 |
void
|
remountSystemReadOnly()
将设备上的系统分区设为只读。 |
void
|
remountSystemWritable()
使设备上的 system 分区可写入。 |
void
|
remountVendorReadOnly()
将设备上的供应商分区设为只读。 |
void
|
remountVendorWritable()
使设备上的供应商分区可写入。 |
boolean
|
removeAdmin(String componentName, int userId)
移除指定用户中的指定设备管理员,如果成功,则返回 |
void
|
removeOwners()
尽最大努力移除所有现有的设备配置文件所有者。 |
boolean
|
removeUser(int userId)
从设备中移除指定用户。 |
void
|
resetContentProviderSetup()
重置内容提供方设置的标志,以便再次触发该设置。 |
boolean
|
runInstrumentationTests(IRemoteAndroidTestRunner runner, Collection<ITestLifeCycleReceiver> listeners)
运行插桩测试,并提供设备恢复功能。 |
boolean
|
runInstrumentationTests(IRemoteAndroidTestRunner runner, ITestLifeCycleReceiver... listeners)
一种便捷方法,用于执行 |
boolean
|
runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId, Collection<ITestLifeCycleReceiver> listeners)
与 |
boolean
|
runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId, ITestLifeCycleReceiver... listeners)
与 |
void
|
setAdbPath(String adbPath)
设置应使用的 adb 二进制文件的路径。 |
void
|
setConfiguration(IConfiguration configuration)
注入正在使用的 |
final
void
|
setConnectionAvdInfo(GceAvdInfo avdInfo)
|
void
|
setDate(Date date)
设置设备上的日期 注意:在设备上设置日期需要 root 权限 |
boolean
|
setDeviceOwner(String componentName, int userId)
在指定用户中将设备管理员组件设置为设备所有者。 |
void
|
setDeviceState(TestDeviceState deviceState)
更新设备的状态。 |
void
|
setEmulatorOutputStream(SizeLimitedOutputStream output)
对于模拟器,请将 |
void
|
setEmulatorProcess(Process p)
当相应设备为模拟器时,设置 |
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)
为设备设置 |
boolean
|
setProperty(String propKey, String propValue)
在设备上设置给定的属性值。 |
void
|
setRecovery(IDeviceRecovery recovery)
设置要用于此设备的 |
void
|
setRecoveryMode(ITestDevice.RecoveryMode mode)
设置设备要使用的当前恢复模式。 |
void
|
setSetting(String namespace, String key, String value)
请参阅 |
void
|
setSetting(int userId, String namespace, String key, String value)
向指定用户的命名空间添加设置值。 |
void
|
setTestLogger(ITestLogger testLogger)
注入 |
void
|
setTrackingSerial(String trackingSerial)
出于设备管理目的,跟踪我们用于引用设备的序列号。 |
void
|
setUseFastbootErase(boolean useFastbootErase)
设置是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。 |
void
|
startLogcat()
在后台开始捕获设备的 logcat 输出。 |
boolean
|
startTradeInModeTesting(int timeoutMs)
启用测试以旧换新模式。 |
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 数据。 |
void
|
stopTradeInModeTesting()
停止以旧换新模式测试。 |
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)
切换到另一个 userId,并将提供的超时时间作为截止时间。 |
boolean
|
syncFiles(File localFileDir, String deviceFilePath)
将本地文件目录的内容增量同步到设备。 |
Bugreport
|
takeBugreport()
获取 bug 报告并将其返回到 |
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 可见。 |
void
|
waitForDeviceFastbootD()
|
boolean
|
waitForDeviceInRecovery(long waitTime)
设备处于“adb recovery”状态时(请注意,这与 |
boolean
|
waitForDeviceInSideload(long waitTime)
阻塞,直到设备处于“adb sideload”状态 |
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, boolean oldShellCommand)
为给定的 adb shell 命令会话和实参构建操作系统命令 |
void
|
checkApiLevelAgainst(String feature, int strictMinLevel)
|
NativeDevice.RebootDeviceAction
|
createRebootDeviceAction(NativeDevice.RebootMode rebootMode, String reason)
创建在执行重新启动操作时使用的 |
IRunUtil
|
createRunUtil()
|
void
|
doAdbReboot(NativeDevice.RebootMode rebootMode, String reason)
执行 adb reboot。 |
void
|
ensureRuntimePermissionSupported()
如果不支持运行时权限,则抛出异常的辅助方法 |
int
|
getApiLevelSafe()
|
ITestLogger
|
getLogger()
|
IRunUtil
|
getRunUtil()
获取要使用的 |
String
|
internalGetProperty(String propName, String fastbootVar, String description)
从 ddmlib 缓存中(默认)提取设备属性,并根据设备是否处于 Fastboot 模式,回退到 `adb shell getprop` 或 `fastboot getvar`。 |
boolean
|
isInRebootCallback()
返回重新启动回调当前是否正在执行。 |
boolean
|
isNewer(File localFile, IFileEntry entry)
如果本地文件比远程文件新,则返回 |
void
|
notifyRebootEnded()
向所有 |
void
|
notifyRebootStarted()
向所有 |
boolean
|
performDeviceAction(String actionDescription, NativeDevice.DeviceAction action, int retryAttempts)
在此设备上执行操作。 |
void
|
postAdbReboot(NativeDevice.RebootMode rebootMode)
重启后可能采取的额外操作。 |
void
|
prePostBootSetup()
允许每种设备类型(AndroidNativeDevice、TestDevice)替换此方法以进行特定的启动后设置。 |
boolean
|
pullFileWithAdbCommand(String remoteFilePath, File localFile, long timeout)
|
void
|
setClock(Clock clock)
设置要使用的 Clock 实例。 |
void
|
setMicrodroidProcess(Process process)
将 TestDevice 标记为 microdroid 并设置其 CID。 |
void
|
setTestDeviceOptions(Map<String, String> deviceOptions)
|
CommandResult
|
simpleFastbootCommand(long timeout, String[] fullCmd)
执行简单的 fastboot 命令并报告命令的状态。 |
CommandResult
|
simpleFastbootCommand(long timeout, Map<String, String> envVarMap, String[] fullCmd)
使用环境变量执行简单的 fastboot 命令,并报告该命令的状态。 |
boolean
|
waitForDeviceNotAvailable(String operationDesc, long time)
等待设备变为不可用状态(停止向 adb 报告)。 |
常量
DEBUGFS_PATH
public static final String DEBUGFS_PATH
常量值: “/sys/kernel/debug”
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)
SD_CARD
protected static final String SD_CARD
常量值: "/sdcard/"
STORAGE_EMULATED
protected static final String STORAGE_EMULATED
常量值: "/storage/emulated/"
字段
公共构造函数
NativeDevice
public NativeDevice (IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)
创建 TestDevice。
| 参数 | |
|---|---|
device |
IDevice:关联的 IDevice |
stateMonitor |
IDeviceStateMonitor:要使用的 IDeviceStateMonitor 机制 |
allocationMonitor |
IDeviceMonitor:用于通知分配状态变化的 IDeviceMonitor。
可以为 null |
公共方法
adbInstallPackage
public String adbInstallPackage (File packageFile,
boolean reinstall,
String... extraArgs)使用 adb 命令在设备上安装 Android 软件包。
| 参数 | |
|---|---|
packageFile |
File:要安装的 APK 文件 |
reinstall |
boolean:如果应执行重新安装,则为 true |
extraArgs |
String:要传递的可选额外实参。如需了解可用的选项,请参阅“adb shell pm -h”。 |
| 返回 | |
|---|---|
String |
一个包含错误代码的 String,如果成功则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
adbInstallPackage
public String adbInstallPackage (File packageFile,
boolean reinstall,
boolean grantPermissions,
String... extraArgs)使用 adb 命令在设备上安装 Android 软件包。
注意:只有需要在安装时明确控制授予运行时权限的使用情形才应调用此函数。
| 参数 | |
|---|---|
packageFile |
File:要安装的 APK 文件 |
reinstall |
boolean:如果应执行重新安装,则为 true |
grantPermissions |
boolean:是否应在安装时授予所有运行时权限 |
extraArgs |
String:要传递的可选额外实参。如需了解可用的选项,请参阅“adb shell pm -h”。 |
| 返回 | |
|---|---|
String |
一个包含错误代码的 String,如果成功则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
batchPrefetchStartupBuildProps
public void batchPrefetchStartupBuildProps ()
通过预提取所需的所有属性(而不是为每个属性调用“adb getprop”)进行微优化(约 400 毫秒)。也就是说,提取所有属性与提取一个属性一样快。 device.getApiLevel()、checkApiLevelAgainstNextRelease 和 getBuildAlias 等方法在底层都会调用 `adb getprop`。我们通过一次调用来获取它们,并调用 NativeDevice.setProperty。即使我们不这样做,NativeDevice 本身也会调用 setProperty 并缓存结果以供日后调用。我们只是提前了一点时间。如果设备处于恢复状态或在提取属性时出现其他错误,我们只需忽略这些错误。
canSwitchToHeadlessSystemUser
public boolean canSwitchToHeadlessSystemUser ()
返回是否允许切换到无头系统用户。
| 返回 | |
|---|---|
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 之后等)生成的日志数据,此方法非常有用。
connectToWifiNetworkIfNeededWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkIfNeededWithResult (String wifiSsid, String wifiPsk, boolean scanSsid)
一种仅在设备当前没有网络连接时才连接的 connectToWifiNetwork(String,String) 变体。
| 参数 | |
|---|---|
scanSsid |
boolean:是否扫描此网络的隐藏 SSID |
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
connectToWifiNetworkIfNeededWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkIfNeededWithResult (String wifiSsid, String wifiPsk)
一种仅在设备当前没有网络连接时才连接的 connectToWifiNetwork(String,String) 变体。
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
connectToWifiNetworkWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkWithResult (String wifiSsid, String wifiPsk, boolean scanSsid)
连接到 WLAN 网络。
开启 wifi 并阻塞,直到成功连接到指定的 wifi 网络。建立连接后,实例会在每次重新启动后尝试恢复连接,直到调用 ITestDevice.disconnectFromWifi() 或 ITestDevice.clearLastConnectedWifiNetwork()。
| 参数 | |
|---|---|
wifiSsid |
String:要连接的 WiFi SSID |
wifiPsk |
String:PSK 密码,如果未加密,则为 null |
scanSsid |
boolean:是否扫描此网络的隐藏 SSID。 |
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
connectToWifiNetworkWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkWithResult (Map<String, String> wifiSsidToPsk)
连接到 WLAN 网络。
开启 Wi-Fi 并阻塞,直到成功连接到 wifiSsidToPsk 映射中给定的某个 Wi-Fi 网络。建立连接后,实例会在每次重新启动后尝试恢复连接,直到调用 ITestDevice.disconnectFromWifi() 或 ITestDevice.clearLastConnectedWifiNetwork()。
| 参数 | |
|---|---|
wifiSsidToPsk |
Map:一个将 Wi-Fi SSID 映射到密码的映射。 |
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
connectToWifiNetworkWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkWithResult (Map<String, String> wifiSsidToPsk, boolean scanSsid)
连接到 WLAN 网络。
开启 Wi-Fi 并阻塞,直到成功连接到 wifiSsidToPsk 映射中给定的某个 Wi-Fi 网络。建立连接后,实例会在每次重新启动后尝试恢复连接,直到调用 ITestDevice.disconnectFromWifi() 或 ITestDevice.clearLastConnectedWifiNetwork()。
| 参数 | |
|---|---|
wifiSsidToPsk |
Map:一个将 Wi-Fi SSID 映射到密码的映射。 |
scanSsid |
boolean:是否扫描此网络的隐藏 SSID。 |
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
connectToWifiNetworkWithResult
public IWifiHelper.WifiConnectionResult connectToWifiNetworkWithResult (String wifiSsid, String wifiPsk)
连接到 WLAN 网络。
开启 wifi 并阻塞,直到成功连接到指定的 wifi 网络。建立连接后,实例会在每次重新启动后尝试恢复连接,直到调用 ITestDevice.disconnectFromWifi() 或 ITestDevice.clearLastConnectedWifiNetwork()。
| 参数 | |
|---|---|
wifiSsid |
String:要连接的 WiFi SSID |
wifiPsk |
String:PSK 密码,如果未加密,则为 null |
| 返回 | |
|---|---|
IWifiHelper.WifiConnectionResult |
WifiConnectionResult 表示连接的状态。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
createUser
public int createUser (String name,
boolean guest,
boolean ephemeral)使用给定的名称和提供的标志创建用户
| 参数 | |
|---|---|
name |
String:要在设备上创建的用户的 |
guest |
boolean:在创建期间启用用户标志 --guest |
ephemeral |
boolean:在创建期间启用用户标志 --ephemeral |
| 返回 | |
|---|---|
int |
所创建用户的 ID |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
IllegalStateException |
|
createUser
public int createUser (String name,
boolean guest,
boolean ephemeral,
boolean forTesting)使用给定的名称和提供的标志创建用户
| 参数 | |
|---|---|
name |
String:要在设备上创建的用户的 |
guest |
boolean:在创建期间启用用户标志 --guest |
ephemeral |
boolean:在创建期间启用用户标志 --ephemeral |
forTesting |
boolean:在创建期间启用测试标志 --for-testing |
| 返回 | |
|---|---|
int |
所创建用户的 ID |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
IllegalStateException |
|
createUser
public int createUser (String name)
创建具有指定名称和默认标志 0 的用户。
| 参数 | |
|---|---|
name |
String:要在设备上创建的用户的 |
| 返回 | |
|---|---|
int |
创建的用户 ID 的整数 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
IllegalStateException |
|
createUserNoThrow
public int createUserNoThrow (String name)
创建具有指定名称和默认标志 0 的用户。
| 参数 | |
|---|---|
name |
String:要在设备上创建的用户的 |
| 返回 | |
|---|---|
int |
创建的用户 ID 的整数,如果出错则为 -1。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
debugDeviceNotAvailable
public DeviceInspectionResult debugDeviceNotAvailable ()
检查设备,并在设备不可用时返回详细信息。
| 返回 | |
|---|---|
DeviceInspectionResult |
|
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。 |
deviceSoftRestarted
public boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)
用于通过比较当前 system_server 与之前的 system_server ProcessInfo 来检查设备是否软重启的辅助方法。使用getProcessByName(String)付款,可优惠 ProcessInfo。
| 参数 | |
|---|---|
prevSystemServerProcess |
ProcessInfo:之前的 system_server 进程 ProcessInfo。 |
| 返回 | |
|---|---|
boolean |
true 如果设备软重启 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
deviceSoftRestartedSince
public boolean deviceSoftRestartedSince (long utcEpochTime,
TimeUnit timeUnit)辅助方法,用于检查设备自其 TimeUnit 以来是否已软重启。软重启是指在设备硬重启(例如:请求的重启)之外重新启动 system_server。可以通过方法 getDeviceDate() 获取当前设备的 utcEpochTime(以毫秒为单位)。
| 参数 | |
|---|---|
utcEpochTime |
long:设备时间(以自纪元以来的秒数表示)。 |
timeUnit |
TimeUnit:指定 utcEpochTime 的时间单位 TimeUnit。 |
| 返回 | |
|---|---|
boolean |
true 如果设备软重启 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
disableAdbRoot
public boolean disableAdbRoot ()
关闭 adb root。
停用 adb root 可能会导致设备与 adb 断开连接。此方法将阻塞,直到设备可用为止。
| 返回 | |
|---|---|
boolean |
如果成功,则为 true。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
disableKeyguard
public void disableKeyguard ()
尝试停用锁屏。
首先等待输入调度准备就绪,这大约发生在设备报告 BOOT_COMPLETE 的同时,但显然是异步的,因为当前框架实现偶尔会出现竞态条件。然后,系统会发送命令来关闭锁屏(仅适用于不安全的锁屏)
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
disableNetworkMonitor
public boolean disableNetworkMonitor ()
停用设备上的网络监控功能。
| 返回 | |
|---|---|
boolean |
如果成功停用监控,则为 true。如果失败,则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
disconnectFromWifi
public boolean disconnectFromWifi ()
断开与 WLAN 网络的连接。
从已知网络列表中移除所有网络,并停用 Wi-Fi。
| 返回 | |
|---|---|
boolean |
如果已成功断开与 WLAN 网络的连接,则为 true。如果断开连接失败,则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
doesFileExist
public boolean doesFileExist (String deviceFilePath,
int userId)用于确定设备上是否存在指定用户的文件的辅助方法。
| 参数 | |
|---|---|
deviceFilePath |
String:要检查的设备上文件的绝对路径 |
userId |
int:要检查文件是否存在所针对的用户 ID |
| 返回 | |
|---|---|
boolean |
如果文件存在,则为 true;否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
doesFileExist
public boolean doesFileExist (String deviceFilePath)
用于确定设备上是否存在文件的辅助方法。
| 参数 | |
|---|---|
deviceFilePath |
String:要检查的设备上文件的绝对路径 |
| 返回 | |
|---|---|
boolean |
如果文件存在,则为 true;否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
dumpHeap
public File dumpHeap (String process,
String devicePath)尝试从 system_server 转储堆。调用者负责清理转储的文件。
| 参数 | |
|---|---|
process |
String:要执行 dumpheap 的设备进程的名称。 |
devicePath |
String:设备上用于放置 dump 的路径。此位置必须是权限允许的位置。 |
| 返回 | |
|---|---|
File |
包含报告的 File。如果出现故障,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
enableAdbRoot
public boolean enableAdbRoot ()
开启 adb root。如果“enable-root”设置是“false”,则会记录一条消息并返回,而不启用 root 权限。
启用 adb root 可能会导致设备与 adb 断开连接。此方法将阻塞,直到设备可用为止。
| 返回 | |
|---|---|
boolean |
如果成功,则为 true。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
enableNetworkMonitor
public boolean enableNetworkMonitor ()
在设备上启用网络监控。
| 返回 | |
|---|---|
boolean |
如果成功启用监控,则为 true。如果失败,则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbCommand
public String executeAdbCommand (long timeout,
String... cmdArgs)辅助方法,用于以指定超时时间执行 adb 命令作为系统命令。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
timeout |
long:设备被视为无响应之前的等待时间(以毫秒为单位),0L 表示无超时 |
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
String |
命令的 stdout。如果命令执行失败,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbCommand
public String executeAdbCommand (String... cmdArgs)
一种辅助方法,用于将 adb 命令作为系统命令执行。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
String |
命令的 stdout。如果命令执行失败,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbCommand
public String executeAdbCommand (long timeout,
Map<String, String> envMap,
String... cmdArgs)辅助方法,用于以指定超时时间执行 adb 命令作为系统命令。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
timeout |
long:设备被视为无响应之前的等待时间(以毫秒为单位),0L 表示无超时 |
envMap |
Map:要为命令设置的环境 |
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
String |
命令的 stdout。如果命令执行失败,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbV2Command
public CommandResult executeAdbV2Command (String... cmdArgs)
一种辅助方法,用于将 adb 命令作为系统命令执行。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbV2Command
public CommandResult executeAdbV2Command (long timeout, String... cmdArgs)
辅助方法,用于以指定超时时间执行 adb 命令作为系统命令。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
timeout |
long:设备被视为无响应之前的等待时间(以毫秒为单位),0L 表示无超时 |
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbV2Command
public CommandResult executeAdbV2Command (long timeout, Map<String, String> envMap, String... cmdArgs)
辅助方法,用于以指定超时时间执行 adb 命令作为系统命令。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
timeout |
long:设备被视为无响应之前的等待时间(以毫秒为单位),0L 表示无超时 |
envMap |
Map:要为命令设置的环境 |
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeAdbV2Command
public CommandResult executeAdbV2Command (long timeout, Map<String, String> envMap, int retryAttempts, String... cmdArgs)
辅助方法,用于以指定超时时间执行 adb 命令作为系统命令。
应尽可能改用 executeShellCommand(String),因为该方法可提供更好的故障检测和性能。
| 参数 | |
|---|---|
timeout |
long:设备被视为无响应之前的等待时间(以毫秒为单位),0L 表示无超时 |
envMap |
Map:要为命令设置的环境 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
cmdArgs |
String:要运行的 adb 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeFastbootCommand
public CommandResult executeFastbootCommand (String... cmdArgs)
辅助方法,用于以系统命令的形式执行 fastboot 命令,默认超时时间为 2 分钟。
预计在设备已处于 fastboot 模式时使用。
| 参数 | |
|---|---|
cmdArgs |
String:要运行的 fastboot 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
executeFastbootCommand
public CommandResult executeFastbootCommand (long timeout, String... cmdArgs)
一种辅助方法,用于以系统命令的形式执行 fastboot 命令。
预计在设备已处于 fastboot 模式时使用。
| 参数 | |
|---|---|
timeout |
long:命令失效前的剩余时间(以毫秒为单位) |
cmdArgs |
String:要运行的 fastboot 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
executeLongFastbootCommand
public CommandResult executeLongFastbootCommand (String... cmdArgs)
一种辅助方法,用于以系统命令的形式执行长时间运行的 fastboot 命令。
与 executeFastbootCommand(String...) 相同,但使用更长的超时时间。
| 参数 | |
|---|---|
cmdArgs |
String:要运行的 fastboot 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
executeLongFastbootCommand
public CommandResult executeLongFastbootCommand (Map<String, String> envVarMap, String... cmdArgs)
辅助方法,用于以系统命令形式执行长时间运行的 fastboot 命令,并使用系统环境变量。
与 executeFastbootCommand(String...) 相同,但使用更长的超时时间。
| 参数 | |
|---|---|
envVarMap |
Map:运行 fastboot 命令时使用的系统环境变量 |
cmdArgs |
String:要运行的 fastboot 命令和实参 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
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 |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
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 |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellCommand
public void executeShellCommand (String command,
IShellOutputReceiver receiver)执行给定的 adb shell 命令,如果命令失败,则重试多次。
一种具有默认值的更简单的 executeShellCommand(String,IShellOutputReceiver,long,TimeUnit,int) 形式。
| 参数 | |
|---|---|
command |
String:要运行的 adb shell 命令 |
receiver |
IShellOutputReceiver:用于将 shell 输出定向到的 IShellOutputReceiver。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd)
用于执行 adb shell 命令并将结果作为 CommandResult 返回的辅助方法,该 CommandResult 会正确填充命令状态输出、标准输出和标准错误。
| 参数 | |
|---|---|
cmd |
String:应运行的命令。 |
| 返回 | |
|---|---|
CommandResult |
CommandResult中的结果。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, File pipeAsInput, OutputStream pipeToOutput, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。
| 参数 | |
|---|---|
cmd |
String:要运行的 adb shell 命令 |
pipeAsInput |
File:将通过管道作为命令输入传递的 File,或 null。 |
pipeToOutput |
OutputStream:标准输出将重定向到的 OutputStream,或 null。 |
maxTimeoutForCommand |
long:命令完成的最长超时时间;单位如 timeUnit 中所指定 |
timeUnit |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, long maxTimeoutForCommand, TimeUnit timeUnit)
执行 adb shell 命令,并使用更多参数来控制命令行为。
| 参数 | |
|---|---|
cmd |
String:要运行的 adb shell 命令 |
maxTimeoutForCommand |
long:命令完成的最长超时时间;单位如 timeUnit 中所指定 |
timeUnit |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, File pipeAsInput)
用于执行 adb shell 命令并将结果作为 CommandResult 返回的辅助方法,该 CommandResult 已正确填充命令状态输出、标准输出和标准错误。
| 参数 | |
|---|---|
cmd |
String:应运行的命令。 |
pipeAsInput |
File:将通过管道作为命令输入传递的 File,或 null。 |
| 返回 | |
|---|---|
CommandResult |
CommandResult中的结果。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。
| 参数 | |
|---|---|
cmd |
String:要运行的 adb shell 命令 |
maxTimeoutForCommand |
long:命令完成的最长超时时间;单位如 timeUnit 中所指定 |
timeUnit |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, OutputStream pipeToOutput)
用于执行 adb shell 命令并将结果作为 CommandResult 返回的辅助方法,该 CommandResult 已正确填充命令状态输出和 stderr。stdout 会定向到指定的流。
| 参数 | |
|---|---|
cmd |
String:应运行的命令。 |
pipeToOutput |
OutputStream:标准输出将重定向到的 OutputStream,或 null。 |
| 返回 | |
|---|---|
CommandResult |
CommandResult中的结果。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
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:将通过管道作为命令输入传递的 File,或 null。 |
pipeToOutput |
OutputStream:标准输出将重定向到的 OutputStream,或 null。 |
pipeToError |
OutputStream:标准错误将重定向到的 OutputStream,或 null。 |
maxTimeoutForCommand |
long:命令完成的最长超时时间;单位如 timeUnit 中所指定 |
timeUnit |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, File pipeAsInput, OutputStream pipeToOutput, OutputStream pipeToError, long maxTimeoutForCommand, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
执行 adb shell 命令,并使用更多参数来控制命令行为。
| 参数 | |
|---|---|
cmd |
String:要运行的 adb shell 命令 |
pipeAsInput |
File:将通过管道作为命令输入传递的 File,或 null。 |
pipeToOutput |
OutputStream:标准输出将重定向到的 OutputStream,或 null。 |
pipeToError |
OutputStream:标准错误将重定向到的 OutputStream,或 null。 |
maxTimeoutForCommand |
long:命令完成的最长超时时间;单位如 timeUnit 中所指定 |
maxTimeToOutputShellResponse |
long:允许命令在最长多长时间内不输出任何响应;单位如 timeUnit 中所指定 |
timeUnit |
TimeUnit:maxTimeToOutputShellResponse 的单位 |
retryAttempts |
int:如果命令因异常而失败,则重试命令的最大次数。如果 retryAttempts 未成功执行,系统会抛出 DeviceNotResponsiveException。 |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, IShellOutputReceiver receiver)
用于执行 adb shell 命令并将结果作为 CommandResult 返回的辅助方法,该 CommandResult 会正确填充命令状态输出、标准输出和标准错误。
| 参数 | |
|---|---|
cmd |
String:应运行的命令。 |
receiver |
IShellOutputReceiver:用于将 shell 输出定向到的 IShellOutputReceiver。 |
| 返回 | |
|---|---|
CommandResult |
CommandResult中的结果。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
fastbootOemRamdumpNow
public CommandResult fastbootOemRamdumpNow ()
一种辅助方法,用于从 fastboot 模式触发 ramdump。
此方法会执行“oem ramdump now”命令。与 ERROR(/#executeFastbootCommand()) 不同,如果命令失败或状态无效,它不会尝试重试或设备恢复,因为设备崩溃是预期结果。
预计在设备已处于 fastboot 模式时使用。
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
fastbootWipePartition
public CommandResult fastbootWipePartition (String partition)
用于擦除设备分区的辅助方法。
如果 getUseFastbootErase() 为 true,则将使用 fastboot erase 来擦除分区。然后,设备必须在下次启动时创建文件系统。
否则,系统会使用 fastboot format 在设备上创建新的文件系统。
预计在设备已处于 fastboot 模式时使用。
| 参数 | |
|---|---|
partition |
String:要擦除的分区 |
| 返回 | |
|---|---|
CommandResult |
包含命令输出的 CommandResult |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getActiveApexes
public Set<ITestDevice.ApexInfo> getActiveApexes ()
提取设备上已激活的 APEX 的相关信息。
| 返回 | |
|---|---|
Set<ITestDevice.ApexInfo> |
Set 个(共 ApexInfo 个)目前已在设备上激活 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getAdbPath
public String getAdbPath ()
返回所用 adb 二进制文件的路径。
| 返回 | |
|---|---|
String |
|
getAllSettings
public Map<String, String> getAllSettings (String namespace)
返回所请求命名空间的键值对。
| 参数 | |
|---|---|
namespace |
String:必须是 {"system", "secure", "global"} 之一 |
| 返回 | |
|---|---|
Map<String, String> |
键值对的映射。如果不支持命名空间,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getAllocationState
public DeviceAllocationState getAllocationState ()
返回设备的当前分配状态
| 返回 | |
|---|---|
DeviceAllocationState |
|
getAndroidId
public String getAndroidId (int userId)
查找并返回与 userId 关联的 android-id,如果未找到,则返回 null。
| 参数 | |
|---|---|
userId |
int |
| 返回 | |
|---|---|
String |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getAndroidIds
public Map<Integer, String> getAndroidIds ()
创建了 Android ID 与匹配的用户 ID 的映射。无法保证每个用户 ID 都能在此函数中找到关联的 Android ID,因此某些用户 ID 可能会匹配到 null。
| 返回 | |
|---|---|
Map<Integer, String> |
找到的与用户 ID 匹配的 Android ID 的映射。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getApiLevel
public int getApiLevel ()
获取设备 API 级别。默认为 UNKNOWN_API_LEVEL。
| 返回 | |
|---|---|
int |
一个整数,用于指示设备的 API 级别 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getApiLevelFull
public int getApiLevelFull ()
类似于 getApiLevel(),但会返回完整版本。
| 返回 | |
|---|---|
int |
一个整数,用于指示设备的完整 API 级别 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getAppPackageInfo
public PackageInfo getAppPackageInfo (String packageName)
提取设备上安装的软件包的相关信息。
| 参数 | |
|---|---|
packageName |
String |
| 返回 | |
|---|---|
PackageInfo |
如果无法检索信息,则为 PackageInfo 或 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getAppPackageInfos
public List<PackageInfo> getAppPackageInfos ()
提取设备上安装的软件包的信息。
| 返回 | |
|---|---|
List<PackageInfo> |
设备上安装的 PackageInfo 的 List。 |
| 抛出 | |
|---|---|
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;否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getBootHistory
public Map<Long, String> getBootHistory ()
辅助方法,用于收集包含启动时间和启动原因的启动历史记录映射。
| 返回 | |
|---|---|
Map<Long, String> |
启动时间(自纪元以来的世界协调时间,以秒为单位)和启动原因的映射 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getBootHistorySince
public Map<Long, String> getBootHistorySince (long utcEpochTime,
TimeUnit timeUnit)辅助方法,用于从设备收集自给定时间(自纪元以来的时间)以来的启动历史记录映射,其中包含启动时间和启动原因,以及指定的时间单位。可以通过方法 getDeviceDate() 获取当前设备的 utcEpochTime(以毫秒为单位)。
| 参数 | |
|---|---|
utcEpochTime |
long:自 Epoch 以来的设备时间。 |
timeUnit |
TimeUnit:时间单位 TimeUnit。 |
| 返回 | |
|---|---|
Map<Long, String> |
启动时间(自纪元以来的世界协调时间,以秒为单位)和启动原因的映射 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getBootloaderVersion
public String getBootloaderVersion ()
用于获取相应设备的引导加载程序版本的便捷方法。
将尝试从设备的当前状态检索引导加载程序版本。(即,如果设备处于 fastboot 模式,它将尝试从 fastboot 检索版本)
| 返回 | |
|---|---|
String |
String 引导加载程序版本,如果找不到,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
getBugreport
public InputStreamSource getBugreport ()
从设备检索 bug 报告。
保证此实现继续在没有 SD 卡(或 SD 卡尚未装载)的设备上正常运行。
| 返回 | |
|---|---|
InputStreamSource |
一种 InputStreamSource,可按需生成 bug 报告内容。如果失败,InputStreamSource 将生成空的 InputStream。 |
getBugreportz
public InputStreamSource getBugreportz ()
从设备检索 bugreportz。ZIP 格式的 bug 报告包含主 bug 报告以及对调试有用的其他日志文件。
仅支持“adb version”> 1.0.36
| 返回 | |
|---|---|
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 的替代方案,有时由于权限问题,IFileEntry 无法正常运行。
| 参数 | |
|---|---|
path |
String:是设备上要执行搜索的路径 |
| 返回 | |
|---|---|
String[] |
包含设备上某个路径中的所有文件的字符串数组。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getContentProvider
public ContentProviderHandler getContentProvider (int userId)
返回 ContentProviderHandler,如果不可用,则返回 null。
如果内容提供程序之前已使用相同的 userId 构建,则可以重复使用。
| 参数 | |
|---|---|
userId |
int:用于初始化内容提供程序的相应用户 ID。 |
| 返回 | |
|---|---|
ContentProviderHandler |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getCurrentFoldableState
public DeviceFoldableState getCurrentFoldableState ()
返回设备的当前可折叠状态,如果出现某些问题,则返回 null。
| 返回 | |
|---|---|
DeviceFoldableState |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getCurrentUser
public int getCurrentUser ()
返回当前正在运行的用户的 ID。如果出现错误,则返回 -10000。
| 返回 | |
|---|---|
int |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getDeviceDate
public long getDeviceDate ()
返回设备的日期(以自纪元以来的毫秒数表示)。
| 返回 | |
|---|---|
long |
设备的日期(采用纪元格式)。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getDeviceDescriptor
public DeviceDescriptor getDeviceDescriptor ()
从设备信息返回 DeviceDescriptor,以便在不传递实际设备对象的情况下获取有关设备的信息。
| 返回 | |
|---|---|
DeviceDescriptor |
|
getDeviceDescriptor
public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)
从设备信息返回 DeviceDescriptor,以便在不传递实际设备对象的情况下获取有关设备的信息。
| 参数 | |
|---|---|
shortDescriptor |
boolean:是否将描述符限制为仅包含最基本的信息 |
| 返回 | |
|---|---|
DeviceDescriptor |
|
getDeviceTimeOffset
public long getDeviceTimeOffset (Date date)
用于获取设备与指定 Date 之间的时间差的辅助程序。在内部使用纪元时间。
| 参数 | |
|---|---|
date |
Date |
| 返回 | |
|---|---|
long |
以毫秒为单位的差值 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getEmulatorOutput
public InputStreamSource getEmulatorOutput ()
获取模拟器 stdout 和 stderr 的数据流
| 返回 | |
|---|---|
InputStreamSource |
模拟器输出 |
getEmulatorProcess
public Process getEmulatorProcess ()
返回与此模拟器对应的 Process。
| 返回 | |
|---|---|
Process |
Process 或 null |
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 mode) 时获取其商品类型。
仅当设备应处于 fastboot 状态时才应使用此方法。在这种情况下,它比通用的 getProductType() 方法更安全,因为 ITestDevice 会知道在设备处于错误状态或无响应时将设备恢复到 fastboot。
| 返回 | |
|---|---|
String |
String 商品类型名称,如果无法确定,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
getFastbootProductVariant
public String getFastbootProductVariant ()
一种便捷方法,用于在设备处于 Fastboot 模式 (Fastboot mode) 时获取其商品类型。
仅当设备应处于 fastboot 状态时才应使用此方法。在这种情况下,它比通用的 getProductType() 方法更安全,因为 ITestDevice 会知道在设备处于错误状态或无响应时将设备恢复到 fastboot。
| 返回 | |
|---|---|
String |
String 商品类型名称,如果无法确定,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
getFastbootSerialNumber
public String getFastbootSerialNumber ()
返回 fastboot 模式序列号。
| 返回 | |
|---|---|
String |
|
getFastbootVariable
public String getFastbootVariable (String variableName)
从设备检索给定的 fastboot 变量值。
| 参数 | |
|---|---|
variableName |
String:变量名称 |
| 返回 | |
|---|---|
String |
属性值;如果不存在,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
getFastbootVersion
public String getFastbootVersion ()
返回所用 fastboot 二进制文件的版本字符串。如果出现问题,则为 null。
| 返回 | |
|---|---|
String |
|
getFileEntry
public IFileEntry getFileEntry (String path)
检索对设备上远程文件的引用。
| 参数 | |
|---|---|
path |
String:要检索的文件路径。可以是绝对路径,也可以是相对于“/”的路径。(即支持“/system”和“system”语法) |
| 返回 | |
|---|---|
IFileEntry |
如果找不到给定 path 处的文件,则为 IFileEntry 或 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getFileEntry
public IFileEntry getFileEntry (FileListingService.FileEntry entry)
用于从非根路径获取 FileEntry 的非官方辅助程序。FIXME:重构 FileEntry 系统,使其可从任何路径访问。(即使是非 root 用户)。
| 参数 | |
|---|---|
entry |
FileListingService.FileEntry:一个 FileEntry,不一定需要像 Ddmlib 那样是根。 |
| 返回 | |
|---|---|
IFileEntry |
表示 FileEntry 的 FileEntryWrapper。 |
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
getFoldableStates
public Set<DeviceFoldableState> getFoldableStates ()
返回设备上的可折叠状态列表。可通过“cmd device_state print-states”获取。
| 返回 | |
|---|---|
Set<DeviceFoldableState> |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getIDevice
public IDevice getIDevice ()
返回对关联的 ddmlib IDevice 的引用。
每次设备与 adb 断开连接并重新连接时,DDMS 可能会分配新的 IDevice。因此,调用方不应保留对 IDevice 的引用,因为该引用可能会过时。
| 返回 | |
|---|---|
IDevice |
IDevice |
getInstalledPackageNames
public Set<String> getInstalledPackageNames ()
提取设备上存在的应用软件包名称。
| 返回 | |
|---|---|
Set<String> |
设备上当前安装的 String 个软件包名称的 Set。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getIntProperty
public long getIntProperty (String name,
long defaultValue)返回设备中指定属性的整数值。
| 参数 | |
|---|---|
name |
String:属性名称 |
defaultValue |
long:如果属性为空或不存在,则返回的默认值。 |
| 返回 | |
|---|---|
long |
属性值;如果属性为空、不存在或没有整数值,则为 defaultValue。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getIpAddress
public String getIpAddress ()
获取设备的 IP 地址。
| 返回 | |
|---|---|
String |
设备的 IP 地址,如果设备没有 IP 地址,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getKeyguardState
public KeyguardControllerState getKeyguardState ()
返回一个对象以获取 Keyguard 的当前状态,如果不支持,则返回 null。
| 返回 | |
|---|---|
KeyguardControllerState |
包含有关锁屏状态的快照的 KeyguardControllerState,如果不支持锁屏查询,则返回 Null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getLastExpectedRebootTimeMillis
public long getLastExpectedRebootTimeMillis ()
返回自纪元以来 Tradefed API 上次触发重新启动的时间(以毫秒为单位),与 System.currentTimeMillis() 返回的值相同。
| 返回 | |
|---|---|
long |
|
getLaunchApiLevel
public int getLaunchApiLevel ()
获取设备首次发布时所采用的 API 级别。默认为 UNKNOWN_API_LEVEL。
| 返回 | |
|---|---|
int |
一个整数,用于指示设备的首次发布 API 级别 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getLogcat
public InputStreamSource getLogcat ()
获取 logcat 数据的快照流。
以两种模式运行:
TestDeviceOptions.getMaxLogcatDataSize() 字节的后台 logcat 捕获的当前内容
| 返回 | |
|---|---|
InputStreamSource |
|
getLogcat
public InputStreamSource getLogcat (int maxBytes)
获取最近 maxBytes 个捕获的 logcat 数据的快照流。
适用于以下情况:您希望频繁捕获所捕获 logcat 数据的快照,但不想因获取整个 getLogcat() 快照而导致磁盘空间可能严重不足。
| 参数 | |
|---|---|
maxBytes |
int:要返回的数据量上限。应为可轻松容纳在内存中的量 |
| 返回 | |
|---|---|
InputStreamSource |
|
getLogcatDump
public InputStreamSource getLogcatDump ()
获取设备的当前 logcat 的 dump。与 getLogcat() 不同,此方法始终会返回 logcat 的静态转储。
缺点是,如果设备无法访问,则不会返回任何内容。
| 返回 | |
|---|---|
InputStreamSource |
logcat 数据的 InputStreamSource。如果无法捕获 logcat 数据,则返回空数据流。 |
getLogcatSince
public InputStreamSource getLogcatSince (long date)
从提供的日期开始,获取捕获的 logcat 数据的快照流。设备上的时间应使用 getDeviceDate()。
| 参数 | |
|---|---|
date |
long:以自纪元以来的毫秒数表示的开始时间,从该时间开始截取快照,直到现在。
(可以使用“date +%s”获取) |
| 返回 | |
|---|---|
InputStreamSource |
|
getMacAddress
public String getMacAddress ()
返回设备的 MAC 地址;如果无法从设备查询,则返回 null。
| 返回 | |
|---|---|
String |
|
getMainUserId
public Integer getMainUserId ()
返回主用户 ID。
| 返回 | |
|---|---|
Integer |
主要用户的 userId(如果有),如果没有主要用户,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getMainlineModuleInfo
public Set<String> getMainlineModuleInfo ()
获取有关设备上安装的 Mainline 模块的信息。
| 返回 | |
|---|---|
Set<String> |
设备上当前安装的 String 个 Mainline 模块的 Set。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getMaxNumberOfRunningUsersSupported
public int getMaxNumberOfRunningUsersSupported ()
获取支持的同时运行的用户数量上限。默认值为 0。
| 返回 | |
|---|---|
int |
一个整数,表示同时运行的用户数 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getMaxNumberOfUsersSupported
public int getMaxNumberOfUsersSupported (String userType)
获取给定用户类型的支持用户数量上限。默认值为 0。
| 参数 | |
|---|---|
userType |
String:用户类型,如 UserManager 中所定义,例如“android.os.usertype.full.SECONDARY”。 |
| 返回 | |
|---|---|
int |
一个整数,表示指定用户类型的支持用户数 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getMaxNumberOfUsersSupported
public int getMaxNumberOfUsersSupported ()
获取支持的可切换用户的最大数量(不包括 Guest)。在 API 版本 36 之后,不包括不可切换的用户(例如个人资料)。默认值为 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 中的缓存信息不可用,则直接查询设备。
待办事项:将此行为移至 IDevice.getMountPoint(String)
| 参数 | |
|---|---|
mountName |
String:装载点的名称 |
| 返回 | |
|---|---|
String |
装载点或 null |
getMountPointInfo
public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)
返回与指定挂载点路径对应的 MountPointInfo;如果该路径未挂载任何内容,或者未以挂载点形式出现在 /proc/mounts 中,则返回 null。
| 参数 | |
|---|---|
mountpoint |
String |
| 返回 | |
|---|---|
ITestDevice.MountPointInfo |
包含“/proc/mounts”中信息的 MountPointInfo 的 List |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getMountPointInfo
public List<ITestDevice.MountPointInfo> getMountPointInfo ()
返回设备上 /proc/mounts 中的信息的已解析版本
| 返回 | |
|---|---|
List<ITestDevice.MountPointInfo> |
包含“/proc/mounts”中信息的 MountPointInfo 的 List |
| 抛出 | |
|---|---|
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”命令,并返回包含给定进程的 PID 和进程启动时间的 ProcessInfo 对象。
| 参数 | |
|---|---|
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 |
设备当前使用的恢复模式。 |
getRemainingCreatableUserCount
public int getRemainingCreatableUserCount (String userType)
返回可在相应设备上创建的指定用户类型的用户数量。
| 参数 | |
|---|---|
userType |
String:用户类型,如 UserManager 中所定义,例如“android.os.usertype.full.SECONDARY”。 |
| 返回 | |
|---|---|
int |
可添加的指定用户类型的用户数量 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (Long displayId, String format, boolean rescale)
以支持的格式从指定显示 ID 的设备中抓取屏幕截图。允许重新缩放以支持较小的尺寸
| 参数 | |
|---|---|
displayId |
Long:要从中获取屏幕截图的屏幕的显示 ID。 |
format |
String:支持 PNG、JPEG |
rescale |
boolean:是否应调整屏幕截图大小以减小生成的图片的大小 |
| 返回 | |
|---|---|
InputStreamSource |
如果屏幕截图成功,则为屏幕截图的 InputStreamSource 格式,否则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (String format)
从设备中抓取屏幕截图。 建议使用 getScreenshot(format) 并采用 JPEG 编码,以缩小文件大小
| 参数 | |
|---|---|
format |
String:支持 PNG、JPEG |
| 返回 | |
|---|---|
InputStreamSource |
如果屏幕截图成功,则为屏幕截图的 InputStreamSource 格式,否则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (long displayId)
从具有指定显示 ID 的设备中抓取屏幕截图。格式为 PNG。
TODO:扩展上述实现以支持“format”和“rescale”
| 参数 | |
|---|---|
displayId |
long:要从中获取屏幕截图的屏幕的显示 ID。 |
| 返回 | |
|---|---|
InputStreamSource |
如果屏幕截图成功,则为屏幕截图的 InputStreamSource 格式,否则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (String format, boolean rescale)
从设备中抓取屏幕截图。建议改用 getScreenshot(String),并采用 JPEG 编码以减小大小。
| 参数 | |
|---|---|
format |
String:支持 PNG、JPEG |
rescale |
boolean:是否应调整屏幕截图大小以减小生成的图片的大小 |
| 返回 | |
|---|---|
InputStreamSource |
如果屏幕截图成功,则为屏幕截图的 InputStreamSource 格式,否则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot ()
从设备中抓取屏幕截图。
| 返回 | |
|---|---|
InputStreamSource |
如果屏幕截图成功,则为 PNG 格式的屏幕截图的 InputStreamSource;如果屏幕截图失败,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getSetting
public String getSetting (int userId,
String namespace,
String key)返回所请求设置的值。 命名空间必须是以下之一:{"system", "secure", "global"}
| 参数 | |
|---|---|
userId |
int |
namespace |
String |
key |
String |
| 返回 | |
|---|---|
String |
与用户的命名空间:键关联的值。如果未找到,则为 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 卡运营商;如果不可用或设备不可用,则返回 null。
| 返回 | |
|---|---|
String |
|
getSimState
public String getSimState ()
返回 SIM 卡状态,如果不可用或设备不可用,则返回 null。
| 返回 | |
|---|---|
String |
|
getTombstones
public List<File> getTombstones ()
从设备中提取并返回墓碑列表。需要 root 权限。
方法是尽力而为,因此如果因任何原因而无法提取某个标记,该标记将从列表中缺失。只有 DeviceNotAvailableException 会提前终止方法。
| 返回 | |
|---|---|
List<File> |
墓碑文件列表,如果没有墓碑,则为空。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getTotalMemory
public long getTotalMemory ()
返回总物理内存大小(以字节为单位),如果出现内部错误,则返回 -1
| 返回 | |
|---|---|
long |
|
getTrackingSerial
public String getTrackingSerial ()
出于设备管理目的,获取用于跟踪设备的序列号。
| 返回 | |
|---|---|
String |
|
getUninstallablePackageNames
public Set<String> getUninstallablePackageNames ()
获取可卸载的应用软件包名称。目前,此属性定义为非系统软件包和更新的系统软件包。
| 返回 | |
|---|---|
Set<String> |
设备上当前安装的不可卸载的 String 软件包名称的 Set。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getUseFastbootErase
public boolean getUseFastbootErase ()
获取是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。
| 返回 | |
|---|---|
boolean |
如果将使用 fastboot erase,则为 true;如果将使用 fastboot format,则为 false。 |
getUserFlags
public int getUserFlags (int userId)
查找并返回指定用户的标志。 标志在 Android 开源项目的“android.content.pm.UserInfo”类中定义。
| 参数 | |
|---|---|
userId |
int |
| 返回 | |
|---|---|
int |
如果找到,则为与所提供的 userId 关联的标志;在任何其他情况下,则为 -10000。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getUserInfos
public Map<Integer, UserInfo> getUserInfos ()
获取设备上 useId 到 UserInfo 的映射。如果设备的输出不符合预期,将抛出 DeviceRuntimeException。
| 返回 | |
|---|---|
Map<Integer, UserInfo> |
UserInfo 对象的列表。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getUserSerialNumber
public int getUserSerialNumber (int userId)
如果找到与 userId 关联的序列号,则返回该序列号;在任何其他情况下,则返回 -10000。
| 参数 | |
|---|---|
userId |
int |
| 返回 | |
|---|---|
int |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getUserVisibleOnDisplay
public int getUserVisibleOnDisplay (int displayId)
获取指定显示屏上可见用户的用户 ID。
| 参数 | |
|---|---|
displayId |
int:显示屏的 ID。 |
| 返回 | |
|---|---|
int |
指定显示屏上可见用户的用户 ID。它不会区分可见的后台用户和当前的前台用户,因为这两种类型的用户都是可见的。为了区分,请进一步与 getCurrentUser() 的结果进行比较。 |
| 抛出 | |
|---|---|
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 |
|
initializeConnection
public void initializeConnection (IBuildInfo info, MultiMap<String, String> attributes)
初始化与设备的连接。此方法由 preInvocationSetup 调用,但在极少数情况下,在设备设置期间创建连接时可能需要单独调用此方法。
| 参数 | |
|---|---|
info |
IBuildInfo |
attributes |
MultiMap |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
TargetSetupError |
|
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 |
|
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 |
|
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 |
|
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 |
|
installPackageWithIncrementalMode
public boolean installPackageWithIncrementalMode (File[] apkFiles,
String[] extraArgs,
String userId)以增量模式安装 APK。
| 参数 | |
|---|---|
apkFiles |
File:要安装的 APK 文件。 |
extraArgs |
String |
userId |
String |
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
invalidatePropertyCache
public void invalidatePropertyCache ()
isAdbTcp
public boolean isAdbTcp ()
| 返回 | |
|---|---|
boolean |
|
isAppEnumerationSupported
public boolean isAppEnumerationSupported ()
检查设备上的平台是否支持应用枚举
| 返回 | |
|---|---|
boolean |
如果支持应用枚举,则为 true,否则为 false |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isBypassLowTargetSdkBlockSupported
public boolean isBypassLowTargetSdkBlockSupported ()
检查设备上的平台是否支持在应用安装时绕过低目标 SDK 限制
| 返回 | |
|---|---|
boolean |
如果支持绕过低目标 SDK 限制,则为 true;否则为 false |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isDebugfsMounted
public boolean isDebugfsMounted ()
检查 debugfs 是否已挂载。
| 返回 | |
|---|---|
boolean |
如果已装载 debugfs,则为 true |
| 抛出 | |
|---|---|
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 |
|
isExecutable
public boolean isExecutable (String fullPath)
如果设备上的文件路径是可执行文件,则返回 True,否则返回 False。
| 参数 | |
|---|---|
fullPath |
String |
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isFastbootEnabled
public boolean isFastbootEnabled ()
如果设备支持 fastboot,则返回 true。
| 返回 | |
|---|---|
boolean |
|
isHeadless
public boolean isHeadless ()
如果设备是无头设备(没有屏幕),则返回 true,否则返回 false。
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isHeadlessSystemUserMode
public boolean isHeadlessSystemUserMode ()
返回设备是否使用无头系统用户模式。
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isMainUserPermanentAdmin
public boolean isMainUserPermanentAdmin ()
返回主用户是否为永久管理员,且无法删除或降级为非管理员状态。
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isMultiUserSupported
public boolean isMultiUserSupported ()
返回相应设备是否支持多个可切换的用户,这些用户拥有各自的登录信息和可自定义的空间。
请注意,即使值为 false,只要不需要登录界面,仍有可能支持多位用户;例如,配置文件可能仍受支持,因为它们不需要登录界面。
此命令还会检查 config_enableMultiUserUI。根据需求,我们可以假设满足此条件的设备已配置为允许通过 adb 添加次要用户。
| 返回 | |
|---|---|
boolean |
设备是否支持多个可切换的用户。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isPackageInstalled
public boolean isPackageInstalled (String packageName,
String userId)查询设备上指定软件包名称和指定用户 ID 的应用是否已安装。
| 参数 | |
|---|---|
packageName |
String:我们要检查的软件包是否已安装。 |
userId |
String:我们要检查软件包是否已安装的用户 ID。如果为 null,则使用主要用户零。 |
| 返回 | |
|---|---|
boolean |
如果相应软件包被报告为已安装,则为 true。否则输出 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isPackageInstalled
public boolean isPackageInstalled (String packageName)
查询设备上是否存在给定的软件包名称,以检查该软件包是否已安装。
| 参数 | |
|---|---|
packageName |
String |
| 返回 | |
|---|---|
boolean |
如果相应软件包被报告为已安装,则为 true。否则输出 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isRuntimePermissionSupported
public boolean isRuntimePermissionSupported ()
检查设备上的平台是否支持运行时权限授予
| 返回 | |
|---|---|
boolean |
如果支持运行时权限,则为 true;否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isStateBootloaderOrFastbootd
public boolean isStateBootloaderOrFastbootd ()
如果设备处于 TestDeviceState.FASTBOOT 或 TestDeviceState.FASTBOOTD 状态,则返回 true。
| 返回 | |
|---|---|
boolean |
|
isUserRunning
public boolean isUserRunning (int userId)
检查指定用户是否正在运行。
| 参数 | |
|---|---|
userId |
int |
| 返回 | |
|---|---|
boolean |
如果用户正在跑步,则为 true;在所有其他情况下,则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isUserSecondary
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 ()
返回设备是否允许用户在后台启动可见的 activity。
如果存在,您可以调用 startVisibleBackgroundUser(int, int, boolean),并传递由 listDisplayIdsForStartingVisibleBackgroundUsers() 返回的显示对象。
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
isWifiEnabled
public boolean isWifiEnabled ()
测试 Wi-Fi 是否已启用。
检查设备上是否已启用 Wi-Fi。在不应使用 WLAN 运行的测试(例如移动数据测试)之前,用于断言 WLAN 状态。
| 返回 | |
|---|---|
boolean |
如果 WLAN 已启用,则为 true。false(如果已停用) |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
listDisplayIds
public Set<Long> listDisplayIds ()
收集设备上“dumpsys SurfaceFlinger”报告的可用显示屏 ID 列表。
| 返回 | |
|---|---|
Set<Long> |
显示屏列表。默认值始终返回默认显示值 0。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
listDisplayIdsForStartingVisibleBackgroundUsers
public Set<Integer> listDisplayIdsForStartingVisibleBackgroundUsers ()
获取可用于 start a user visible in the background 的显示屏列表。
| 返回 | |
|---|---|
Set<Integer> |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
listUsers
public ArrayList<Integer> listUsers ()
获取设备上的用户列表。如果设备的输出不符合预期,将抛出 DeviceRuntimeException。
| 返回 | |
|---|---|
ArrayList<Integer> |
用户 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。 |
logOnDevice
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() 替换的实参。 |
nonBlockingReboot
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 ()
执行指令以配置设备,以便在每次启动后进行测试。
应在设备完全启动/可用后调用
在正常情况下,无需显式调用此方法,因为实现应在执行重新启动时自动执行这些步骤。
在设备因其他事件(例如快速启动更新命令已完成)而重新启动时,可能需要调用该方法
| 抛出 | |
|---|---|
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 |
|
pullDir
public boolean pullDir (String deviceFilePath,
File localDir,
int userId,
long timeout)以递归方式从设备拉取目录内容。
| 参数 | |
|---|---|
deviceFilePath |
String:远程源的绝对文件路径 |
localDir |
File:要将文件拉取到的本地目录 |
userId |
int:要从中提取的用户 ID |
timeout |
long:拉取命令的超时时间 |
| 返回 | |
|---|---|
boolean |
如果成功拉取文件,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pullFile
public boolean pullFile (String remoteFilePath,
File localFile,
int userId,
long timeout)从设备中检索文件。
| 参数 | |
|---|---|
remoteFilePath |
String:设备上文件的绝对路径。 |
localFile |
File:用于存储内容的本地文件。如果非空,则替换内容。 |
userId |
int:要从中提取的用户 ID |
timeout |
long:拉取文件命令超时 |
| 返回 | |
|---|---|
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)从设备中检索文件,将其存储在本地临时 File 中,然后返回该 File。
| 参数 | |
|---|---|
remoteFilePath |
String:设备上文件的绝对路径。 |
userId |
int:要从中提取的用户 ID |
| 返回 | |
|---|---|
File |
包含设备文件内容的 File,或者如果因任何原因(包括主机文件系统存在问题)导致复制失败,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pullFile
public File pullFile (String remoteFilePath)
从设备中检索文件,将其存储在本地临时 File 中,然后返回该 File。
| 参数 | |
|---|---|
remoteFilePath |
String:设备上文件的绝对路径。 |
| 返回 | |
|---|---|
File |
包含设备文件内容的 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 |
|
pullFileFromExternal
public File pullFileFromExternal (String remoteFilePath)
一种便捷方法,用于从设备的外部存储空间检索文件,将其存储在本地临时 File 中,并返回对该 File 的引用。
| 参数 | |
|---|---|
remoteFilePath |
String:设备上文件的路径(相对于设备的外部存储空间装载点) |
| 返回 | |
|---|---|
File |
包含设备文件内容的 File,或者如果因任何原因(包括主机文件系统存在问题)导致复制失败,则为 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath,
int userId)以递归方式将目录内容推送到设备。
| 参数 | |
|---|---|
localFileDir |
File:要推送的本地目录 |
deviceFilePath |
String:远程目的地的绝对文件路径 |
userId |
int:要推送到的用户 ID |
| 返回 | |
|---|---|
boolean |
如果文件已成功推送,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath,
Set<String> excludedDirectories)以递归方式将目录内容推送到设备,同时排除一些已过滤的目录。
| 参数 | |
|---|---|
localFileDir |
File:要推送的本地目录 |
deviceFilePath |
String:远程目的地的绝对文件路径 |
excludedDirectories |
Set:一组不应推送的排除目录名称。 |
| 返回 | |
|---|---|
boolean |
如果文件已成功推送,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath)以递归方式将目录内容推送到设备。
| 参数 | |
|---|---|
localFileDir |
File:要推送的本地目录 |
deviceFilePath |
String:远程目的地的绝对文件路径 |
| 返回 | |
|---|---|
boolean |
如果文件已成功推送,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pushFile
public boolean pushFile (File localFile,
String remoteFilePath,
boolean evaluateContentProviderNeeded)pushFile(File,String) 的变体,可选择性地考虑评估内容提供方的需求。
| 参数 | |
|---|---|
localFile |
File:要推送的本地文件 |
remoteFilePath |
String:远程目标绝对文件路径 |
evaluateContentProviderNeeded |
boolean:是否检查是否需要内容提供程序 |
| 返回 | |
|---|---|
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:要推送到的 userId |
| 返回 | |
|---|---|
boolean |
如果文件已成功推送,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
pushString
public boolean pushString (String contents,
String remoteFilePath)将从字符串创建的文件推送到设备
| 参数 | |
|---|---|
contents |
String:要推送的文件的内容 |
remoteFilePath |
String:远程目标绝对文件路径 |
| 返回 | |
|---|---|
boolean |
如果字符串已成功推送,则为 true。否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
重新启动
public void reboot (String reason)
将设备重新启动到 adb 模式,并使给定的 reason 在重新启动后保持不变。
阻塞,直到设备可用。
可以通过查询 sys.boot.reason 属性来获取上次重新启动的原因。
| 参数 | |
|---|---|
reason |
String:相应重新启动的原因;如果未指定原因,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
重新启动
public String reboot (String command,
String reason)使用给定的 command 重新启动设备。
阻塞,直到设备可用。
可以通过查询 sys.boot.reason 属性来获取上次重新启动的原因。
| 参数 | |
|---|---|
command |
String:传递给“adb”的命令。请注意,该命令是“按原样”传递的,因此调用方需要根据需要提供适当的引号(尤其是当该命令包含多个以空格分隔的部分时)。 |
reason |
String:相应重新启动的原因;如果未指定原因,则为 null。 |
| 返回 | |
|---|---|
String |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootIntoBootloader
public void rebootIntoBootloader ()
将设备重新启动到引导加载程序模式。
阻塞,直到设备处于引导加载程序模式。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
rebootIntoFastbootd
public void rebootIntoFastbootd ()
将设备重新启动到 fastbootd 模式。
阻塞,直到设备处于 fastbootd 模式。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
rebootIntoRecovery
public void rebootIntoRecovery ()
将设备重新启动到 adb 恢复模式。
阻塞,直到设备进入恢复模式
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootIntoSideload
public void rebootIntoSideload ()
将设备重新启动到 adb 旁加载模式(请注意,这是恢复模式下的一种特殊模式)
阻塞,直到设备进入旁加载模式
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootIntoSideload
public void rebootIntoSideload (boolean autoReboot)
将设备重新启动到 adb 旁加载模式(请注意,这是恢复模式下的一种特殊模式)
阻塞,直到设备进入旁加载模式
| 参数 | |
|---|---|
autoReboot |
boolean:是否在旁加载后自动重启设备 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootUntilOnline
public void rebootUntilOnline ()
reboot() 的替代方案,仅阻塞到设备在线(即对 adb 可见)为止。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootUntilOnline
public void rebootUntilOnline (String reason)
reboot() 的替代方案,仅阻塞到设备在线(即对 adb 可见)为止。
| 参数 | |
|---|---|
reason |
String:相应重新启动的原因;如果未指定原因,则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootUserspace
public void rebootUserspace ()
仅重启设备的用户空间部分。
阻塞,直到设备可用。
警告。用户空间重启目前正在积极开发中,请自行承担使用风险。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
rebootUserspaceUntilOnline
public void rebootUserspaceUntilOnline ()
rebootUserspace() ()} 的替代方法,仅阻塞到设备在线(即对 adb 可见)为止。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
recoverDevice
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 ()
使设备上的 system 分区可写入。可能会重新启动设备。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
remountVendorReadOnly
public void remountVendorReadOnly ()
将设备上的 vendor 分区设为只读。可能会重新启动设备。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
remountVendorWritable
public void remountVendorWritable ()
使设备上的供应商分区可写入。可能会重新启动设备。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
removeAdmin
public boolean removeAdmin (String componentName,
int userId)移除指定用户中的指定设备管理员,如果成功,则返回 true,否则返回 false。
| 参数 | |
|---|---|
componentName |
String:要移除的设备管理员。 |
userId |
int:设备管理员所在用户的。 |
| 返回 | |
|---|---|
boolean |
如果成功,则为 true;否则为 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
removeUser
public boolean removeUser (int userId)
从设备中移除指定用户。
| 参数 | |
|---|---|
userId |
int:要移除的用户的 |
| 返回 | |
|---|---|
boolean |
如果我们成功移除了用户,则返回 true,否则返回 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
resetContentProviderSetup
public void resetContentProviderSetup ()
重置内容提供方设置的标志,以便再次触发该设置。
runInstrumentationTests
public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, Collection<ITestLifeCycleReceiver> listeners)
运行插桩测试,并提供设备恢复功能。
如果与设备的连接在测试运行完成之前断开,并且恢复成功,则所有监听器都会收到 testRunFailed 通知,并且返回“false”。测试命令不会重新运行。如有必要,调用方可自行重试。
如果在测试运行完成之前与设备的连接断开,并且恢复失败,系统会通知所有监听器 testRunFailed,并抛出 DeviceNotAvailableException。
| 参数 | |
|---|---|
runner |
IRemoteAndroidTestRunner:运行测试的 IRemoteAndroidTestRunner |
listeners |
Collection:测试结果监听器 |
| 返回 | |
|---|---|
boolean |
如果测试命令已完成,则为 true。如果因设备通信异常而未能成功完成,但恢复成功,则为 false |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
runInstrumentationTests
public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, ITestLifeCycleReceiver... listeners)
一种便捷方法,用于执行 runInstrumentationTests(IRemoteAndroidTestRunner,Collection),并将一个或多个监听器作为参数传递。
| 参数 | |
|---|---|
runner |
IRemoteAndroidTestRunner:运行测试的 IRemoteAndroidTestRunner |
listeners |
ITestLifeCycleReceiver:测试结果监听器 |
| 返回 | |
|---|---|
boolean |
如果测试命令已完成,则为 true。false(如果未能完成,但恢复成功) |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
runInstrumentationTestsAsUser
public boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, int userId, Collection<ITestLifeCycleReceiver> listeners)
与 ITestDevice.runInstrumentationTests(IRemoteAndroidTestRunner,Collection) 相同,但会针对指定用户运行测试。
| 参数 | |
|---|---|
runner |
IRemoteAndroidTestRunner |
userId |
int |
listeners |
Collection |
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
runInstrumentationTestsAsUser
public boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, int userId, ITestLifeCycleReceiver... listeners)
与 ITestDevice.runInstrumentationTests(IRemoteAndroidTestRunner,ITestLifeCycleReceiver...) 相同,但会针对指定用户运行测试。
| 参数 | |
|---|---|
runner |
IRemoteAndroidTestRunner |
userId |
int |
listeners |
ITestLifeCycleReceiver |
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
setAdbPath
public void setAdbPath (String adbPath)
设置应使用的 adb 二进制文件的路径。
| 参数 | |
|---|---|
adbPath |
String |
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 |
TestDeviceState:TestDeviceState |
setEmulatorOutputStream
public void setEmulatorOutputStream (SizeLimitedOutputStream output)
对于模拟器,请将 SizeLimitedOutputStream 设置为日志输出
| 参数 | |
|---|---|
output |
SizeLimitedOutputStream:记录输出 |
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 |
IDevice:IDevice |
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 |
IDeviceRecovery:IDeviceRecovery |
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 |
setTrackingSerial
public void setTrackingSerial (String trackingSerial)
出于设备管理目的,跟踪我们用于引用设备的序列号。
| 参数 | |
|---|---|
trackingSerial |
String |
setUseFastbootErase
public void setUseFastbootErase (boolean useFastbootErase)
设置是使用 fastboot erase 还是 fastboot format 来擦除设备上的分区。
| 参数 | |
|---|---|
useFastbootErase |
boolean:如果应使用 fastboot erase,则为 true;如果应使用 fastboot format,则为 false。 |
startLogcat
public void startLogcat ()
在后台开始捕获设备的 logcat 输出。
如果已在捕获 logcat 输出,则此命令不会有任何作用。 之后可以通过 getLogcat 检索数据。
当设备不再使用时,必须调用 stopLogcat()。
在 TF 调用上下文中,通常不需要调用 startLogcat() 和 stopLogcat(),因为 TF 框架会启动和停止 logcat。
startTradeInModeTesting
public boolean startTradeInModeTesting (int timeoutMs)
启用以旧换新模式。设备将被擦除并重新启动。
| 参数 | |
|---|---|
timeoutMs |
int |
| 返回 | |
|---|---|
boolean |
如果成功,则为 true,否则为 false |
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
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 ()
关闭并删除模拟器输出。
stopLogcat
public void stopLogcat ()
停止从设备捕获 logcat 输出,并舍弃当前保存的 logcat 数据。
如果未捕获 logcat 输出,则不会产生任何影响。
stopTradeInModeTesting
public void stopTradeInModeTesting ()
停止以旧换新模式测试。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
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 |
|
switchUser
public boolean switchUser (int userId)
切换到另一个具有默认超时时长的 userId。switchUser(int, long)。
| 参数 | |
|---|---|
userId |
int |
| 返回 | |
|---|---|
boolean |
如果新 userId 与 userId 提供程序匹配,则为 true。否则输出 false。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
switchUser
public boolean switchUser (int userId,
long timeout)切换到另一个 userId,并将提供的超时时间作为截止时间。 在用户更改成功后尝试停用 Keyguard。
| 参数 | |
|---|---|
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 |
|
uninstallPackage
public String uninstallPackage (String packageName)
从设备中卸载 Android 软件包。
| 参数 | |
|---|---|
packageName |
String:要卸载的 Android 软件包 |
| 返回 | |
|---|---|
String |
一个包含错误代码的 String,如果成功则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
uninstallPackageForUser
public String uninstallPackageForUser (String packageName,
int userId)为指定用户从设备卸载 Android 软件包。
| 参数 | |
|---|---|
packageName |
String:要卸载的 Android 软件包 |
userId |
int:要卸载的整数用户 ID。 |
| 返回 | |
|---|---|
String |
一个包含错误代码的 String,如果成功则为 null。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
unlockDevice
public boolean unlockDevice ()
如果设备处于加密状态,则解锁设备。
此方法可能会重启框架,但不会调用postBootSetup()。因此,当此方法返回时,设备可能尚未完全准备好进行测试。
| 返回 | |
|---|---|
boolean |
如果成功或设备未加密,则为 true。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
UnsupportedOperationException |
|
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 |
|
waitForDeviceInRecovery
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 |
waitForDeviceOnline
public void waitForDeviceOnline ()
阻塞,直到设备通过 adb 可见。使用默认超时时间
请注意,设备在完成操作后可能不一定会响应命令。请改用 waitForDeviceAvailable()。
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
waitForDeviceOnline
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,
boolean oldShellCommand)为给定的 adb shell 命令会话和实参构建操作系统命令
| 参数 | |
|---|---|
command |
String |
forceExitStatusDetection |
boolean |
oldShellCommand |
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。 |
doAdbReboot
protected void doAdbReboot (NativeDevice.RebootMode rebootMode, String reason)
执行 adb reboot。
| 参数 | |
|---|---|
rebootMode |
NativeDevice.RebootMode:相应重启的模式。 |
reason |
String:用于此重启。 |
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
ensureRuntimePermissionSupported
protected void ensureRuntimePermissionSupported ()
如果不支持运行时权限,则抛出异常的辅助方法
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
getApiLevelSafe
protected int getApiLevelSafe ()
| 返回 | |
|---|---|
int |
|
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 |
|
UnsupportedOperationException |
|
isInRebootCallback
protected boolean isInRebootCallback ()
返回是否正在执行重新启动回调。如果为 true,则应停用所有用于重新启动的公共 API。
| 返回 | |
|---|---|
boolean |
|
isNewer
protected boolean isNewer (File localFile,
IFileEntry entry)如果本地文件比远程文件新,则返回 true。IFileEntry 精确到分钟;如果时间相同,则认为文件较新。
| 参数 | |
|---|---|
localFile |
File |
entry |
IFileEntry |
| 返回 | |
|---|---|
boolean |
|
notifyRebootEnded
protected void notifyRebootEnded ()
向所有 IDeviceActionReceiver 通知重新启动结束事件。
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
notifyRebootStarted
protected void notifyRebootStarted ()
通知所有 IDeviceActionReceiver 重新启动开始事件。
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
performDeviceAction
protected boolean performDeviceAction (String actionDescription,
NativeDevice.DeviceAction action,
int retryAttempts)在此设备上执行操作。尝试恢复设备,并在操作失败时选择性地重试命令。
| 参数 | |
|---|---|
actionDescription |
String:要执行的操作的简短说明。仅用于日志记录目的。 |
action |
NativeDevice.DeviceAction:要执行的操作 |
retryAttempts |
int:如果操作失败但恢复成功,则重试操作的次数 |
| 返回 | |
|---|---|
boolean |
如果操作成功执行,则为 true |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
如果恢复尝试失败或在达到最大尝试次数后仍未成功 |
postAdbReboot
protected void postAdbReboot (NativeDevice.RebootMode rebootMode)
重新启动后可能采取的额外操作。
| 参数 | |
|---|---|
rebootMode |
NativeDevice.RebootMode |
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
prePostBootSetup
protected void prePostBootSetup ()
允许每种设备类型(AndroidNativeDevice、TestDevice)替换此方法以进行特定的启动后设置。
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
pullFileWithAdbCommand
protected boolean pullFileWithAdbCommand (String remoteFilePath,
File localFile,
long timeout)| 参数 | |
|---|---|
remoteFilePath |
String |
localFile |
File |
timeout |
long |
| 返回 | |
|---|---|
boolean |
|
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
setClock
protected void setClock (Clock clock)
设置要使用的 Clock 实例。
| 参数 | |
|---|---|
clock |
Clock |
setMicrodroidProcess
protected void setMicrodroidProcess (Process process)
将 TestDevice 标记为 microdroid 并设置其 CID。
| 参数 | |
|---|---|
process |
Process:Microdroid 虚拟机的进程。 |
setTestDeviceOptions
protected void setTestDeviceOptions (Map<String, String> deviceOptions)
| 参数 | |
|---|---|
deviceOptions |
Map |
simpleFastbootCommand
protected CommandResult simpleFastbootCommand (long timeout, String[] fullCmd)
执行简单的 fastboot 命令并报告命令的状态。
| 参数 | |
|---|---|
timeout |
long |
fullCmd |
String |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
UnsupportedOperationException |
|
simpleFastbootCommand
protected CommandResult simpleFastbootCommand (long timeout, Map<String, String> envVarMap, String[] fullCmd)
使用环境变量执行简单的 fastboot 命令,并报告该命令的状态。
| 参数 | |
|---|---|
timeout |
long |
envVarMap |
Map |
fullCmd |
String |
| 返回 | |
|---|---|
CommandResult |
|
| 抛出 | |
|---|---|
UnsupportedOperationException |
|
waitForDeviceNotAvailable
protected boolean waitForDeviceNotAvailable (String operationDesc,
long time)等待设备变为不可用状态(停止向 adb 报告)。
| 参数 | |
|---|---|
operationDesc |
String:正在等待不可用操作的名称。 |
time |
long:等待发生不可用情况的时间。 |
| 返回 | |
|---|---|
boolean |
如果设备确实变得不可用,则为 true。 |