本地设备

public class NativeDevice
extends Object implements IManagedTestDevice , IConfigurationReceiver , ITestLoggerReceiver

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


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

概括

嵌套类

class NativeDevice.AdbAction

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

class NativeDevice.AdbShellAction

class NativeDevice.RebootDeviceAction

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

常数

int INVALID_USER_ID

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

long MAX_HOST_DEVICE_TIME_OFFSET

int MAX_RETRY_ATTEMPTS

执行命令重试的默认次数

领域

public static final String DEBUGFS_PATH

protected static final String SD_CARD

protected static final String STORAGE_EMULATED

protected TestDeviceOptions mOptions

protected final IDeviceStateMonitor mStateMonitor

公共构造函数

NativeDevice (IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)

创建一个TestDevice

公共方法

void batchPrefetchStartupBuildProps ()

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

boolean canSwitchToHeadlessSystemUser ()

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

boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

检查当前是否支持给定最低支持级别的功能。

boolean checkConnectivity ()

检查设备是否具有网络连接。

boolean clearErrorDialogs ()

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

void clearLastConnectedWifiNetwork ()

清除上次连接的 wifi 网络。

void clearLogcat ()

删除所有累积的 logcat 数据。

boolean connectToWifiNetwork ( wifiSsidToPsk, boolean scanSsid) connectToWifiNetwork ( wifiSsidToPsk, boolean scanSsid)

连接到 wifi 网络。

boolean connectToWifiNetwork (String wifiSsid, String wifiPsk)

连接到 wifi 网络。

boolean connectToWifiNetwork ( wifiSsidToPsk) connectToWifiNetwork ( wifiSsidToPsk)

连接到 wifi 网络.f

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

连接到 wifi 网络。

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

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

boolean connectToWifiNetworkIfNeeded (String wifiSsid, String wifiPsk)

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

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

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

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

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

int createUser (String name)

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

int createUserNoThrow (String name)

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

void deleteFile (String deviceFilePath)

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

void deregisterDeviceActionReceiver ( IDeviceActionReceiver deviceActionReceiver)

删除已注册的IDeviceActionReceiver

boolean deviceSoftRestarted ( ProcessInfo prevSystemServerProcess)

通过将当前 system_server 与以前的 system_server ProcessInfo进行比较来检查设备是否软重启的帮助程序方法。

boolean deviceSoftRestartedSince (long utcEpochTime, TimeUnit timeUnit)

用于检查设备是否自 UTC 时间以来设备及其ERROR(/TimeUnit)软重启的方法。

boolean disableAdbRoot ()

关闭 adb root。

void disableKeyguard ()

尝试禁用键盘保护。

boolean disableNetworkMonitor ()

禁用设备上的网络监控。

boolean disconnectFromWifi ()

与 WiFi 网络断开连接。

boolean doesFileExist (String deviceFilePath, int userId)

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

boolean doesFileExist (String deviceFilePath)

确定设备上的文件是否存在的帮助程序方法。

File dumpHeap (String process, String devicePath)

尝试从 system_server 转储堆。

boolean enableAdbRoot ()

打开 adb root。

boolean enableNetworkMonitor ()

启用设备上的网络监控。

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

将 adb 命令作为具有指定超时的系统命令执行的帮助程序方法。

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

将 adb 命令作为具有指定超时的系统命令执行的帮助程序方法。

String executeAdbCommand (String... cmdArgs)

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

CommandResult executeFastbootCommand (String... cmdArgs)

将 fastboot 命令作为系统命令执行的帮助程序方法,默认超时为 2 分钟。

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

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

CommandResult executeLongFastbootCommand (String... cmdArgs)

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

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

帮助程序方法,将长时间运行的 fastboot 命令作为具有系统环境变量的系统命令执行。

String executeShellCommand (String command)

执行 adb shell 命令并以String形式返回输出的 Helper 方法。

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

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

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

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

void executeShellCommand (String command, IShellOutputReceiver receiver)

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

CommandResult executeShellV2Command (String cmd)

执行 adb shell 命令并将结果作为CommandResult返回的帮助程序方法,其中正确填充了命令状态输出、stdout 和 stderr。

CommandResult executeShellV2Command (String cmd, OutputStream pipeToOutput)

执行 adb shell 命令并将结果作为CommandResult返回的帮助程序方法,其中正确填充了命令状态输出和 stderr。

CommandResult executeShellV2Command (String cmd, File pipeAsInput)

执行 adb shell 命令并将结果作为CommandResult返回的帮助程序方法,其中正确填充了命令状态输出、stdout 和 stderr。

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

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

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

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

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

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

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

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

CommandResult fastbootWipePartition (String partition)

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

getActiveApexes ()

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

getAllSettings (String namespace)

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

DeviceAllocationState getAllocationState ()

返回设备当前的分配状态

String getAndroidId (int userId)

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

getAndroidIds ()

创建一个找到匹配用户 ID 的 Android ID 地图。

int getApiLevel ()

获取设备 API 级别。

PackageInfo getAppPackageInfo (String packageName)

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

getAppPackageInfos ()

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

String getBasebandVersion ()

获取该设备的基带(无线电)版本的便捷方法。

Integer getBattery ()

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

boolean getBooleanProperty (String name, boolean defaultValue)

返回给定属性的布尔值。

getBootHistory ()

Helper 方法收集带有启动时间和启动原因的启动历史记录图。

getBootHistorySince (long utcEpochTime, TimeUnit timeUnit)

帮助程序方法收集启动历史记录图,其中包含自设备纪元以来的给定时间和指定的时间单位以来的启动时间和启动原因。

String getBootloaderVersion ()

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

InputStreamSource getBugreport ()

从设备检索错误报告。

InputStreamSource getBugreportz ()

从设备检索错误报告。

String getBuildAlias ()

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

String getBuildFlavor ()

检索设备的构建风格。

String getBuildId ()

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

String getBuildSigningKeys ()

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

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

DeviceDescriptor getCachedDeviceDescriptor ()

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

DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

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

String[] getChildren (String path)

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

AbstractConnection getConnection ()

与设备关联的当前连接。

DeviceFoldableState getCurrentFoldableState ()

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

int getCurrentUser ()

返回当前运行用户的id。

String getDeviceClass ()

获取设备类别。

long getDeviceDate ()

返回设备的日期(自纪元以来的毫秒数)。

DeviceDescriptor getDeviceDescriptor ()

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

DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

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

TestDeviceState getDeviceState ()

获取设备的状态。

long getDeviceTimeOffset (Date date)

帮助获取设备与给定ERROR(/Date)之间的时差。

InputStreamSource getEmulatorOutput ()

获取模拟器stdout和stderr的流

Process getEmulatorProcess ()

返回该模拟器对应的Process

final File getExecuteShellCommandLog ()

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

long getExternalStoreFreeSpace ()

用于确定设备外部存储上的可用空间量的帮助程序方法。

String getFastbootPath ()

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

String getFastbootProductType ()

当设备处于快速启动模式时获取该设备的产品类型的便捷方法。

String getFastbootProductVariant ()

当设备处于快速启动模式时获取该设备的产品类型的便捷方法。

String getFastbootSerialNumber ()

返回快速启动模式序列号。

String getFastbootVariable (String variableName)

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

String getFastbootVersion ()

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

IFileEntry getFileEntry (String path)

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

IFileEntry getFileEntry (FileListingService.FileEntry entry)

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

getFoldableStates ()

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

IDevice getIDevice ()

返回对关联 ddmlib IDevice的引用。

getInstalledPackageNames ()

获取设备上存在的应用程序包名称。

long getIntProperty (String name, long defaultValue)

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

String getIpAddress ()

获取设备的IP地址。

KeyguardControllerState getKeyguardState ()

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

long getLastExpectedRebootTimeMillis ()

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

int getLaunchApiLevel ()

获取设备首次启动的 API 级别。

InputStreamSource getLogcat ()

获取 logcat 数据的快照流。

InputStreamSource getLogcat (int maxBytes)

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

InputStreamSource getLogcatDump ()

获取设备当前 logcat 的转储。

InputStreamSource getLogcatSince (long date)

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

String getMacAddress ()

返回设备的MAC地址,如果向设备查询失败则返回null。

Integer getMainUserId ()

返回主用户 ID。

getMainlineModuleInfo ()

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

int getMaxNumberOfRunningUsersSupported ()

获取支持的同时运行用户的最大数量。

int getMaxNumberOfUsersSupported ()

获取支持的最大用户数。

Process getMicrodroidProcess ()
IDeviceStateMonitor getMonitor ()

返回与设备关联的IDeviceStateMonitor

String getMountPoint (String mountName)

返回一个挂载点。

ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

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

getMountPointInfo ()

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

TestDeviceOptions getOptions ()

获取设备的测试选项。

long getPartitionFreeSpace (String partition)

确定设备分区上的可用空间量的帮助程序方法。

Integer getPrimaryUserId ()

返回主要用户 ID。

ProcessInfo getProcessByName (String processName)

Helper 方法运行“pidof”和“stat”命令,并返回带有给定进程的 PID 和进程启动时间的ProcessInfo对象。

String getProcessPid (String process)

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

String getProductType ()

获取该设备的产品类型的便捷方法。

String getProductVariant ()

获取该设备的产品变型的便捷方法。

String getProperty (String name)

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

ITestDevice.RecoveryMode getRecoveryMode ()

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

InputStreamSource getScreenshot (String format)

从设备抓取屏幕截图。

InputStreamSource getScreenshot (long displayId)

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

InputStreamSource getScreenshot (String format, boolean rescale)

从设备抓取屏幕截图。

InputStreamSource getScreenshot ()

从设备抓取屏幕截图。

String getSerialNumber ()

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

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

返回所请求设置的值。

String getSetting (String namespace, String key)

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

String getSimOperator ()

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

String getSimState ()

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

getTombstones ()

从设备中获取并返回逻辑删除列表。

long getTotalMemory ()

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

getUninstallablePackageNames ()

获取可卸载的应用程序包名称。

boolean getUseFastbootErase ()

获取是否使用 fastboot 擦除或 fastboot 格式来擦除设备上的分区。

int getUserFlags (int userId)

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

getUserInfos ()

获取设备上 useId 到UserInfo的 Map。

int getUserSerialNumber (int userId)

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

IManagedTestDevice.DeviceEventResponse handleAllocationEvent (DeviceEvent event)

处理给定的DeviceEvent。

处理 DeviceEvent,这可能会也可能不会将该设备转换到新的分配状态。

boolean hasFeature (String feature)

检查设备上是否有可用的功能。

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

在设备上安装 Android 软件包。

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

在设备上安装 Android 软件包。

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

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

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

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

void invalidatePropertyCache ()
boolean isAdbRoot ()

boolean isAdbTcp ()
boolean isAppEnumerationSupported ()

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

boolean isBypassLowTargetSdkBlockSupported ()

检查设备上的平台是否支持绕过应用程序安装时的低目标 sdk 块

boolean isDebugfsMounted ()

检查 debugfs 是否已安装。

boolean isDeviceEncrypted ()

返回设备是否已加密。

boolean isDirectory (String path)

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

boolean isEnableAdbRoot ()
boolean isEncryptionSupported ()

返回设备是否支持加密。

