TestDevice

public class TestDevice
extends NativeDevice

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


针对全堆栈 Android 设备的 ITestDevice 实现

摘要

嵌套类

class TestDevice.MicrodroidBuilder

用于创建 Microdroid TestDevice 的构建器。 

常量

String DISMISS_KEYGUARD_CMD

可用于关闭锁屏的命令。

公共构造函数

TestDevice(IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)

公共方法

boolean canSwitchToHeadlessSystemUser()

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

boolean clearErrorDialogs()

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

int createUser(String name)

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

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

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

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

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

int createUserNoThrow(String name)

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

void disableKeyguard()

尝试停用锁屏。

boolean doesFileExist(String deviceFilePath, int userId)

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

boolean doesFileExist(String deviceFilePath)

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

File dumpHeap(String process, String devicePath)

尝试从 system_server 转储堆。

getActiveApexes()

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

getAllSettings(String namespace)

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

String getAndroidId(int userId)

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

getAndroidIds()

创建了 Android ID 的 Map,其中包含与用户 ID 匹配的 Android ID。

PackageInfo getAppPackageInfo(String packageName)

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

getAppPackageInfos()

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

InputStreamSource getBugreport()

从设备检索 bug 报告。

InputStreamSource getBugreportz()

从设备检索 bugreportz。

DeviceFoldableState getCurrentFoldableState()

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

int getCurrentUser()

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

getFoldableStates()

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

getInstalledPackageNames()

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

KeyguardControllerState getKeyguardState()

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

Integer getMainUserId()

返回主用户 ID。

getMainlineModuleInfo()

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

int getMaxNumberOfRunningUsersSupported()

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

int getMaxNumberOfUsersSupported()

获取支持的最大用户数。

Integer getPrimaryUserId()

返回主用户 ID。

InputStreamSource getScreenshot(String format, boolean rescale)

从设备中抓取屏幕截图。

InputStreamSource getScreenshot(long displayId)

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

InputStreamSource getScreenshot(String format)

从设备中抓取屏幕截图。

InputStreamSource getScreenshot()

从设备中抓取屏幕截图。

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

返回所请求设置的值。

String getSetting(String namespace, String key)

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

getUninstallablePackageNames()

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

int getUserFlags(int userId)

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

getUserInfos()

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

int getUserSerialNumber(int userId)

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

boolean hasFeature(String feature)

检查设备上是否提供某项功能。

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

在设备上安装 Android 软件包。

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

在设备上安装 Android 软件包。

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

在设备上安装 Android 软件包。

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

在设备上为指定用户安装 Android 软件包。

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

在设备上为指定用户安装 Android 软件包。

boolean installPackageWithIncrementalMode(File[] apkFiles, String[] extraArgs, String userId)

以增量模式安装 APK。

String installPackages( packageFiles, boolean reinstall, String... extraArgs)

String installPackages( packageFiles, boolean reinstall, boolean grantPermissions, String... extraArgs)

String installPackagesForUser( packageFiles, boolean reinstall, int userId, String... extraArgs)

String installPackagesForUser( packageFiles, boolean reinstall, boolean grantPermissions, int userId, String... extraArgs)

String installRemotePackages( remoteApkPaths, boolean reinstall, String... extraArgs)

String installRemotePackages( remoteApkPaths, boolean reinstall, boolean grantPermissions, String... extraArgs)

boolean isAppEnumerationSupported()

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

boolean isHeadlessSystemUserMode()

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

boolean isMainUserPermanentAdmin()

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

boolean isMultiUserSupported()

确定是否支持多用户。

boolean isPackageInstalled(String packageName, String userId)

查询设备上指定软件包名称和指定用户 ID 的应用,以检查该应用是否已安装在相应用户上。

boolean isPackageInstalled(String packageName)

查询设备上是否存在指定软件包名称,以检查该软件包是否已安装。

boolean isUserRunning(int userId)

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

boolean isUserSecondary(int userId)

根据指定用户的标志,返回该用户是否为次要用户。

boolean isUserVisible(int userId)

检查指定用户是否可见。

boolean isUserVisibleOnDisplay(int userId, int displayId)

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

boolean isVisibleBackgroundUsersOnDefaultDisplaySupported()

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

boolean isVisibleBackgroundUsersSupported()

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

listDisplayIds()

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

listDisplayIdsForStartingVisibleBackgroundUsers()

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

listUsers()

获取设备上的用户列表。

boolean logBugreport(String dataName, ITestLogger listener)

用于获取 bug 报告并将其记录到报告者的辅助方法。