boolean isExecutable (String fullPath)

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

boolean isFastbootEnabled ()

返回设备是否可以使用 fastboot。

boolean isHeadless ()

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

boolean isHeadlessSystemUserMode ()

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

boolean isMainUserPermanentAdmin ()

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

boolean isMultiUserSupported ()

确定是否支持多用户。

boolean isPackageInstalled (String packageName, String userId)

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

boolean isPackageInstalled (String packageName)

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

boolean isRuntimePermissionSupported ()

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

boolean isStateBootloaderOrFastbootd ()

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

boolean isUserRunning (int userId)

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

boolean isUserSecondary (int userId)

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

boolean isUserVisible (int userId)

检查给定用户是否可见。

boolean isUserVisibleOnDisplay (int userId, int displayId)

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

boolean isVisibleBackgroundUsersOnDefaultDisplaySupported ()

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

boolean isVisibleBackgroundUsersSupported ()

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

boolean isWifiEnabled ()

测试 wifi 是否已启用。

listDisplayIds ()

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

listDisplayIdsForStartingVisibleBackgroundUsers ()

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

listUsers ()

获取设备上的用户列表。

boolean logAnrs ( ITestLogger logger)

从设备收集并记录 ANR。

boolean logBugreport (String dataName, ITestLogger listener)

获取错误报告并将其记录给报告者的帮助方法。

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

在设备的 logcat 中记录消息。

void mountDebugfs ()

挂载调试文件。

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)

从设备中递归提​​取目录内容。

boolean pullFile (String remoteFilePath, File localFile)

从设备上检索文件。

File pullFile (String remoteFilePath, int userId)

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

File pullFile (String remoteFilePath)

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

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

从设备上检索文件。

String pullFileContents (String remoteFilePath)

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

File pullFileFromExternal (String remoteFilePath)

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

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

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

boolean pushDir (File localFileDir, String deviceFilePath)

递归地将目录内容推送到设备。

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

pushFile(File, String)的变体,可以选择考虑评估内容提供者的需求。

boolean pushFile (File localFile, String remoteFilePath)

将文件推送到设备。

boolean pushString (String contents, String remoteFilePath)

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

void reboot (String reason)

将设备重新启动到 adb 模式,并给出在重新启动后保留的reason

void reboot ()

将设备重新启动至 adb 模式。

void rebootIntoBootloader ()

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

void rebootIntoFastbootd ()

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

void rebootIntoRecovery ()

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

void rebootIntoSideload ()

重新启动设备进入 adb sideload 模式(请注意,这是恢复下的特殊模式)

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

void rebootIntoSideload (boolean autoReboot)

重新启动设备进入 adb sideload 模式(请注意,这是恢复下的特殊模式)

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

void rebootUntilOnline ()

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

void rebootUntilOnline (String reason)

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

void rebootUserspace ()

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

void rebootUserspaceUntilOnline ()

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

boolean recoverDevice ()

尝试恢复设备通信。

void registerDeviceActionReceiver ( IDeviceActionReceiver deviceActionReceiver)

为此设备注册一个IDeviceActionReceiver

void remountSystemReadOnly ()

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

void remountSystemWritable ()

使设备上的系统分区可写。

void remountVendorReadOnly ()

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

void remountVendorWritable ()

使设备上的供应商分区可写。

boolean removeAdmin (String componentName, int userId)

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

void removeOwners ()

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

boolean removeUser (int userId)

从设备中删除给定用户。

void resetContentProviderSetup ()

重置内容提供商设置的标志以便再次触发它。

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

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

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

运行仪器测试并提供设备恢复。

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

ERROR(ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)/com.android.tradefed.device.ITestDevice#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection) ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection))但运行测试对于给定的用户。

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

ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...)相同,但为给定用户运行测试。

void setConfiguration ( IConfiguration configuration)

注入正在使用的IConfiguration

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

设置设备上的日期

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

boolean setDeviceOwner (String componentName, int userId)

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

void setDeviceState ( TestDeviceState deviceState)

更新设备的状态。

void setEmulatorOutputStream ( SizeLimitedOutputStream output)

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

void setEmulatorProcess (Process p)

当该设备是模拟器时,设置Process

void setFastbootEnabled (boolean fastbootEnabled)

设置设备的快速启动选项。

void setFastbootPath (String fastbootPath)

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

void setIDevice (IDevice newDevice)

更新与此 ITestDevice 关联的 IDevice。

void setLogStartDelay (int delay)

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

void setOptions ( TestDeviceOptions options)

设置设备的TestDeviceOptions

boolean setProperty (String propKey, String propValue)

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

void setRecovery ( IDeviceRecovery recovery)

设置用于此设备的IDeviceRecovery

void setRecoveryMode ( ITestDevice.RecoveryMode mode)

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

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

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

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

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

void setTestLogger ( ITestLogger testLogger)

注入ITestLogger实例

void setUseFastbootErase (boolean useFastbootErase)

设置是否使用 fastboot 擦除或 fastboot 格式来擦除设备上的分区。

void startLogcat ()

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

boolean startUser (int userId)

如果给定用户当前已停止,则在后台启动该用户。

boolean startUser (int userId, boolean waitFlag)

如果给定用户当前已停止,则在后台启动该用户。

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

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

void stopEmulatorOutput ()

关闭并删除模拟器输出。

void stopLogcat ()

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

boolean stopUser (int userId)

停止给定用户。

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

停止给定用户。

String switchToAdbTcp ()

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

boolean switchToAdbUsb ()

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

boolean switchUser (int userId)

切换到另一个具有默认超时的用户 ID。

boolean switchUser (int userId, long timeout)

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

boolean syncFiles (File localFileDir, String deviceFilePath)

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

Bugreport takeBugreport ()

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

String uninstallPackage (String packageName)

从设备卸载 Android 软件包。

String uninstallPackageForUser (String packageName, int userId)

从设备上为给定用户卸载 Android 软件包。

boolean unlockDevice ()

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

void unmountDebugfs ()

卸载 debugfs。

boolean waitForBootComplete (long timeOut)

阻塞直到设置设备的启动完成标志。

boolean waitForDeviceAvailable ()

等待设备响应并可用于测试。

boolean waitForDeviceAvailable (long waitTime)

等待设备响应并可用于测试。

boolean waitForDeviceAvailableInRecoverPath (long waitTime)

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

void waitForDeviceBootloader ()

阻塞直到设备通过 fastboot 可见。

boolean waitForDeviceInRecovery (long waitTime)

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

boolean waitForDeviceInSideload (long waitTime)

阻止设备处于“adb 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)

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

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

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

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

执行 adb 重启。

void ensureRuntimePermissionSupported ()

如果不支持运行时权限,则抛出异常的辅助方法

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

获取要使用的RunUtil实例。

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

默认情况下从 ddmlib 缓存中获取设备属性,然后根据设备是否处于 Fastboot 状态,返回到“adb shell getprop”或“fastboot getvar”。

boolean isInRebootCallback ()

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

boolean isNewer (File localFile, IFileEntry entry)

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

void notifyRebootEnded ()

通知所有IDeviceActionReceiver有关重新启动结束事件的信息。

void notifyRebootStarted ()

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

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

在此设备上执行操作。

void postAdbReboot ()

重新启动后可能采取的额外操作。

void prePostBootSetup ()

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

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

设置要使用的 Clock 实例。

void setMicrodroidProcess (Process process)

将 TestDevice 标记为 microdroid 并设置其 CID。

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

使用环境变量执行简单的 fastboot 命令并报告命令的状态。

CommandResult simpleFastbootCommand (long timeout, String[] fullCmd)

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

boolean waitForDeviceNotAvailable (String operationDesc, long time)

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

常数

INVALID_USER_ID

public static final int INVALID_USER_ID

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

常量值:-10000 (0xffffd8f0)

MAX_HOST_DEVICE_TIME_OFFSET

protected static final long MAX_HOST_DEVICE_TIME_OFFSET

常量值:5000 (0x0000000000001388)

最多重试次数

protected static final int MAX_RETRY_ATTEMPTS

执行命令重试的默认次数

常量值:2 (0x00000002)

领域

调试路径

public static final String DEBUGFS_PATH

SD卡

protected static final String SD_CARD

存储_模拟

protected static final String STORAGE_EMULATED

m选项

protected TestDeviceOptions mOptions

状态监视器

protected final IDeviceStateMonitor mStateMonitor

公共构造函数

本地设备

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

创建一个TestDevice

参数
device IDevice :关联的IDevice

stateMonitor IDeviceStateMonitor :要使用的IDeviceStateMonitor机制

allocationMonitor IDeviceMonitor :通知分配状态更改的IDeviceMonitor 。可以为空

公共方法

batchPrefetchStartupBuildProps

public void batchPrefetchStartupBuildProps ()

通过预取我们需要的所有道具而不是为每个道具调用“adb getprop”来进行微优化(大约 400 毫秒)。即,获取所有属性与获取一个属性一样快。像 device.getApiLevel()、checkApiLevelAgainstNextRelease 和 getBuildAlias 这样的东西都在底层调用“adb getprop”。我们通过一次调用获取它们并调用 NativeDevice.setProperty。即使我们不这样做,NativeDevice 本身也会调用 setProperty 并缓存结果以供将来调用。我们只是稍微提前了一点。如果设备处于恢复状态或在获取道具时出现其他错误,我们将忽略它们。

可以切换到Headless系统用户

public boolean canSwitchToHeadlessSystemUser ()

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

退货
boolean

投掷
DeviceNotAvailableException

检查 ApiLevelAgainstNextRelease

public boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

检查当前是否支持给定最低支持级别的功能。此方法考虑了 API 级别提升之前尚未发布的功能。

参数
strictMinLevel int :支持该功能的严格的最小可能级别。

退货
boolean如果支持该级别,则为 True。否则为假。

投掷
DeviceNotAvailableException

检查连接性

public boolean checkConnectivity ()

检查设备是否具有网络连接。

退货
boolean如果设备有有效的网络连接, true ,否则为false

投掷
DeviceNotAvailableException

清除错误对话框

public boolean clearErrorDialogs ()

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

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

投掷
DeviceNotAvailableException

清除上次连接的 Wifi 网络

public void clearLastConnectedWifiNetwork ()

清除上次连接的 wifi 网络。应在开始新调用时调用此函数,以避免在设备重新启动后连接到先前测试中使用的 wifi 网络。

清除Logcat

public void clearLogcat ()

删除所有累积的 logcat 数据。

当您想要确保ITestDevice#getLogcat()仅返回在某个点之后(例如刷新新设备版本后等)生成的日志数据时,这非常有用。

连接到Wifi网络

public boolean connectToWifiNetwork ( wifiSsidToPsk, 
                boolean scanSsid)

连接到 wifi 网络。

打开 wifi 并阻止,直到与 wifiSsidToPsk 映射中给出的 wifi 网络之一成功连接。建立连接后,实例将在每次重新启动后尝试恢复连接,直到调用ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork()为止。

参数
wifiSsidToPsk :wifi SSID 到密码的映射。

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

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

连接到Wifi网络

public boolean connectToWifiNetwork (String wifiSsid, 
                String wifiPsk)

连接到 wifi 网络。

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