void notifySnapuserd(SnapuserdWaitPhase waitPhase)
void postInvocationTearDown(Throwable exception)

设备特定所需清理的额外步骤,将在调用完成后执行。

boolean removeAdmin(String componentName, int userId)

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

void removeOwners()

尽最大努力移除所有现有的设备配置文件所有者。

boolean removeUser(int userId)

从设备中移除指定用户。

boolean setDeviceOwner(String componentName, int userId)

在指定用户中将设备管理员组件设为设备所有者。

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

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

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

向指定用户的命名空间添加设置值。

void shutdownMicrodroid(ITestDevice microdroidDevice)

关闭 microdroid 设备(如果存在)。

boolean startUser(int userId)

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

boolean startUser(int userId, boolean waitFlag)

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

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

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

boolean stopUser(int userId)

停止指定用户。

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

停止指定用户。

boolean supportsMicrodroid()

检查运行 microdroid 的前提条件。

boolean supportsMicrodroid(boolean protectedVm)

检查运行 microdroid 的前提条件。

boolean switchUser(int userId)

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

boolean switchUser(int userId, long timeout)

切换到另一个 userId,并将提供的超时时间作为截止时间。

Bugreport takeBugreport()

获取 bug 报告并将其返回到 Bugreport 对象中以进行处理。

String uninstallPackage(String packageName)

从设备中卸载 Android 软件包。

String uninstallPackageForUser(String packageName, int userId)

为指定用户从设备中卸载 Android 软件包。

void waitForSnapuserd(SnapuserdWaitPhase currentPhase)

受保护的方法

AaptParser createParser(File appFile)
void doAdbReboot(NativeDevice.RebootMode rebootMode, String reason)

执行 adb 重启。

InputStreamSource getBugreportInternal()
File getBugreportzInternal()

用于获取 bugreportz zip 文件(以 ERROR(/File) 形式)的内部辅助方法。

long getCheckNewUserSleep()

公开以供测试。

long getHostCurrentTime()

公开以供测试

void prePostBootSetup()

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

常量

DISMISS_KEYGUARD_CMD

public static final String DISMISS_KEYGUARD_CMD

可用于关闭锁屏界面的命令。

常量值: “input keyevent 82”

公共构造函数

TestDevice

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

公共方法

canSwitchToHeadlessSystemUser

public boolean canSwitchToHeadlessSystemUser ()

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

返回
boolean

抛出
DeviceNotAvailableException

clearErrorDialogs

public boolean clearErrorDialogs ()

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

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

抛出
DeviceNotAvailableException

createUser

public int createUser (String name)

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

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

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

抛出
DeviceNotAvailableException

createUser

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

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

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

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

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

返回
int 所创建用户的 ID

抛出
DeviceNotAvailableException

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

createUserNoThrow

public int createUserNoThrow (String name)

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

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

返回
int 创建的用户 ID 的整数,如果出错则为 -1。

抛出
DeviceNotAvailableException

disableKeyguard

public void disableKeyguard ()

尝试停用锁屏。

首先,等待输入调度准备就绪,这大约发生在设备报告 BOOT_COMPLETE 的同时,但显然是异步的,因为当前框架实现偶尔会出现竞态条件。然后,系统会发送命令来关闭锁屏(仅适用于不安全的锁屏)

抛出
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 包含报告的 ERROR(/File)。如果出现故障,则为 null。

抛出
DeviceNotAvailableException

getActiveApexes

public  getActiveApexes ()

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

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

抛出
DeviceNotAvailableException

getAllSettings

public  getAllSettings (String namespace)

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

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

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

抛出
DeviceNotAvailableException

getAndroidId

public String getAndroidId (int userId)

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

参数
userId int

返回
String

抛出
DeviceNotAvailableException

getAndroidIds

public  getAndroidIds ()

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

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

抛出
DeviceNotAvailableException

getAppPackageInfo

public PackageInfo getAppPackageInfo (String packageName)

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

参数
packageName String

返回
PackageInfo 如果无法检索信息,则为 PackageInfonull

抛出
DeviceNotAvailableException

getAppPackageInfos

public  getAppPackageInfos ()

获取设备上安装的软件包的信息。

返回
设备上安装的 PackageInfoERROR(/List)

抛出
DeviceNotAvailableException

getBugreport

public InputStreamSource getBugreport ()

从设备检索 bug 报告。

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

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

getBugreportz

public InputStreamSource getBugreportz ()

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

仅支持“adb version”> 1.0.36

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

getCurrentFoldableState

public DeviceFoldableState getCurrentFoldableState ()

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