参数
wifiSsid String : 要连接的 wifi ssid

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

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

连接到Wifi网络

public boolean connectToWifiNetwork ( wifiSsidToPsk)

连接到 wifi 网络。

打开 wifi 并阻止,直到与 wifiSsidToPsk 映射中给出的 wifi 网络之一成功连接。一旦建立连接,实例将在每次重新启动后尝试恢复连接,直到调用ITestDevice#disconnectFromWifi()ITestDevice#clearLastConnectedWifiNetwork()

参数
wifiSsidToPsk :wifi SSID 到密码的映射。

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

连接到Wifi网络

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

连接到 wifi 网络。

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

参数
wifiSsid String : 要连接的 wifi ssid

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

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

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

如果需要连接到 Wifi 网络

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

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

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

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

如果需要连接到 Wifi 网络

public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk)

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

退货
boolean如果成功连接到 wifi 网络则为true 。否则为false

投掷
DeviceNotAvailableException

创建用户

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

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

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

guest boolean : 在创建过程中启用用户标志 --guest

ephemeral boolean :在创建过程中启用用户标志 --ephemeral

退货
int创建用户的id

投掷
DeviceNotAvailableException

创建用户

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

创建用户

public int createUser (String name)

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

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

退货
int创建的用户 ID 的整数

投掷
DeviceNotAvailableException

创建用户不抛出

public int createUserNoThrow (String name)

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

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

退货
int创建的用户 ID 的整数或 -1 表示错误。

投掷
DeviceNotAvailableException

删除文件

public void deleteFile (String deviceFilePath)

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

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

投掷
DeviceNotAvailableException

注销设备操作接收器

public void deregisterDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

删除已注册的IDeviceActionReceiver

参数
deviceActionReceiver IDeviceActionReceiver :将被删除的IDeviceActionReceiver

设备软重启

public boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

通过将当前 system_server 与以前的 system_server ProcessInfo进行比较来检查设备是否软重启的帮助程序方法。使用getProcessByName(String)获取ProcessInfo

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

退货
boolean如果设备软重启则为true

投掷
DeviceNotAvailableException

设备软重启以来

public boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

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

退货
boolean如果设备软重启则为true

投掷
DeviceNotAvailableException

禁用AdbRoot

public boolean disableAdbRoot ()

关闭 adb root。

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

退货
boolean如果成功则为true

投掷
DeviceNotAvailableException

禁用键盘锁

public void disableKeyguard ()

尝试禁用键盘保护。

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

投掷
DeviceNotAvailableException

禁用网络监视器

public boolean disableNetworkMonitor ()

禁用设备上的网络监控。

退货
boolean如果成功禁用监控则为true 。如果失败则为false

投掷
DeviceNotAvailableException

断开与Wifi的连接

public boolean disconnectFromWifi ()

与 WiFi 网络断开连接。

从已知网络列表中删除所有网络并禁用 wifi。

退货
boolean如果成功断开与 wifi 网络的连接,则为true 。如果断开连接失败,则false

投掷
DeviceNotAvailableException

文件是否存在

public boolean doesFileExist (String deviceFilePath, 
                int userId)

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

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

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

退货
boolean如果文件存在true ,否则为false

投掷
DeviceNotAvailableException

文件是否存在

public boolean doesFileExist (String deviceFilePath)

确定设备上的文件是否存在的帮助程序方法。

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

退货
boolean如果文件存在true ,否则为false

投掷
DeviceNotAvailableException

转储堆

public File dumpHeap (String process, 
                String devicePath)

尝试从 system_server 转储堆。调用者有责任清理转储的文件。

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

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

退货
File包含报告的ERROR(/File) 。如果某件事失败则为空。

投掷
DeviceNotAvailableException

启用AdbRoot

public boolean enableAdbRoot ()

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

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

退货
boolean如果成功则为true

投掷
DeviceNotAvailableException

启用网络监视器

public boolean enableNetworkMonitor ()

启用设备上的网络监控。

退货
boolean true如果监控启用成功。如果失败则为false

投掷
DeviceNotAvailableException

执行Adb命令

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

将 adb 命令作为具有指定超时的系统命令执行的帮助程序方法。

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

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

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

退货
String命令的标准输出。如果命令执行失败则为null

投掷
DeviceNotAvailableException

执行Adb命令

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

将 adb 命令作为具有指定超时的系统命令执行的帮助程序方法。

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

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

envMap :为命令设置的环境

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

退货
String命令的标准输出。如果命令执行失败则为null

投掷
DeviceNotAvailableException

执行Adb命令

public String executeAdbCommand (String... cmdArgs)

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

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

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

退货
String命令的标准输出。如果命令执行失败则为null

投掷
DeviceNotAvailableException

执行Fastboot命令

public CommandResult executeFastbootCommand (String... cmdArgs)

将 fastboot 命令作为系统命令执行的帮助程序方法,默认超时为 2 分钟。

预计在设备已处于快速启动模式时使用。

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

退货
CommandResult包含命令输出的 CommandResult

投掷
DeviceNotAvailableException

执行Fastboot命令

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

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

预计在设备已处于快速启动模式时使用。

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

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

退货
CommandResult包含命令输出的 CommandResult

投掷
DeviceNotAvailableException

执行LongFastboot命令

public CommandResult executeLongFastbootCommand (String... cmdArgs)

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

executeFastbootCommand(String)相同,只是使用更长的超时。

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

退货
CommandResult包含命令输出的 CommandResult

投掷
DeviceNotAvailableException

执行LongFastboot命令

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

帮助程序方法,将长时间运行的 fastboot 命令作为具有系统环境变量的系统命令执行。

executeFastbootCommand(String)相同,但使用较长的超时。

参数
envVarMap :fastboot命令随附的系统环境变量

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

退货
CommandResult包含命令输出的命令重点

投掷
DeviceNotAvailableException

执行Shell命令

public String executeShellCommand (String command)

执行ADB Shell命令并将输出作为String返回的帮助方法。

参数
command String :运行的ADB shell命令

退货
String外壳输出

投掷
DeviceNotAvailableException

执行Shell命令

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

执行ADB Shell命令,其中有更多参数可以控制命令行为。

参数
command String :运行的ADB shell命令

receiver IShellOutputReceiverIShellOutputReceiver将shell输出转到。

maxTimeToOutputShellResponse long :允许命令不输出任何响应的最大时间; timeUnit指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse的单位

retryAttempts int :如果由于异常而失败,则重试命令的最大次数。如果在没有成功的情况下执行retryAttempts deviceNotresponsiveException,则将投掷。

投掷
DeviceNotAvailableException

执行Shell命令

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

执行ADB Shell命令,其中有更多参数可以控制命令行为。

参数
command String :运行的ADB shell命令

receiver IShellOutputReceiverIShellOutputReceiver将shell输出转到。

maxTimeoutForCommand long :命令完成的最大超时; timeUnit指定的单位

maxTimeToOutputShellResponse long :允许命令不输出任何响应的最大时间; timeUnit指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse的单位

retryAttempts int :如果由于异常而失败,则重试命令的最大次数。如果在没有成功的情况下执行retryAttempts deviceNotresponsiveException,则将投掷。

投掷
DeviceNotAvailableException

执行Shell命令

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

执行给定的ADB Shell命令,如果命令失败,则多次重试。

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

参数
command String :运行的ADB shell命令

receiver IShellOutputReceiverIShellOutputReceiver将shell输出转到。

投掷
DeviceNotAvailableException

executeshellv2Command

public CommandResult executeShellV2Command (String cmd)

执行ADB shell命令并将结果返回的助手方法作为命令状态输出,stdout和stderr正确填充的CommandResult重点。

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

退货
CommandResult CommandResult的结果。

投掷
DeviceNotAvailableException

executeshellv2Command

public CommandResult executeShellV2Command (String cmd, 
                OutputStream pipeToOutput)

执行ADB shell命令并将结果返回的助手方法作为命令状态输出和stderr正确填充的CommandResult 。 STDOUT定向到指定的流。

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

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

退货
CommandResult CommandResult的结果。

投掷
DeviceNotAvailableException

executeshellv2Command

public CommandResult executeShellV2Command (String cmd, 
                File pipeAsInput)

执行ADB shell命令并将结果返回的助手方法作为命令状态输出,Stdout和stderr正确填充的CommandResult重点。

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

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

退货
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 TimeUnitmaxTimeToOutputShellResponse的单位

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 TimeUnitmaxTimeToOutputShellResponse的单位

退货
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 :将作为命令或null输入输入的ERROR(/File)

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

maxTimeoutForCommand long :命令完成的最大超时; timeUnit指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse的单位

retryAttempts int :如果由于异常而失败,则重试命令的最大次数。如果在没有成功的情况下执行retryAttempts deviceNotresponsiveException,则将投掷。

退货
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 :将作为命令或null输入输入的ERROR(/File)

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

pipeToError OutputStreamERROR(/OutputStream)其中将重定向性std错误或null。

maxTimeoutForCommand long :命令完成的最大超时; timeUnit指定的单位

timeUnit TimeUnitmaxTimeToOutputShellResponse的单位

retryAttempts int :如果由于异常而失败,则重试命令的最大次数。如果在没有成功的情况下执行retryAttempts deviceNotresponsiveException,则将投掷。

退货
CommandResult

投掷
DeviceNotAvailableException

FastBootWiPepartition

public CommandResult fastbootWipePartition (String partition)

助手方法擦除设备的分区。

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

预计设备已经处于快速启动模式时使用。

参数
partition String :擦除的分区

退货
CommandResult包含命令输出的命令重点

投掷
DeviceNotAvailableException

getActiveapeS

public  getActiveApexes ()

获取有关在设备上激活的顶点的信息。

退货
当前在设备上激活的ApexInfoERROR(/Set)

投掷
DeviceNotAvailableException

getallSettings

public  getAllSettings (String namespace)

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

参数
namespace String :必须是{“系统”,“安全”,“全局”}之一

退货
钥匙值对的地图。 null如果不支持名称空间。

投掷
DeviceNotAvailableException

getallocationstate

public DeviceAllocationState getAllocationState ()

返回当前设备的分配状态

退货
DeviceAllocationState

获取AndroidId

public String getAndroidId (int userId)

查找并返回与用户ID相关的Android-ID,如果找不到的(未找到)。

参数
userId int

退货
String

投掷
DeviceNotAvailableException

getandroids

public  getAndroidIds ()

创建一个匹配用户ID的Android ID的地图。每个用户ID都不会在此功能中找到关联的Android ID,因此某些用户ID可能与NULL匹配。

退货
Android ID的地图找到了匹配的用户ID。

投掷
DeviceNotAvailableException

getapilevel

public int getApiLevel ()

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

退货
int一个表示设备API级别的整数

投掷
DeviceNotAvailableException

getapppackageinfo

public PackageInfo getAppPackageInfo (String packageName)

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

参数
packageName String

退货
PackageInfo如果null PackageInfo信息

投掷
DeviceNotAvailableException

getapppackageinfos

public  getAppPackageInfos ()

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

退货
设备上安装的PackageInfoERROR(/List)

投掷
DeviceNotAvailableException

GetBaseBandversion

public String getBasebandVersion ()