返回
DeviceFoldableState

抛出
DeviceNotAvailableException

getCurrentUser

public int getCurrentUser ()

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

返回
int

抛出
DeviceNotAvailableException

getFoldableStates

public  getFoldableStates ()

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

返回

抛出
DeviceNotAvailableException

getInstalledPackageNames

public  getInstalledPackageNames ()

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

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

抛出
DeviceNotAvailableException

getKeyguardState

public KeyguardControllerState getKeyguardState ()

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

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

抛出
DeviceNotAvailableException

getMainUserId

public Integer getMainUserId ()

返回主用户 ID。

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

抛出
DeviceNotAvailableException

getMainlineModuleInfo

public  getMainlineModuleInfo ()

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

返回
设备上当前安装的 String 个 Mainline 模块的 ERROR(/Set)

抛出
DeviceNotAvailableException

getMaxNumberOfRunningUsersSupported

public int getMaxNumberOfRunningUsersSupported ()

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

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

抛出
DeviceNotAvailableException

getMaxNumberOfUsersSupported

public int getMaxNumberOfUsersSupported ()

获取支持的最大用户数。默认设置为 0。

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

抛出
DeviceNotAvailableException

getPrimaryUserId

public Integer getPrimaryUserId ()

返回主用户 ID。

返回
Integer 主要用户的 userId(如果有),如果没有主要用户,则为 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 (long displayId)

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

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

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

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

从设备中抓取屏幕截图。

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

getUninstallablePackageNames

public  getUninstallablePackageNames ()

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

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

抛出
DeviceNotAvailableException

getUserFlags

public int getUserFlags (int userId)

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

参数
userId int

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

抛出
DeviceNotAvailableException

getUserInfos

public  getUserInfos ()

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

返回
UserInfo 对象的列表。

抛出
DeviceNotAvailableException

getUserSerialNumber

public int getUserSerialNumber (int userId)

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

参数
userId int

返回
int

抛出
DeviceNotAvailableException

hasFeature

public boolean hasFeature (String feature)

检查某项功能是否适用于设备。

参数
feature String:应采用“feature:”或直接采用“”格式。

返回
boolean 如果找到相应功能,则为 true;否则为 false。

抛出
DeviceNotAvailableException

installPackage

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

在设备上安装 Android 软件包。

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

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

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

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

抛出
DeviceNotAvailableException

installPackage

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

在设备上安装 Android 软件包。

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

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

certFile File:如果应执行重新安装,则为 true

reinstall boolean:是否应在安装时授予所有运行时权限

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

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

抛出
DeviceNotAvailableException

installPackage

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

在设备上安装 Android 软件包。

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

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

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

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

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

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

抛出
DeviceNotAvailableException

installPackageForUser

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

在设备上为指定用户安装 Android 软件包。

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

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

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

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

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

抛出
DeviceNotAvailableException

installPackageForUser

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

在设备上为指定用户安装 Android 软件包。

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

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

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

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

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

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

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

抛出
DeviceNotAvailableException

installPackageWithIncrementalMode

public boolean installPackageWithIncrementalMode (File[] apkFiles, 
                String[] extraArgs, 
                String userId)

以增量模式安装 APK。

参数
apkFiles File:要安装的 APK 文件。

extraArgs String

userId String

返回
boolean

抛出
DeviceNotAvailableException

installPackages

public String installPackages ( packageFiles, 
                boolean reinstall, 
                String... extraArgs)

参数
packageFiles

reinstall boolean

extraArgs String

返回
String

抛出
DeviceNotAvailableException

installPackages

public String installPackages ( packageFiles, 
                boolean reinstall, 
                boolean grantPermissions, 
                String... extraArgs)

参数
packageFiles

reinstall boolean

grantPermissions boolean

extraArgs String

返回
String

抛出
DeviceNotAvailableException

installPackagesForUser

public String installPackagesForUser ( packageFiles, 
                boolean reinstall, 
                int userId, 
                String... extraArgs)

参数
packageFiles

reinstall boolean

userId int

extraArgs String

返回
String

抛出
DeviceNotAvailableException

installPackagesForUser

public String installPackagesForUser ( packageFiles, 
                boolean reinstall, 
                boolean grantPermissions, 
                int userId, 
                String... extraArgs)

参数
packageFiles

reinstall boolean

grantPermissions boolean

userId int

extraArgs String

返回
String

抛出
DeviceNotAvailableException

installRemotePackages

public String installRemotePackages ( remoteApkPaths, 
                boolean reinstall, 
                String... extraArgs)