获取此设备基带(无线电)版本的便利方法。获取广播版本是特定于设备的,因此它可能不会返回所有设备的正确信息。此方法依赖于gsm.version.baseband Propery返回正确的版本信息。对于某些CDMA设备而言,这是不准确的,此处返回的版本可能与FastBoot报告的版本不匹配,也可能无法返回CDMA Radio的版本。 TL; DR此方法仅在gsm.version.baseband属性与fastboot getvar version-baseband返回的版本相同时才报告准确的版本。

退货
String String基带版本或null如果无法确定(设备没有无线电或版本字符串)

投掷
DeviceNotAvailableException

GetBattery

public Integer getBattery ()

如果电池电量不可用,将返回设备的当前电池电量或无效的电池电量。

退货
Integer

getBooleanproperty

public boolean getBooleanProperty (String name, 
                boolean defaultValue)

返回给定属性的布尔值。

参数
name String :属性名称

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

退货
boolean如果属性具有值"1""off" "y""yes" "on" "0" "n" "no" "true"false true否则"false"defaultValue

投掷
DeviceNotAvailableException

GetBoothistory

public  getBootHistory ()

助手方法通过引导时间和启动原因收集引导历史图。

退货
启动时间的地图(自时代以来为第二个UTC时间)和引导原因

投掷
DeviceNotAvailableException

GetBoothistorys

public  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

助手方法以启动时间和启动原因收集启动历史图以来,自设备时期以来的给定时间和指定的时间单元。当前的设备utcepochtime以毫秒为单位,可以通过方法getDeviceDate()获得。

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

timeUnit TimeUnit :Time单元时间TimeUnit

退货
启动时间的地图(自时代以来为第二个UTC时间)和引导原因

投掷
DeviceNotAvailableException

getBootloaderversion

public String getBootloaderVersion ()

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

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

退货
String String引导程序版本或null如果找不到

投掷
DeviceNotAvailableException

GetBugreport

public InputStreamSource getBugreport ()

从设备检索BugReport。

保证的实现可以继续在没有SDCARD的设备上工作(或者尚未安装SDCARD)。

退货
InputStreamSource InputStreamSource将按需生产BugReport内容。如果发生故障, InputStreamSource将产生一个空ERROR(/InputStream)

GetBugreportz

public InputStreamSource getBugreportz ()

从设备检索Bugreportz。 zip格式BugReport包含用于调试的主要BugReport和其他日志文件。

仅支持“ ADB版本”> 1.0.36

退货
InputStreamSource包含bugreportz的zip文件的InputStreamSource ,在失败的情况下返回null。

GetBuildalias

public String getBuildAlias ()

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

构建别名通常比构建ID(通常是Nexus构建的数字)更可读的字符串。例如,Final Android 4.2发行版已构建别名JDQ39,并构建ID 573038

退货
String构建别名或倒退以构建ID(如果无法检索)

投掷
DeviceNotAvailableException

GetBuildFlavor

public String getBuildFlavor ()

检索设备的制造风味。

退货
String如果无法检索的构建风味或无效

投掷
DeviceNotAvailableException

GetBuildid

public String getBuildId ()

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

退货
String如果无法IBuildInfo#UNKNOWN_BUILD_ID

投掷
DeviceNotAvailableException

GetBuildSigningKeys

public String getBuildSigningKeys ()

返回用于签署设备图像的密钥类型

通常,Android设备可以用测试键(例如AOSP)或释放键(由单个设备制造商控制)签名

退货
String签名密钥如果发现,则否则为空。

投掷
DeviceNotAvailableException

GetCachedDevicedScriptor

public DeviceDescriptor getCachedDeviceDescriptor ()

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

退货
DeviceDescriptor

GetCachedDevicedScriptor

public DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

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

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

退货
DeviceDescriptor

获取孩子

public String[] getChildren (String path)

替代使用IFileEntry ,有时由于权限而无法工作。

参数
path String :是设备上搜索的路径

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

投掷
DeviceNotAvailableException

getConnection

public AbstractConnection getConnection ()

与设备关联的当前连接。

退货
AbstractConnection

getCurrentFoldableState

public DeviceFoldableState getCurrentFoldableState ()

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

退货
DeviceFoldableState

投掷
DeviceNotAvailableException

获取当前用户

public int getCurrentUser ()

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

退货
int

投掷
DeviceNotAvailableException

GetDeviceClass

public String getDeviceClass ()

获取设备类。

退货
String String设备类。

GetDevedate

public long getDeviceDate ()

自时代以来,以毫秒为单位返回设备的日期。

退货
long设备以时期格式的日期。

投掷
DeviceNotAvailableException

getDevicedScriptor

public DeviceDescriptor getDeviceDescriptor ()

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

退货
DeviceDescriptor

getDevicedScriptor

public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

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

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

退货
DeviceDescriptor

GetDevicestate

public TestDeviceState getDeviceState ()

获取设备的状态。

退货
TestDeviceState

getDevicEtimeOffset

public long getDeviceTimeOffset (Date date)

助手以获得设备和给定ERROR(/Date)之间的时差。内部使用时代时间。

参数
date Date

退货
long毫秒的差异

投掷
DeviceNotAvailableException

geteMulatorOutput

public InputStreamSource getEmulatorOutput ()

获取模拟器Stdout和stderr的流

退货
InputStreamSource模拟器输出

GeteMulatorProcess

public Process getEmulatorProcess ()

返回与此模拟器相对应的Process

退货
Process Processnull

getExecuteshellCommandLog

public final File getExecuteShellCommandLog ()

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

退货
File

getExternalStoreFreeSpace

public long getExternalStoreFreeSpace ()

帮助确定设备外部存储空间的辅助方法。

退货
long KB中的自由空间数量

投掷
DeviceNotAvailableException

GetFastBootPath

public String getFastbootPath ()

返回使用快速启动二进制的路径。仍然需要isFastbootEnabled()为真,以启用FastBoot函数。

退货
String

GetFastBootProductType

public String getFastbootProductType ()

在快速启动模式下,以获取该设备的产品类型的便利方法。

仅当设备应在FastBoot中时,才应使用此方法。在这种情况下,它比通用getProductType()方法更安全,因为如果设备处于不正确状态或无响应措施,则iTestDevice将知道将设备恢复到FastBoot中。

退货
String String产品类型名称或null如果无法确定

投掷
DeviceNotAvailableException

GetFastBootProductVariant

public String getFastbootProductVariant ()

在快速启动模式下,以获取该设备的产品类型的便利方法。

仅当设备应在FastBoot中时,才应使用此方法。在这种情况下,它比通用getProductType()方法更安全,因为如果设备处于不正确状态或无响应措施,则iTestDevice将知道将设备恢复到FastBoot中。

退货
String String产品类型名称或null如果无法确定

投掷
DeviceNotAvailableException

GetFastBootSerialnumber

public String getFastbootSerialNumber ()

返回FastBoot模式序列号。

退货
String

GetFastBootVaria

public String getFastbootVariable (String variableName)

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

参数
variableName String :变量名称

退货
String属性值或null (如果不存在)

投掷
DeviceNotAvailableException

GetFastBootversion

public String getFastbootVersion ()

返回使用的FastBoot二进制的版本字符串。或者如果出现问题,则无效。

退货
String

getfileentry

public IFileEntry getFileEntry (String path)

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

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

退货
IFileEntry如果找不到给定path的文件,则IFileEntrynull

投掷
DeviceNotAvailableException

getfileentry

public IFileEntry getFileEntry (FileListingService.FileEntry entry)

非正式的助手可以从非根路径获得FileEntry 。 FIXME:重构Fileentry系统将其从任何路径可用。 (甚至非根)。

参数
entry FileListingService.FileEntryFileEntry不一定按照DDMLIB的要求。

退货
IFileEntry代表fileentry的fileentrywrapper。

投掷
com.android.tradefed.device.devicenotavailable Exception
DeviceNotAvailableException

GetFoldableStates

public  getFoldableStates ()

返回设备上可折叠状态的列表。可以使用“ CMD Device_state打印状态”获得。

退货

投掷
DeviceNotAvailableException

GetIdevice

public IDevice getIDevice ()

返回对关联的DDMLIB IDevice引用。

每当设备断开并重新连接ADB时,DDM都可以通过DDMS分配新的IDevice 。因此,呼叫者不应对IDevice进行引用,因为该参考可能会变成陈旧。

退货
IDevice IDevice

GetInstalledPackagenames

public  getInstalledPackageNames ()

获取设备上存在的应用程序包名称。

退货
当前在设备上安装的String软件包名称的ERROR(/Set)

投掷
DeviceNotAvailableException

获取整数属性

public long getIntProperty (String name, 
                long defaultValue)

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

参数
name String :属性名称

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

退货
long属性值或defaultValue如果属性为空,不存在或没有整数值。

投掷
DeviceNotAvailableException

获取IP地址

public String getIpAddress ()

获取设备的IP地址。

退货
String设备的IP地址,如果设备没有IP地址,则为null

投掷
DeviceNotAvailableException

GetKeyguardstate

public KeyguardControllerState getKeyguardState ()

返回对象以获取钥匙守卫或null的当前状态,如果不支持。

退货
KeyguardControllerState一个包含密钥守卫状态的快照的KeyguardControllerState ,如果不支持密钥守卫查询,则返回null。

投掷
DeviceNotAvailableException

getlasteppedReboottimemillis

public long getLastExpectedRebootTimeMillis ()

System.currentTimeMillis()返回以来,返回最后一次交易的API触发了一次以毫秒为单位的重新启动。

退货
long

getlaunchapilevel

public int getLaunchApiLevel ()

获取设备的第一个启动API级别。默认为UNKNOWN_API_LEVEL

退货
int一个整数,指示第一个启动的API设备级别

投掷
DeviceNotAvailableException

getlogcat

public InputStreamSource getLogcat ()

抓住LogCat数据的快照流。

以两种模式工作:

  • 如果当前在后台捕获了logcat,则将返回到TestDeviceOptions.getMaxLogcatDataSize()字节,该字节的当前内容的当前内容capture capture的当前内容
  • 否则,如果设备当前响应,将返回LogCat数据的静态转储

    退货
    InputStreamSource

  • getlogcat

    public InputStreamSource getLogcat (int maxBytes)

    抓住捕获的logcat数据的最后一个maxBytes的快照流。

    对于您想捕获捕获的LogCat数据的频繁快照而不产生可能的大磁盘空间罚款,即获取整个getLogcat()快照时,很有用。

    参数
    maxBytes int :要返回的最大数据量。应该是可以舒适地适合记忆的数量

    退货
    InputStreamSource

    getlogcatdump

    public InputStreamSource getLogcatDump ()

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

    缺点是,如果无法到达设备,则不会返回。

    退货
    InputStreamSource LOGCAT数据的InputStreamSource 。如果无法捕获LogCat数据,将返回空流。

    getlogcatsince

    public InputStreamSource getLogcatSince (long date)

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

    参数
    date long :自何时启动快照直到现在的时期格式以来,以毫秒为单位。 (可以使用“日期 +%s”获得)

    退货
    InputStreamSource

    获取Mac地址

    public String getMacAddress ()

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

    退货
    String

    GetMainuserid

    public Integer getMainUserId ()

    返回主要用户ID。

    退货
    Integer如果有一个,则主要用户的用户ID,如果没有主要用户,则为空。

    投掷
    DeviceNotAvailableException

    GetMainlineModuleinfo

    public  getMainlineModuleInfo ()

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

    退货
    当前在设备上安装的String主线模块的ERROR(/Set)

    投掷
    DeviceNotAvailableException

    getmaxnumberofrunninguserssporport

    public int getMaxNumberOfRunningUsersSupported ()

    获得同时运行的用户的最大数量。默认为 0。

    退货
    int一个整数,指示同时运行的用户的数量

    投掷
    DeviceNotAvailableException

    getmaxnumberofuserssporport

    public int getMaxNumberOfUsersSupported ()

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

    退货
    int一个指示支持用户数量的整数

    投掷
    DeviceNotAvailableException

    getmicrodroidprocess

    public Process getMicrodroidProcess ()

    退货
    Process返回微吸收VM的过程。如果TestDevice不是微糖,请返回空。

    GetMonitor

    public IDeviceStateMonitor getMonitor ()

    返回与设备关联的IDeviceStateMonitor

    退货
    IDeviceStateMonitor

    getmountpoint

    public String getMountPoint (String mountName)

    返回安装点。

    如果没有IDevice中的缓存信息,请直接查询设备。

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

    参数
    mountName String :安装点的名称

    退货
    String安装点或null

    getmountpointinfo

    public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    返回对应于指定的安装点路径的MountPointInfo ,如果该路径没有安装或以其他方式没有出现在 /proc /安装端作为安装点,则null

    参数
    mountpoint String

    退货
    ITestDevice.MountPointInfo MountPointInfoERROR(/List)其中包含“/proc/mounts”中的信息

    投掷
    DeviceNotAvailableException

    getmountpointinfo

    public  getMountPointInfo ()

    返回设备上 /proc /安装的信息的解析版本

    退货
    MountPointInfoERROR(/List)其中包含“/proc/mounts”中的信息

    投掷
    DeviceNotAvailableException

    获取选项

    public TestDeviceOptions getOptions ()

    获取设备的测试选项。

    退货
    TestDeviceOptions与正在测试的设备有关的TestDeviceOptions

    getPartitionFreespace

    public long getPartitionFreeSpace (String partition)

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

    参数
    partition String

    退货
    long KB中的自由空间数量

    投掷
    DeviceNotAvailableException

    GetPrimaryuserid

    public Integer getPrimaryUserId ()

    返回主要用户ID。

    退货
    Integer主用户(如果有)的用户ID,如果没有主用户,则为null。

    投掷
    DeviceNotAvailableException

    getProcessbyName

    public ProcessInfo getProcessByName (String processName)

    助手方法运行“ pidof”和“ stat”命令,并使用PID返回ProcessInfo对象,并在给定过程的开始时间和过程开始时间。

    参数
    processName String :proces name string。

    退货
    ProcessInfo给定ProcessName的ProcessInfo

    投掷
    DeviceNotAvailableException

    getProcesspid

    public String getProcessPid (String process)

    如果出现问题,将返回服务的PID或无效。

    参数
    process String :proces name string。

    退货
    String

    投掷
    DeviceNotAvailableException

    获取产品类型

    public String getProductType ()

    获取此设备产品类型的便利方法。

    如果设备处于ADB或FastBoot模式,此方法将起作用。

    退货
    String String产品类型名称。不会为空

    投掷
    DeviceNotAvailableException

    GetProductVariant

    public String getProductVariant ()

    获取此设备产品变体的便利方法。

    如果设备处于ADB或FastBoot模式,此方法将起作用。

    退货
    String String产品变体名称或null如果无法确定

    投掷
    DeviceNotAvailableException

    获取属性

    public String getProperty (String name)

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

    参数
    name String :属性名称

    退货
    String属性值或null (如果不存在)

    投掷
    DeviceNotAvailableException

    GetRecoveryMode

    public ITestDevice.RecoveryMode getRecoveryMode ()

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

    退货
    ITestDevice.RecoveryMode设备使用的当前恢复模式。

    获取屏幕截图

    public InputStreamSource getScreenshot (String format)

    从设备上捕获屏幕截图。建议使用getscreenshot(格式)代替JPEG编码较小的尺寸

    参数
    format String :支持的PNG,JPEG

    退货
    InputStreamSource格式的屏幕截图的InputStreamSource ,如果屏幕截图不成功,则为null

    投掷
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot (long displayId)

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

    TODO:扩展上述实现以支持“格式”和“恢复”

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

    退货
    InputStreamSource格式的屏幕截图的InputStreamSource ,如果屏幕截图不成功,则为null

    投掷
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot (String format, 
                    boolean rescale)

    从设备上捕获屏幕截图。建议使用getScreenshot(String)代替JPEG编码的尺寸较小。

    参数
    format String :支持的PNG,JPEG

    rescale boolean :如果应重新屏幕截图以减少产生图像的大小

    退货
    InputStreamSource格式的屏幕截图的InputStreamSource ,如果屏幕截图不成功,则为null

    投掷
    DeviceNotAvailableException

    获取屏幕截图

    public InputStreamSource getScreenshot ()

    从设备上捕获屏幕截图。

    退货
    InputStreamSource如果屏幕截图不成功,则以PNG格式的屏幕截图或null InputStreamSource

    投掷
    DeviceNotAvailableException

    获取序列号

    public String getSerialNumber ()

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

    退货
    String String序列号

    获取设置

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

    返回请求的设置的值。名称空间必须是:{“系统”,“安全”,“全局”}之一

    参数
    userId int

    namespace String

    key String

    退货
    String与命名空间相关的值:用户的密钥。如果找不到的话,则无效。

    投掷
    DeviceNotAvailableException

    获取设置

    public String getSetting (String namespace, 
                    String key)

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

    参数
    namespace String

    key String

    退货
    String

    投掷
    DeviceNotAvailableException

    getemoperator

    public String getSimOperator ()

    返回SIM卡操作员或NULL(如果不可用),或者设备不可用。

    退货
    String

    getSimstate

    public String getSimState ()

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

    退货
    String

    GetTombstones

    public  getTombstones ()

    从设备中获取并返回墓碑清单。需要根。

    方法是最好的效果,因此,如果由于任何原因将一个墓碑未能拉出,则它将缺少列表中的墓碑。只有DeviceNotAvailableException才能尽早终止该方法。

    退货
    墓碑文件列表,如果没有墓碑,则空。

    投掷
    DeviceNotAvailableException

    getTotalMemory

    public long getTotalMemory ()

    在内部错误时返回字节中的总物理内存大小或-1

    退货
    long

    getuninstallable -packagenames

    public  getUninstallablePackageNames ()

    获取可以卸载的应用程序包名称。目前将其定义为非系统软件包和更新的系统软件包。

    退货
    当前在设备上安装的非安装String软件包名称的ERROR(/Set)

    投掷
    DeviceNotAvailableException

    GetUseStfastbooterase

    public boolean getUseFastbootErase ()

    获取是使用FastBoot Erase还是FastBoot格式来擦除设备上的分区。

    退货
    boolean如果使用FastBoot擦除,则如果使用FastBoot格式, false true

    getuserflags

    public int getUserFlags (int userId)

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

    参数
    userId int

    退货
    int如果发现,则与用户ID相关的标志在任何其他情况下都可以-10000。

    投掷
    DeviceNotAvailableException

    getuserinfos

    public  getUserInfos ()

    获取在设备上使用UserInfo的useID地图。如果设备的输出不如预期,将抛出DeviceRuntimeException

    退货
    UserInfo对象列表。

    投掷
    DeviceNotAvailableException

    getuserialnumber

    public int getUserSerialNumber (int userId)

    在任何其他情况下,返回与用户ID相关的序列号,-10000。

    参数
    userId int

    退货
    int

    投掷
    DeviceNotAvailableException

    HandlealLocationEvent

    public IManagedTestDevice.DeviceEventResponse handleAllocationEvent (DeviceEvent event)

    处理给定的设备Event。可以过渡设备到新状态。将告知IDeviceMonitor任何国家过渡。

    处理设备Event,该设备Event可能会或可能不会将该设备转换为新的分配状态。

    参数
    event DeviceEvent

    退货
    IManagedTestDevice.DeviceEventResponse

    有特征

    public boolean hasFeature (String feature)

    检查设备上是否有功能。

    参数
    feature String :哪种格式应为“功能: “ 或者 ” “ 直接地。

    退货
    boolean如果找到功能,则为true,否则为错误。

    投掷
    DeviceNotAvailableException

    安装包

    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

    安装包

    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

    无效的propertycache

    public void invalidatePropertyCache ()

    Isadbroot

    public boolean isAdbRoot ()

    退货
    boolean

    投掷
    DeviceNotAvailableException

    ISADBTCP

    public boolean isAdbTcp ()

    退货
    boolean

    Isappenumerations pupport

    public boolean isAppEnumerationSupported ()

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

    退货
    boolean如果支持应用程序枚举,则为false,否则

    投掷
    DeviceNotAvailableException

    ISBYPASSLOWTARGETSDKBLOCKSUPTORPORTED

    public boolean isBypassLowTargetSdkBlockSupported ()

    检查设备上的平台是否支持绕过应用程序安装上的低目标SDK块

    退货
    boolean如果支持旁路低目标SDK块,则为false,否则为否则

    投掷
    DeviceNotAvailableException

    isdebugfsmount

    public boolean isDebugfsMounted ()

    检查debugfs是否已安装。

    退货
    boolean如果debugfs true

    投掷
    DeviceNotAvailableException

    ISDEVICEENCHECTPTED

    public boolean isDeviceEncrypted ()

    如果设备加密,则返回。

    退货
    boolean如果对设备进行了加密,则为true

    投掷
    DeviceNotAvailableException

    是目录

    public boolean isDirectory (String path)

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

    参数
    path String

    退货
    boolean

    投掷
    DeviceNotAvailableException

    iSenableAdbroot

    public boolean isEnableAdbRoot ()

    退货
    boolean true在设备上启用了ADB根

    Isencryptionsupport

    public boolean isEncryptionSupported ()

    如果在设备上支持加密,则返回。

    退货
    boolean如果设备支持加密,则为true

    投掷
    DeviceNotAvailableException

    是可执行文件

    public boolean isExecutable (String fullPath)

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

    参数
    fullPath String

    退货
    boolean

    投掷
    DeviceNotAvailableException

    ISFastBooteNabled

    public boolean isFastbootEnabled ()

    如果设备可用于FastBoot,请返回。

    退货
    boolean

    是无头的

    public boolean isHeadless ()

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

    退货
    boolean

    投掷
    DeviceNotAvailableException

    isHeadlessSystemUserMode

    public boolean isHeadlessSystemUserMode ()

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

    退货
    boolean

    投掷
    DeviceNotAvailableException

    Ismainuserpermanentadmin

    public boolean isMainUserPermanentAdmin ()

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

    退货
    boolean

    投掷
    DeviceNotAvailableException

    Ismultusersporport

    public boolean isMultiUserSupported ()

    确定是否支持多用户。

    退货
    boolean如果支持多用户,则为false,否则

    投掷
    DeviceNotAvailableException

    isPackageInstall

    public boolean isPackageInstalled (String packageName, 
                    String userId)

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

    参数
    packageName String :我们正在检查是否已安装的软件包。

    userId String :我们正在检查软件包的用户ID。如果为null,则将使用主用户零。

    退货
    boolean如果将包装报告为已安装,则为the。否则为假。

    投掷
    DeviceNotAvailableException

    isPackageInstall

    public boolean isPackageInstalled (String packageName)

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

    参数
    packageName String

    退货
    boolean如果将包装报告为已安装,则为the。否则为假。

    投掷
    DeviceNotAvailableException

    IsruntimePermissionsupport

    public boolean isRuntimePermissionSupported ()

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

    退货
    boolean是的,如果支持运行时权限,否则为false。

    投掷
    DeviceNotAvailableException

    isstatebootloaderorfastbootd

    public boolean isStateBootloaderOrFastbootd ()

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

    退货
    boolean

    正在运行

    public boolean isUserRunning (int userId)

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

    参数
    userId int

    退货
    boolean如果用户运行,则在其他情况下为FALSE。

    投掷
    DeviceNotAvailableException

    iSusersecdary

    public boolean isUserSecondary (int userId)

    根据其标志,返回指定的用户是否是二级用户。

    参数
    userId int

    退货
    boolean是的,如果用户是次要的,则为false否则。

    投掷
    DeviceNotAvailableException

    可以维修

    public boolean isUserVisible (int userId)

    检查给定的用户是否可见。

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

    参数
    userId int

    退货
    boolean

    投掷
    DeviceNotAvailableException

    Inservisible display

    public boolean isUserVisibleOnDisplay (int userId, 
                    int displayId)

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

    “可见”用户是与“人类”用户进行交互的用户,因此能够在该显示中启动启动活动。

    参数
    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

    Isvisiblebackgroundusersporport

    public boolean isVisibleBackgroundUsersSupported ()

    返回该设备是否允许在后台看到用户。

    如果是这样,您可以致电startVisibleBackgroundUser(int, int, boolean) ,传递由listDisplayIdsForStartingVisibleBackgroundUsers()

    退货
    boolean

    投掷
    DeviceNotAvailableException

    是否启用Wifi

    public boolean isWifiEnabled ()

    测试是否启用了WiFi。

    检查是否在设备上启用了WiFi。对于在不应该使用WiFi(例如移动数据测试)进行测试之前主张WiFi状态。

    退货
    boolean如果启用了wifi,则为truefalse如果禁用

    投掷
    DeviceNotAvailableException

    ListDisplayids

    public  listDisplayIds ()

    收集设备上可用显示ID的列表,如“ Dumpsys SurfaceFlinger”报告。

    退货
    显示列表。默认值始终返回默认显示0。

    投掷
    DeviceNotAvailableException

    ListDisplayidsforStartingVisibleBackgrounduser

    public  listDisplayIdsForStartingVisibleBackgroundUsers ()

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

    退货

    投掷
    DeviceNotAvailableException

    列出用户

    public  listUsers ()

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

    退货
    用户ID列表。

    投掷
    DeviceNotAvailableException

    Loganrs

    public boolean logAnrs (ITestLogger logger)

    从设备收集并记录ANRS。

    参数
    logger ITestLoggerITestLogger记录ANRS。

    退货
    boolean如果记录成功,则是真的,否则为错误。

    投掷
    DeviceNotAvailableException

    logbugreport

    public boolean logBugreport (String dataName, 
                    ITestLogger listener)

    辅助方法将BugReport并将其记录到记者。

    参数
    dataName String :将在其报告的名称中报告。

    listener ITestLoggerITestLogger记录bugreport。

    退货
    boolean如果记录成功,则是真的,否则为错误。

    logondevice

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

    在设备的对数猫中记录一条消息。这是一个安全的电话,即使登录失败也不会投掷。

    参数
    tag String :我们在logcat中记录消息的标签。

    level Log.LogLevel :logcat中消息的调试级别。

    format String :消息格式。

    args Object :通过string.format()替换的args。

    Mountdebugfs

    public void mountDebugfs ()

    山debugfs。

    投掷
    DeviceNotAvailableException

    非BlockingReboot

    public void nonBlockingReboot ()

    发出重新启动设备并在命令上返回的命令以及ADB不再可见设备时。

    投掷
    DeviceNotAvailableException

    addbrootaction

    public void postAdbRootAction ()

    如果设备需要在ADB root之后和设备重新在线之前采取一些特定的操作,则覆盖。默认实现不包括任何加法操作。在此阶段,不能保证启用ADB根。

    投掷
    com.android.tradefed.device.devicenotavailable Exception
    DeviceNotAvailableException

    后刺激性

    public void postAdbUnrootAction ()

    如果设备需要在ADB Unroot之后以及设备返回在线之前,则覆盖设备是否需要采取一些特定的操作。默认实现不包括任何其他操作。在此阶段,不能保证ADB root被禁用。

    投掷
    com.android.tradefed.device.devicenotavailable Exception
    DeviceNotAvailableException

    后启动

    public void postBootSetup ()

    执行指令以配置每个引导后测试设备。

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

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

    可能需要调用的地方是当设备重新启动其他事件时(例如,何时快速启动更新命令完成)

    投掷
    DeviceNotAvailableException

    后投资测试

    public void postInvocationTearDown (Throwable exception)

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

    参数
    exception Throwable :如果有的话,最终例外是由调用失败提出的。

    启动前

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

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

    参数
    info IBuildInfo :设备的IBuildInfo

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

    投掷
    DeviceNotAvailableException
    TargetSetupError

    plldir

    public boolean pullDir (String deviceFilePath, 
                    File localDir)

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

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

    localDir File :将文件拉入的本地目录

    退货
    boolean如果成功拉出文件,则为true 。否则为false

    投掷
    DeviceNotAvailableException

    拉文件

    public boolean pullFile (String remoteFilePath, 
                    File localFile)

    检索文件设备的文件。

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

    localFile File :要将内容存储在中的本地文件。如果非空,将更换内容。

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

    投掷
    DeviceNotAvailableException

    拉文件

    public File pullFile (String remoteFilePath, 
                    int userId)

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

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

    userId int :要从

    退货
    File一个包含设备文件内容的ERROR(/File) ,如果出于任何原因副本失败(包括主机文件系统的问题),则null

    投掷
    DeviceNotAvailableException

    拉文件

    public File pullFile (String remoteFilePath)

    Retrieves a file off device, stores it in a local temporary ERROR(/File) , and returns that File .

    参数
    remoteFilePath String : the absolute path to file on device.

    退货
    File A ERROR(/File) containing the contents of the device file, or null if the copy failed for any reason (including problems with the host filesystem)

    投掷
    DeviceNotAvailableException

    拉文件

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

    Retrieves a file off device.

    参数
    remoteFilePath String : the absolute path to file on device.

    localFile File : the local file to store contents in. If non-empty, contents will be replaced.

    userId int : The user id to pull from

    退货
    boolean true if file was retrieved successfully.否则为false

    投掷
    DeviceNotAvailableException

    pullFileContents

    public String pullFileContents (String remoteFilePath)

    Retrieves a file off device, and returns the contents.

    参数
    remoteFilePath String : the absolute path to file on device.

    退货
    String A String containing the contents of the device file, or null if the copy failed for any reason (including problems with the host filesystem)

    投掷
    DeviceNotAvailableException

    pullFileFromExternal

    public File pullFileFromExternal (String remoteFilePath)

    A convenience method to retrieve a file from the device's external storage, stores it in a local temporary ERROR(/File) , and return a reference to that File .

    参数
    remoteFilePath String : the path to file on device, relative to the device's external storage mountpoint

    退货
    File A ERROR(/File) containing the contents of the device file, or null if the copy failed for any reason (including problems with the host filesystem)

    投掷
    DeviceNotAvailableException

    pushDir

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

    Recursively push directory contents to device while excluding some directories that are filtered.

    参数
    localFileDir File : the local directory to push

    deviceFilePath String : the absolute file path of the remote destination

    excludedDirectories : Set of excluded directories names that shouldn't be pushed.

    退货
    boolean true if file was pushed successfully.否则为false

    投掷
    DeviceNotAvailableException

    pushDir

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath)

    Recursively push directory contents to device.

    参数
    localFileDir File : the local directory to push

    deviceFilePath String : the absolute file path of the remote destination

    退货
    boolean true if file was pushed successfully.否则为false

    投掷
    DeviceNotAvailableException

    推送文件

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

    Variant of pushFile(File, String) which can optionally consider evaluating the need for the content provider.

    参数
    localFile File : the local file to push

    remoteFilePath String : the remote destination absolute file path

    evaluateContentProviderNeeded boolean : whether to check if we need the content provider

    退货
    boolean true if file was pushed successfully.否则为false

    投掷
    DeviceNotAvailableException

    推送文件

    public boolean pushFile (File localFile, 
                    String remoteFilePath)

    Push a file to device. By default using a content provider.

    参数
    localFile File : the local file to push

    remoteFilePath String : the remote destination absolute file path

    退货
    boolean true if file was pushed successfully.否则为false

    投掷
    DeviceNotAvailableException

    pushString

    public boolean pushString (String contents, 
                    String remoteFilePath)

    Push file created from a string to device

    参数
    contents String : the contents of the file to push

    remoteFilePath String : the remote destination absolute file path

    退货
    boolean true if string was pushed successfully.否则为false

    投掷
    DeviceNotAvailableException

    重启

    public void reboot (String reason)

    Reboots the device into adb mode with given reason to be persisted across reboot.

    Blocks until device becomes available.

    Last reboot reason can be obtained by querying sys.boot.reason propety.

    参数
    reason String : a reason for this reboot, or null if no reason is specified.

    投掷
    DeviceNotAvailableException

    重启

    public void reboot ()

    Reboots the device into adb mode.

    Blocks until device becomes available.

    投掷
    DeviceNotAvailableException

    rebootIntoBootloader

    public void rebootIntoBootloader ()

    Reboots the device into bootloader mode.

    Blocks until device is in bootloader mode.

    投掷
    DeviceNotAvailableException

    rebootIntoFastbootd

    public void rebootIntoFastbootd ()

    Reboots the device into fastbootd mode.

    Blocks until device is in fastbootd mode.

    投掷
    DeviceNotAvailableException

    rebootIntoRecovery

    public void rebootIntoRecovery ()

    Reboots the device into adb recovery mode.

    Blocks until device enters recovery

    投掷
    DeviceNotAvailableException

    rebootIntoSideload

    public void rebootIntoSideload ()

    Reboots the device into adb sideload mode (note that this is a special mode under recovery)

    Blocks until device enters sideload mode

    投掷
    DeviceNotAvailableException

    rebootIntoSideload

    public void rebootIntoSideload (boolean autoReboot)

    Reboots the device into adb sideload mode (note that this is a special mode under recovery)

    Blocks until device enters sideload mode

    参数
    autoReboot boolean : whether to automatically reboot the device after sideload

    投掷
    DeviceNotAvailableException

    rebootUntilOnline

    public void rebootUntilOnline ()

    An alternate to reboot() that only blocks until device is online ie visible to adb.

    投掷
    DeviceNotAvailableException

    rebootUntilOnline

    public void rebootUntilOnline (String reason)

    An alternate to reboot() that only blocks until device is online ie visible to adb.

    参数
    reason String : a reason for this reboot, or null if no reason is specified.

    投掷
    DeviceNotAvailableException

    rebootUserspace

    public void rebootUserspace ()

    Reboots only userspace part of device.

    Blocks until device becomes available.

    警告。 Userspace reboot is currently under active development, use it on your own risk.

    投掷
    DeviceNotAvailableException

    rebootUserspaceUntilOnline

    public void rebootUserspaceUntilOnline ()

    An alternate to rebootUserspace() ()} that only blocks until device is online ie visible to adb.

    投掷
    DeviceNotAvailableException

    recoverDevice

    public boolean recoverDevice ()

    Attempts to recover device communication.

    退货
    boolean True if recovery attempted and successful, returns False if recovery was skipped

    投掷
    DeviceNotAvailableException if device is no longer available

    registerDeviceActionReceiver

    public void registerDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

    Registers a IDeviceActionReceiver for this device.

    All registered IDeviceActionReceiver s will be notified before a device action starts and after the device action ends.

    参数
    deviceActionReceiver IDeviceActionReceiver : A IDeviceActionReceiver which will be registered.

    remountSystemReadOnly

    public void remountSystemReadOnly ()

    Make the system partition on the device read-only. May reboot the device.

    投掷
    DeviceNotAvailableException

    remountSystemWritable

    public void remountSystemWritable ()

    Make the system partition on the device writable. May reboot the device.

    投掷
    DeviceNotAvailableException

    remountVendorReadOnly

    public void remountVendorReadOnly ()

    Make the vendor partition on the device read-only. May reboot the device.

    投掷
    DeviceNotAvailableException

    remountVendorWritable

    public void remountVendorWritable ()

    Make the vendor partition on the device writable. May reboot the device.

    投掷
    DeviceNotAvailableException

    removeAdmin

    public boolean removeAdmin (String componentName, 
                    int userId)

    Remove given device admin in given user and return true if it is successful, false otherwise.

    参数
    componentName String : of device admin to be removed.

    userId int : of user that the device admin lives in.

    退货
    boolean True if it is successful, false otherwise.

    投掷
    DeviceNotAvailableException

    removeOwners

    public void removeOwners ()

    Remove all existing device profile owners with the best effort.

    投掷
    DeviceNotAvailableException

    删除用户

    public boolean removeUser (int userId)

    Remove a given user from the device.

    参数
    userId int : of the user to remove

    退货
    boolean true if we were successful in removing the user, false otherwise.

    投掷
    DeviceNotAvailableException

    resetContentProviderSetup

    public void resetContentProviderSetup ()

    Reset the flag for content provider setup in order to trigger it again.

    runInstrumentationTests

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

    Convenience method for performing ERROR(/#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection)) with one or more listeners passed as parameters.

    参数
    runner IRemoteAndroidTestRunner : the IRemoteAndroidTestRunner which runs the tests

    listeners ITestLifeCycleReceiver : the test result listener(s)

    退货
    boolean true if test command completed. false if it failed to complete, but recovery succeeded

    投掷
    DeviceNotAvailableException

    runInstrumentationTests

    public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

    Runs instrumentation tests, and provides device recovery.

    If connection with device is lost before test run completes, and recovery succeeds, all listeners will be informed of testRunFailed and "false" will be returned. The test command will not be rerun. It is left to callers to retry if necessary.

    If connection with device is lost before test run completes, and recovery fails, all listeners will be informed of testRunFailed and DeviceNotAvailableException will be thrown.

    参数
    runner IRemoteAndroidTestRunner : the IRemoteAndroidTestRunner which runs the tests

    listeners : the test result listeners

    退货
    boolean true if test command completed. false if it failed to complete due to device communication exception, but recovery succeeded

    投掷
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

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

    Same as ERROR(ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)/com.android.tradefed.device.ITestDevice#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection) ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, Collection)) but runs the test for the given user.

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners

    退货
    boolean

    投掷
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

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

    Same as ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...) but runs the test for a given user.

    参数
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    退货
    boolean

    投掷
    DeviceNotAvailableException

    设置配置

    public void setConfiguration (IConfiguration configuration)

    注入正在使用的IConfiguration

    参数
    configuration IConfiguration

    setConnectionAvdInfo

    public final void setConnectionAvdInfo (GceAvdInfo avdInfo)

    参数
    avdInfo GceAvdInfo

    设置日期

    public void setDate (Date date)

    Sets the date on device

    Note: setting date on device requires root

    参数
    date Date : specify a particular date; will use host date if null

    投掷
    DeviceNotAvailableException

    setDeviceOwner

    public boolean setDeviceOwner (String componentName, 
                    int userId)

    Set a device admin component as device owner in given user.

    参数
    componentName String : of device admin to be device owner.

    userId int : of the user that the device owner lives in.

    退货
    boolean True if it is successful, false otherwise.

    投掷
    DeviceNotAvailableException

    setDeviceState

    public void setDeviceState (TestDeviceState deviceState)

    Update the device's state.

    参数
    deviceState TestDeviceState : the TestDeviceState

    setEmulatorOutputStream

    public void setEmulatorOutputStream (SizeLimitedOutputStream output)

    For emulator set SizeLimitedOutputStream to log output

    参数
    output SizeLimitedOutputStream : to log the output

    setEmulatorProcess

    public void setEmulatorProcess (Process p)

    Sets the Process , when this device is an emulator.

    参数
    p Process

    setFastbootEnabled

    public void setFastbootEnabled (boolean fastbootEnabled)

    Set the fastboot option for the device. Should be set when device is first allocated.

    参数
    fastbootEnabled boolean : whether fastboot is available for the device or not

    setFastbootPath

    public void setFastbootPath (String fastbootPath)

    Sets the path to the fastboot binary that should be used. Still requires isFastbootEnabled() to be true, to have fastboot functions enabled.

    参数
    fastbootPath String

    setIDevice

    public void setIDevice (IDevice newDevice)

    Update the IDevice associated with this ITestDevice.

    The new IDevice must refer the same physical device as the current reference. This method will be called if DDMS has allocated a new IDevice

    参数
    newDevice IDevice : the IDevice

    setLogStartDelay

    public void setLogStartDelay (int delay)

    Sets the time in ms to wait before starting logcat capture for a online device.

    参数
    delay int : the delay in ms

    设置选项

    public void setOptions (TestDeviceOptions options)

    Set the TestDeviceOptions for the device

    参数
    options TestDeviceOptions

    设置属性

    public boolean setProperty (String propKey, 
                    String propValue)

    Sets the given property value on the device. Requires adb root is true.

    参数
    propKey String : The key targeted to be set.

    propValue String : The property value to be set.

    退货
    boolean returns True if the setprop command was successful, False otherwise.

    投掷
    DeviceNotAvailableException

    setRecovery

    public void setRecovery (IDeviceRecovery recovery)

    Set the IDeviceRecovery to use for this device. Should be set when device is first allocated.

    参数
    recovery IDeviceRecovery : the IDeviceRecovery

    setRecoveryMode

    public void setRecoveryMode (ITestDevice.RecoveryMode mode)

    Set the current recovery mode to use for the device.

    Used to control what recovery method to use when a device communication problem is encountered. Its recommended to only use this method sparingly when needed (for example, when framework is down, etc

    参数
    mode ITestDevice.RecoveryMode : whether 'recover till online only' mode should be on or not.

    设置设置

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

    See setSetting(int, String, String, String) and performed on system user.

    参数
    namespace String

    key String

    value String

    投掷
    DeviceNotAvailableException

    设置设置

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

    Add a setting value to the namespace of a given user. Some settings will only be available after a reboot. namespace must be one of: {"system", "secure", "global"}

    参数
    userId int

    namespace String

    key String

    value String

    投掷
    DeviceNotAvailableException

    setTestLogger

    public void setTestLogger (ITestLogger testLogger)

    Injects the ITestLogger instance

    参数
    testLogger ITestLogger

    setUseFastbootErase

    public void setUseFastbootErase (boolean useFastbootErase)

    Set whether to use fastboot erase or fastboot format to wipe a partition on the device.

    参数
    useFastbootErase boolean : true if fastboot erase should be used or false if fastboot format should be used.

    startLogcat

    public void startLogcat ()

    Start capturing logcat output from device in the background.

    Will have no effect if logcat output is already being captured. Data can be later retrieved via getLogcat.

    When the device is no longer in use, stopLogcat() must be called.

    startLogcat() and stopLogcat() do not normally need to be called when within a TF invocation context, as the TF framework will start and stop logcat.

    startUser

    public boolean startUser (int userId)

    Starts a given user in the background if it is currently stopped. If the user is already running in the background, this method is a NOOP.

    参数
    userId int : of the user to start in the background

    退货
    boolean true if the user was successfully started in the background.

    投掷
    DeviceNotAvailableException

    startUser

    public boolean startUser (int userId, 
                    boolean waitFlag)

    Starts a given user in the background if it is currently stopped. If the user is already running in the background, this method is a NOOP. Possible to provide extra flag to wait for the operation to have effect.

    参数
    userId int : of the user to start in the background

    waitFlag boolean : will make the command wait until user is started and unlocked.

    退货
    boolean true if the user was successfully started in the background.

    投掷
    DeviceNotAvailableException

    startVisibleBackgroundUser

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

    Starts a given user in the background, visible in the given display (ie, allowing the user to launch activities in that display).

    NOTE: this command doesn't check if the user exists, display is available, device supports such feature , etc.

    参数
    userId int : of the user to start in the background

    displayId int : display to start user visible on

    waitFlag boolean : will make the command wait until user is started and unlocked.

    退货
    boolean true if the user was successfully started visible in the background.

    投掷
    DeviceNotAvailableException

    stopEmulatorOutput

    public void stopEmulatorOutput ()

    Close and delete the emulator output.

    stopLogcat

    public void stopLogcat ()

    Stop capturing logcat output from device, and discard currently saved logcat data.

    Will have no effect if logcat output is not being captured.

    停止用户

    public boolean stopUser (int userId)

    Stops a given user. If the user is already stopped, this method is a NOOP. Cannot stop current and system user.

    参数
    userId int : of the user to stop.

    退货
    boolean true if the user was successfully stopped.

    投掷
    DeviceNotAvailableException

    停止用户

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

    Stop a given user. Possible to provide extra flags to wait for the operation to have effect, and force terminate the user. Cannot stop current and system user.

    参数
    userId int : of the user to stop.

    waitFlag boolean : will make the command wait until user is stopped.

    forceFlag boolean : will force stop the user.

    退货
    boolean true if the user was successfully stopped.

    投掷
    DeviceNotAvailableException

    switchToAdbTcp

    public String switchToAdbTcp ()

    Switch device to adb-over-tcp mode.

    退货
    String the tcp serial number or null if device could not be switched

    投掷
    DeviceNotAvailableException

    switchToAdbUsb

    public boolean switchToAdbUsb ()

    Switch device to adb over usb mode.

    退货
    boolean true if switch was successful, false otherwise.

    投掷
    DeviceNotAvailableException

    切换用户

    public boolean switchUser (int userId)

    Switch to another userId with a default timeout. switchUser(int, long) .

    参数
    userId int

    退货
    boolean True if the new userId matches the userId provider.否则为假。

    投掷
    DeviceNotAvailableException

    切换用户

    public boolean switchUser (int userId, 
                    long timeout)

    Switch to another userId with the provided timeout as deadline. Attempt to disable keyguard after user change is successful.

    参数
    userId int

    timeout long : to wait before returning false for switch-user failed.

    退货
    boolean True if the new userId matches the userId provider.否则为假。

    投掷
    DeviceNotAvailableException

    syncFiles

    public boolean syncFiles (File localFileDir, 
                    String deviceFilePath)

    Incrementally syncs the contents of a local file directory to device.

    Decides which files to push by comparing timestamps of local files with their remote equivalents. Only 'newer' or non-existent files will be pushed to device. Thus overhead should be relatively small if file set on device is already up to date.

    Hidden files (with names starting with ".") will be ignored.

    Example usage: syncFiles("/tmp/files", "/sdcard") will created a /sdcard/files directory if it doesn't already exist, and recursively push the /tmp/files contents to /sdcard/files.

    参数
    localFileDir File : the local file directory containing files to recursively push.

    deviceFilePath String : the remote destination absolute file path root. All directories in thos file path must be readable. ie pushing to /data/local/tmp when adb is not root will fail

    退货
    boolean true if files were synced successfully.否则为false

    投掷
    DeviceNotAvailableException

    takeBugreport

    public Bugreport takeBugreport ()

    Take a bugreport and returns it inside a Bugreport object to handle it. Return null in case of issue. File referenced in the Bugreport object need to be cleaned via Bugreport.close() .

    退货
    Bugreport

    uninstallPackage

    public String uninstallPackage (String packageName)

    Uninstall an Android package from device.

    参数
    packageName String : the Android package to uninstall

    退货
    String a String with an error code, or null if success.

    投掷
    DeviceNotAvailableException

    uninstallPackageForUser

    public String uninstallPackageForUser (String packageName, 
                    int userId)

    Uninstall an Android package from device for a given user.

    参数
    packageName String : the Android package to uninstall

    userId int : the integer user id to uninstall for.

    退货
    String a String with an error code, or null if success.

    投掷
    DeviceNotAvailableException

    unlockDevice

    public boolean unlockDevice ()

    Unlocks the device if the device is in an encrypted state.

    This method may restart the framework but will not call postBootSetup() . Therefore, the device might not be fully ready to be tested when this method returns.

    退货
    boolean true if successful or if the device is unencrypted.

    投掷
    DeviceNotAvailableException

    unmountDebugfs

    public void unmountDebugfs ()

    Unmount debugfs.

    投掷
    DeviceNotAvailableException

    waitForBootComplete

    public boolean waitForBootComplete (long timeOut)

    Blocks until the device's boot complete flag is set.

    参数
    timeOut long : time in msecs to wait for the flag to be set

    退货
    boolean true if device's boot complete flag is set within the timeout

    投掷
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable ()

    Waits for the device to be responsive and available for testing. Uses default timeout.

    退货
    boolean True if device is available, False if recovery is disabled and unavailable.

    投掷
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable (long waitTime)

    Waits for the device to be responsive and available for testing.

    参数
    waitTime long : the time in ms to wait

    退货
    boolean True if device is available, False if recovery is disabled and unavailable.

    投掷
    DeviceNotAvailableException

    waitForDeviceAvailableInRecoverPath

    public boolean waitForDeviceAvailableInRecoverPath (long waitTime)

    Waits for the device to be responsive and available without considering recovery path.

    参数
    waitTime long

    退货
    boolean True if device is available, False if unavailable.

    投掷
    DeviceNotAvailableException

    waitForDeviceBootloader

    public void waitForDeviceBootloader ()

    Blocks until device is visible via fastboot. Use default timeout.

    投掷
    DeviceNotAvailableException

    waitForDeviceInRecovery

    public boolean waitForDeviceInRecovery (long waitTime)

    Blocks for the device to be in the 'adb recovery' state (note this is distinct from IDeviceRecovery ).

    参数
    waitTime long : the time in ms to wait

    退货
    boolean true if device boots into recovery before time expires.否则为false

    waitForDeviceInSideload

    public boolean waitForDeviceInSideload (long waitTime)

    Blocks for the device to be in the 'adb sideload' state

    参数
    waitTime long : the time in ms to wait

    退货
    boolean true if device boots into sideload before time expires.否则为false

    waitForDeviceNotAvailable

    public boolean waitForDeviceNotAvailable (long waitTime)

    Blocks for the device to be not available ie missing from adb

    参数
    waitTime long : the time in ms to wait

    退货
    boolean true if device becomes not available before time expires.否则为false

    waitForDeviceOnline

    public void waitForDeviceOnline ()

    Blocks until device is visible via adb. Uses default timeout

    Note the device may not necessarily be responsive to commands on completion. Use waitForDeviceAvailable() instead.

    投掷
    DeviceNotAvailableException

    waitForDeviceOnline

    public void waitForDeviceOnline (long waitTime)

    Blocks until device is visible via adb.

    Note the device may not necessarily be responsive to commands on completion. Use waitForDeviceAvailable() instead.

    参数
    waitTime long : the time in ms to wait

    投掷
    DeviceNotAvailableException

    waitForDeviceShell

    public boolean waitForDeviceShell (long waitTime)

    Waits for device to be responsive to a basic adb shell command.

    参数
    waitTime long : the time in ms to wait

    退货
    boolean true if device becomes responsive before waitTime elapses.

    受保护的方法

    addExtraConnectionBuilderArgs

    protected void addExtraConnectionBuilderArgs (DefaultConnection.ConnectionBuilder builder)

    参数
    builder DefaultConnection.ConnectionBuilder

    buildAdbShellCommand

    protected String[] buildAdbShellCommand (String command, 
                    boolean forceExitStatusDetection)

    Builds the OS command for the given adb shell command session and args

    参数
    command String

    forceExitStatusDetection boolean

    退货
    String[]

    checkApiLevelAgainst

    protected void checkApiLevelAgainst (String feature, 
                    int strictMinLevel)

    参数
    feature String

    strictMinLevel int

    createRebootDeviceAction

    protected NativeDevice.RebootDeviceAction createRebootDeviceAction (NativeDevice.RebootMode rebootMode, 
                    String reason)

    Create a RebootDeviceAction to be used when performing a reboot action.

    参数
    rebootMode NativeDevice.RebootMode : a mode of this reboot.

    reason String : for this reboot.

    退货
    NativeDevice.RebootDeviceAction the created RebootDeviceAction .

    createRunUtil

    protected IRunUtil createRunUtil ()

    退货
    IRunUtil

    doAdbReboot

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

    Perform a adb reboot.

    参数
    rebootMode NativeDevice.RebootMode : a mode of this reboot.

    reason String : for this reboot.

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    ensureRuntimePermissionSupported

    protected void ensureRuntimePermissionSupported ()

    helper method to throw exception if runtime permission isn't supported

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    getApiLevelSafe

    protected int getApiLevelSafe ()

    退货
    int

    获取记录器

    protected ITestLogger getLogger ()

    退货
    ITestLogger

    getRunUtil

    protected IRunUtil getRunUtil ()

    Get the RunUtil instance to use.

    退货
    IRunUtil

    initializeConnection

    protected void initializeConnection (IBuildInfo info, 
                    MultiMap<String, String> attributes)

    参数
    info IBuildInfo

    attributes MultiMap

    投掷
    DeviceNotAvailableException
    TargetSetupError

    internalGetProperty

    protected String internalGetProperty (String propName, 
                    String fastbootVar, 
                    String description)

    Fetch a device property, from the ddmlib cache by default, and falling back to either `adb shell getprop` or `fastboot getvar` depending on whether the device is in Fastboot or not.

    参数
    propName String : The name of the device property as returned by `adb shell getprop`

    fastbootVar String : The name of the equivalent fastboot variable to query. if null , fastboot query will not be attempted

    description String : A simple description of the variable. First letter should be capitalized.

    退货
    String A string, possibly null or empty, containing the value of the given property

    投掷
    DeviceNotAvailableException

    isInRebootCallback

    protected boolean isInRebootCallback ()

    Returns whether reboot callbacks is currently being executed or not. All public api's for reboot should be disabled if true.

    退货
    boolean

    isNewer

    protected boolean isNewer (File localFile, 
                    IFileEntry entry)

    Return true if local file is newer than remote file. IFileEntry being accurate to the minute, in case of equal times, the file will be considered newer.

    参数
    localFile File

    entry IFileEntry

    退货
    boolean

    notifyRebootEnded

    protected void notifyRebootEnded ()

    Notifies all IDeviceActionReceiver about reboot end event.

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    notifyRebootStarted

    protected void notifyRebootStarted ()

    Notifies all IDeviceActionReceiver about reboot start event.

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    performDeviceAction

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

    Performs an action on this device. Attempts to recover device and optionally retry command if action fails.

    参数
    actionDescription String : a short description of action to be performed. Used for logging purposes only.

    action NativeDevice.DeviceAction : the action to be performed

    retryAttempts int : the retry attempts to make for action if it fails but recovery succeeds

    退货
    boolean true if action was performed successfully

    投掷
    DeviceNotAvailableException if recovery attempt fails or max attempts done without success

    postAdbReboot

    protected void postAdbReboot ()

    Possible extra actions that can be taken after a reboot.

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    prePostBootSetup

    protected void prePostBootSetup ()

    Allows each device type (AndroidNativeDevice, TestDevice) to override this method for specific post boot setup.

    投掷
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    pullFileInternal

    protected boolean pullFileInternal (String remoteFilePath, 
                    File localFile)

    参数
    remoteFilePath String

    localFile File

    退货
    boolean

    投掷
    DeviceNotAvailableException

    设置时钟

    protected void setClock (Clock clock)

    Set the Clock instance to use.

    参数
    clock Clock

    setMicrodroidProcess

    protected void setMicrodroidProcess (Process process)

    Marks the TestDevice as microdroid and sets its CID.

    参数
    process Process : Process of the Microdroid VM.

    setTestDeviceOptions

    protected void setTestDeviceOptions ( deviceOptions)

    参数
    deviceOptions

    simpleFastbootCommand

    protected CommandResult simpleFastbootCommand (long timeout, 
                     envVarMap, 
                    String[] fullCmd)

    Executes a simple fastboot command with environment variables and report the status of the command.

    参数
    timeout long

    envVarMap

    fullCmd String

    退货
    CommandResult

    simpleFastbootCommand

    protected CommandResult simpleFastbootCommand (long timeout, 
                    String[] fullCmd)

    Executes a simple fastboot command and report the status of the command.

    参数
    timeout long

    fullCmd String

    退货
    CommandResult

    waitForDeviceNotAvailable

    protected boolean waitForDeviceNotAvailable (String operationDesc, 
                    long time)

    Wait to see the device going unavailable (stop reporting to adb).

    参数
    operationDesc String : The name of the operation that is waiting for unavailable.

    time long : The time to wait for unavailable to occur.

    退货
    boolean True if device did become unavailable.