参数
remoteApkPaths

reinstall boolean

extraArgs String

返回
String

抛出
DeviceNotAvailableException

installRemotePackages

public String installRemotePackages ( remoteApkPaths, 
                boolean reinstall, 
                boolean grantPermissions, 
                String... extraArgs)

参数
remoteApkPaths

reinstall boolean

grantPermissions boolean

extraArgs String

返回
String

抛出
DeviceNotAvailableException

isAppEnumerationSupported

public boolean isAppEnumerationSupported ()

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

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

抛出
DeviceNotAvailableException

isHeadlessSystemUserMode

public boolean isHeadlessSystemUserMode ()

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

返回
boolean

抛出
DeviceNotAvailableException

isMainUserPermanentAdmin

public boolean isMainUserPermanentAdmin ()

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

返回
boolean

抛出
DeviceNotAvailableException

isMultiUserSupported

public boolean isMultiUserSupported ()

确定是否支持多用户。

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

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

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

listDisplayIds

public  listDisplayIds ()

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

返回
展示广告列表。默认情况下,始终返回默认显示屏 0。

抛出
DeviceNotAvailableException

listDisplayIdsForStartingVisibleBackgroundUsers

public  listDisplayIdsForStartingVisibleBackgroundUsers ()

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

返回

抛出
DeviceNotAvailableException

listUsers

public  listUsers ()

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

返回
用户 ID 列表。

抛出
DeviceNotAvailableException

logBugreport

public boolean logBugreport (String dataName, 
                ITestLogger listener)

用于获取 bug 报告并将其记录到报告者的辅助方法。

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

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

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

notifySnapuserd

public void notifySnapuserd (SnapuserdWaitPhase waitPhase)

参数
waitPhase SnapuserdWaitPhase

postInvocationTearDown

public void postInvocationTearDown (Throwable exception)

设备特定所需清理的额外步骤,将在调用完成后执行。

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

removeAdmin

public boolean removeAdmin (String componentName, 
                int userId)

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

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

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

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

抛出
DeviceNotAvailableException

removeOwners

public void removeOwners ()

尽最大努力移除所有现有的设备配置文件所有者。

抛出
DeviceNotAvailableException

removeUser

public boolean removeUser (int userId)

从设备中移除指定用户。

参数
userId int:要移除的用户的

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

抛出
DeviceNotAvailableException

setDeviceOwner

public boolean setDeviceOwner (String componentName, 
                int userId)

在指定用户中将设备管理员组件设为设备所有者。

参数
componentName String:设备管理员成为设备所有者。

userId int:设备所有者居住地的用户。

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

抛出
DeviceNotAvailableException

setFirstBootloaderReboot

public void setFirstBootloaderReboot ()

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

shutdownMicrodroid

public void shutdownMicrodroid (ITestDevice microdroidDevice)

关闭 microdroid 设备(如果存在)。

参数
microdroidDevice ITestDevice

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

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

supportsMicrodroid

public boolean supportsMicrodroid ()

检查运行 microdroid 的前提条件。

返回
boolean 如果前提条件得到满足,则返回 true;否则返回 false。

supportsMicrodroid

public boolean supportsMicrodroid (boolean protectedVm)

检查运行 microdroid 的前提条件。

参数
protectedVm boolean:如果 microdroid 旨在受保护的虚拟机上运行,则为 true。

返回
boolean 如果前提条件得到满足,则返回 true;否则返回 false。

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

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

waitForSnapuserd

public void waitForSnapuserd (SnapuserdWaitPhase currentPhase)

参数
currentPhase SnapuserdWaitPhase

抛出
DeviceNotAvailableException

受保护的方法

createParser

protected AaptParser createParser (File appFile)

参数
appFile File

返回
AaptParser

doAdbReboot

protected void doAdbReboot (NativeDevice.RebootMode rebootMode, 
                String reason)

执行 adb 重启。

参数
rebootMode NativeDevice.RebootMode:相应重新启动的模式。

reason String:用于此重新启动。

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

getBugreportInternal

protected InputStreamSource getBugreportInternal ()

返回
InputStreamSource

getBugreportzInternal

protected File getBugreportzInternal ()

用于获取 bugreportz zip 文件(以 ERROR(/File) 形式)的内部辅助方法。

返回
File

getCheckNewUserSleep

protected long getCheckNewUserSleep ()

公开以供测试。

返回
long

getHostCurrentTime

protected long getHostCurrentTime ()

公开以进行测试

返回
long

prePostBootSetup

protected void prePostBootSetup ()

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

抛出
DeviceNotAvailableException