NativeDevice

public class NativeDevice
extends Object implements IManagedTestDevice , IConfigurationReceiver

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


ITestDevice非全棧安卓設備的默認實現。

概括

嵌套類

class NativeDevice.AdbAction

用於運行 OS 'adb ....' 命令的DeviceAction

class NativeDevice.AdbShellAction

class NativeDevice.RebootDeviceAction

DeviceAction用於重新啟動設備。

enum NativeDevice.RebootMode

一種重啟模式。

常數

int INVALID_USER_ID

為任何無效/未找到的用戶 ID 返回值:UserHandle 定義了 -10000 值

long MAX_HOST_DEVICE_TIME_OFFSET

int MAX_RETRY_ATTEMPTS

命令重試嘗試執行的默認次數

字段

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

公共方法

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 network.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)

創建一個具有給定名稱和默認標誌 0 的用戶。

int createUserNoThrow (String name)

創建一個具有給定名稱和默認標誌 0 的用戶。

void deleteFile (String deviceFilePath)

用於刪除設備上的文件或目錄的輔助方法。

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 (String... cmdArgs)

將 adb 命令作為系統命令執行的輔助方法。

CommandResult executeFastbootCommand (String... cmdArgs)

將 fastboot 命令作為系統命令執行的輔助方法,默認超時為 2 分鐘。

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

將 fastboot 命令作為系統命令執行的輔助方法。

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

輔助方法,它將長時間運行的 fastboot 命令作為具有系統環境變量的系統命令執行。

CommandResult executeLongFastbootCommand (String... cmdArgs)

將長時間運行的快速啟動命令作為系統命令執行的輔助方法。

String executeShellCommand (String command)

執行 adb shell 命令並以String形式返回輸出的輔助方法。

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

執行 adb shell 命令,帶有更多參數來控制命令行為。

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

執行 adb shell 命令,帶有更多參數來控制命令行為。

void executeShellCommand (String command, IShellOutputReceiver receiver)

執行給定的 adb shell 命令,如果命令失敗則重試多次。

CommandResult executeShellV2Command (String cmd)

輔助方法,它執行 adb shell 命令並將結果作為CommandResult正確填充,其中包含命令狀態輸出、stdout 和 stderr。

CommandResult executeShellV2Command (String cmd, OutputStream pipeToOutput)

輔助方法,它執行CommandResult shell 命令並將結果作為正確填充命令狀態輸出和標準錯誤的命令結果返回。

CommandResult executeShellV2Command (String cmd, File pipeAsInput)

輔助方法,它執行 adb shell 命令並將結果作為正確填充命令狀態輸出、stdout 和 stderr 的CommandResult返回。

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 的 Map。

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)

Helper 方法收集自給定時間以來從設備和指定的時間單位開始的啟動時間和啟動原因的啟動歷史映射。

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

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

返回一個對像以獲取 keyguard 的當前狀態,如果不支持,則返回 null。

long getLastExpectedRebootTimeMillis ()

返回自 EPOCH 以來 Tradefed API 觸發重啟的最後一次時間(以毫秒為單位),由System.currentTimeMillis()返回。

int getLaunchApiLevel ()

獲取設備的第一個啟動的 API 級別。

InputStreamSource getLogcat ()

抓取 logcat 數據的快照流。

InputStreamSource getLogcat (int maxBytes)

獲取捕獲的 logcat 數據的最後一個maxBytes的快照流。

InputStreamSource getLogcatDump ()

獲取設備當前 logcat 的轉儲。

InputStreamSource getLogcatSince (long date)

從提供的日期開始抓取捕獲的 logcat 數據的快照流。

String getMacAddress ()

返回設備的MAC地址,如果從設備查詢失敗則返回null。

getMainlineModuleInfo ()

獲取設備上安裝的主線模塊的信息。

int getMaxNumberOfRunningUsersSupported ()

獲取支持的同時運行用戶的最大數量。

int getMaxNumberOfUsersSupported ()

獲取支持的最大用戶數。

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 erase 或 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 軟件包。

boolean isAdbRoot ()

boolean isAdbTcp ()
boolean isAppEnumerationSupported ()

檢查設備上的平台是否支持應用枚舉

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

測試wifi是否開啟。

listDisplayIds ()

收集“dumpsys SurfaceFlinger”報告的設備上可用顯示 ID 的列表。

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

使設備上的系統分區可寫。

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, ITestLifeCycleReceiver... listeners)

ITestDevice#runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...)相同,但為給定用戶運行測試。

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))但運行測試對於給定的用戶。

void setConfiguration ( IConfiguration configuration)

注入正在使用的IConfiguration

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 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 setUseFastbootErase (boolean useFastbootErase)

設置是否使用 fastboot erase 或 fastboot 格式擦除設備上的分區。

void startLogcat ()

開始在後台從設備捕獲 logcat 輸出。

boolean startUser (int userId)

如果當前已停止,則在後台啟動給定用戶。

boolean startUser (int userId, 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)

切換到另一個具有默認超時的 userId。

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

如果設備處於加密狀態,則解鎖設備。

boolean waitForBootComplete (long timeOut)

阻塞直到設備的啟動完成標誌被設置。

boolean waitForDeviceAvailable ()

等待設備響應並可用於測試。

boolean waitForDeviceAvailable (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 checkApiLevelAgainst (String feature, int strictMinLevel)
NativeDevice.RebootDeviceAction createRebootDeviceAction ( NativeDevice.RebootMode rebootMode, String reason)

創建要在執行重新啟動操作時使用的RebootDeviceAction

void doAdbReboot ( NativeDevice.RebootMode rebootMode, String reason)

執行 adb 重啟。

void ensureRuntimePermissionSupported ()

如果不支持運行時權限,則拋出異常的輔助方法

InputStreamSource getBugreportInternal ()
File getBugreportzInternal ()

將 bugreportz zip 文件作為ERROR(/File)獲取的內部助手方法。

IRunUtil getRunUtil ()

獲取要使用的RunUtil實例。

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

默認情況下,從 ddmlib 緩存中獲取設備屬性,然後根據設備是否處於 Fastboot 狀態,回退到 `adb shell getprop` 或 `fastboot getvar`。

boolean isNewer (File localFile, IFileEntry entry)

如果本地文件比遠程文件更新,則返回true

boolean performDeviceAction (String actionDescription, com.android.tradefed.device.NativeDevice.DeviceAction action, int retryAttempts)

在此設備上執行操作。

void postAdbReboot ()

重新啟動後可能採取的額外操作。

void prePostBootSetup ()

允許每種設備類型(AndroidNativeDevice、TestDevice)覆蓋此方法以進行特定的啟動後設置。

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

設置要使用的時鐘實例。

void setLogStartDelay (int delay)

設置開始在線設備的 logcat 捕獲之前等待的時間(以毫秒為單位)。

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)

MAX_RETRY_ATTEMPTS

protected static final int MAX_RETRY_ATTEMPTS

命令重試嘗試執行的默認次數

常數值:2 (0x00000002)

字段

SD卡

protected static final String SD_CARD

STORAGE_EMULATED

protected static final String STORAGE_EMULATED

mOptions

protected TestDeviceOptions mOptions

mStateMonitor

protected final IDeviceStateMonitor mStateMonitor

公共構造函數

NativeDevice

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

創建一個TestDevice

參數
device IDevice : 關聯的IDevice

stateMonitor IDeviceStateMonitor :要使用的IDeviceStateMonitor機制

allocationMonitor IDeviceMonitor :通知分配狀態更改的IDeviceMonitor 。可以為空

公共方法

checkApiLevelAgainstNextRelease

public boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

在給定最低支持級別的情況下,檢查當前是否支持某個功能。在 API 級別提升之前,此方法考慮了尚未發布的功能。

參數
strictMinLevel int :支持該功能的嚴格最小可能級別。

退貨
boolean如果支持該級別,則為真。否則為假。

投擲
DeviceNotAvailableException

檢查連接性

public boolean checkConnectivity ()

檢查設備是否具有網絡連接。

退貨
boolean如果設備具有有效的網絡連接,則為true ,否則為false

投擲
DeviceNotAvailableException

清除錯誤對話框

public boolean clearErrorDialogs ()

嘗試關閉設備 UI 上當前顯示的任何錯誤對話框。

退貨
boolean如果不存在對話框或成功清除對話框,則為true 。否則false

投擲
DeviceNotAvailableException

clearLastConnectedWifi網絡

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

參數
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

connectToWifiNetworkIfNeeded

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

connectToWifiNetwork(String, String)的一種變體,僅在設備當前沒有網絡連接時才連接。

參數
scanSsid boolean : 是否掃描此網絡的隱藏 SSID

退貨
boolean如果成功連接到 wifi 網絡,則為true 。否則false

投擲
DeviceNotAvailableException

connectToWifiNetworkIfNeeded

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)

創建一個具有給定名稱和默認標誌 0 的用戶。

參數
name String : 要在設備上創建的用戶

退貨
int創建的用戶 ID 的整數

投擲
DeviceNotAvailableException

createUserNoThrow

public int createUserNoThrow (String name)

創建一個具有給定名稱和默認標誌 0 的用戶。

參數
name String : 要在設備上創建的用戶

退貨
int創建的用戶 ID 的整數或 -1 表示錯誤。

投擲
DeviceNotAvailableException

刪除文件

public void deleteFile (String deviceFilePath)

用於刪除設備上的文件或目錄的輔助方法。

參數
deviceFilePath String : 文件在設備上的絕對路徑。

投擲
DeviceNotAvailableException

deviceSoftRestarted

public boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

通過比較當前 system_server 和以前的 system_server ProcessInfo來檢查設備是否軟重啟的輔助方法。使用getProcessByName(String)獲取ProcessInfo

參數
prevSystemServerProcess ProcessInfo :之前的 system_server 進程ProcessInfo

退貨
boolean如果設備軟重啟,則為true

投擲
DeviceNotAvailableException

deviceSoftRestartedSince

public boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

輔助方法,用於檢查設備是否自 UTC 時間以來從設備及其ERROR(/TimeUnit)開始軟重啟。軟重啟是指 system_server 在設備硬重啟之外重啟(例如:請求重啟)。可以通過getDeviceDate()方法獲取 Milliseseccond 中的當前設備 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

disconnectFromWifi

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

執行AdbCommand

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

輔助方法,它執行 adb 命令作為具有指定超時的系統命令。

應盡可能使用executeShellCommand(String) ,因為該方法提供了更好的故障檢測和性能。

參數
timeout long :設備被認為無響應之前的時間(以毫秒為單位),0L 表示沒有超時

cmdArgs String :要運行的 adb 命令和參數

退貨
String命令的標準輸出。如果命令執行失敗,則返回null

投擲
DeviceNotAvailableException

執行AdbCommand

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 ( envVarMap, 
                String... cmdArgs)

輔助方法,它將長時間運行的 fastboot 命令作為具有系統環境變量的系統命令執行。

executeFastbootCommand(String)相同,只是使用了更長的超時時間。

參數
envVarMap : fastboot 命令運行的系統環境變量

cmdArgs String : 要運行的 fastboot 命令和參數

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException

執行LongFastboot命令

public CommandResult executeLongFastbootCommand (String... cmdArgs)

將長時間運行的快速啟動命令作為系統命令執行的輔助方法。

executeFastbootCommand(String)相同,只是使用了更長的超時時間。

參數
cmdArgs String : 要運行的 fastboot 命令和參數

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException

執行ShellCommand

public String executeShellCommand (String command)

執行 adb shell 命令並以String形式返回輸出的輔助方法。

參數
command String : 要運行的 adb shell 命令

退貨
String外殼輸出

投擲
DeviceNotAvailableException

執行ShellCommand

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

執行 adb shell 命令,帶有更多參數來控制命令行為。

參數
command String : 要運行的 adb shell 命令

receiver IShellOutputReceiver :將 shell 輸出定向到的IShellOutputReceiver

maxTimeToOutputShellResponse long :允許命令不輸出任何響應的最長時間; timeUnit中指定的單位

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

retryAttempts int :如果由於異常而失敗,則重試命令的最大次數。如果retryAttempts未成功執行,將拋出 DeviceNotResponsiveException。

投擲
DeviceNotAvailableException

執行ShellCommand

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

執行 adb shell 命令,帶有更多參數來控制命令行為。

參數
command String : 要運行的 adb shell 命令

receiver IShellOutputReceiver :將 shell 輸出定向到的IShellOutputReceiver

maxTimeoutForCommand long :命令完成的最大超時時間; timeUnit中指定的單位

maxTimeToOutputShellResponse long :允許命令不輸出任何響應的最長時間; timeUnit中指定的單位

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

retryAttempts int :如果由於異常而失敗,則重試命令的最大次數。如果retryAttempts未成功執行,將拋出 DeviceNotResponsiveException。

投擲
DeviceNotAvailableException

執行ShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

執行給定的 adb shell 命令,如果命令失敗則重試多次。

具有默認值的executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, long, TimeUnit, int)的更簡單形式。

參數
command String : 要運行的 adb shell 命令

receiver IShellOutputReceiver :將 shell 輸出定向到的IShellOutputReceiver

投擲
DeviceNotAvailableException

執行ShellV2命令

public CommandResult executeShellV2Command (String cmd)

輔助方法,它執行 adb shell 命令並將結果作為CommandResult正確填充,其中包含命令狀態輸出、stdout 和 stderr。

參數
cmd String :應該運行的命令。

退貨
CommandResult CommandResult中的結果。

投擲
DeviceNotAvailableException

執行ShellV2命令

public CommandResult executeShellV2Command (String cmd, 
                OutputStream pipeToOutput)

輔助方法,它執行CommandResult shell 命令並將結果作為正確填充命令狀態輸出和標準錯誤的命令結果返回。 stdout 被定向到指定的流。

參數
cmd String :應該運行的命令。

pipeToOutput OutputStream : ERROR(/OutputStream)將重定向 std 輸出,或者為 null。

退貨
CommandResult CommandResult中的結果。

投擲
DeviceNotAvailableException

執行ShellV2命令

public CommandResult executeShellV2Command (String cmd, 
                File pipeAsInput)

輔助方法,它執行 adb shell 命令並將結果作為正確填充命令狀態輸出、stdout 和 stderr 的CommandResult返回。

參數
cmd String :應該運行的命令。

pipeAsInput File : 一個ERROR(/File)將作為命令的輸入通過管道傳輸,或者為 null。

退貨
CommandResult CommandResult中的結果。

投擲
DeviceNotAvailableException

執行ShellV2命令

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

執行 adb shell 命令,帶有更多參數來控制命令行為。

參數
cmd String : 要運行的 adb shell 命令

maxTimeoutForCommand long :命令完成的最大超時時間; timeUnit中指定的單位

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

retryAttempts int :如果由於異常而失敗,則重試命令的最大次數。 DeviceNotResponsiveException will be thrown if retryAttempts are performed without success.

退貨
CommandResult

投擲
DeviceNotAvailableException

executeShellV2Command

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

Executes a adb shell command, with more parameters to control command behavior.

參數
cmd String : the adb shell command to run

maxTimeoutForCommand long : the maximum timeout for the command to complete; unit as specified in timeUnit

timeUnit TimeUnit : unit for maxTimeToOutputShellResponse

退貨
CommandResult

投擲
DeviceNotAvailableException

executeShellV2Command

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

Executes a adb shell command, with more parameters to control command behavior.

參數
cmd String : the adb shell command to run

pipeAsInput File : A ERROR(/File) that will be piped as input to the command, or null.

pipeToOutput OutputStream : ERROR(/OutputStream) where the std output will be redirected, or null.

maxTimeoutForCommand long : the maximum timeout for the command to complete; unit as specified in timeUnit

timeUnit TimeUnit : unit for maxTimeToOutputShellResponse

retryAttempts int : the maximum number of times to retry command if it fails due to a exception. DeviceNotResponsiveException will be thrown if retryAttempts are performed without success.

退貨
CommandResult

投擲
DeviceNotAvailableException

executeShellV2Command

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

Executes a adb shell command, with more parameters to control command behavior.

參數
cmd String : the adb shell command to run

pipeAsInput File : A ERROR(/File) that will be piped as input to the command, or null.

pipeToOutput OutputStream : ERROR(/OutputStream) where the std output will be redirected, or null.

pipeToError OutputStream : ERROR(/OutputStream) where the std error will be redirected, or null.

maxTimeoutForCommand long : the maximum timeout for the command to complete; unit as specified in timeUnit

timeUnit TimeUnit : unit for maxTimeToOutputShellResponse

retryAttempts int : the maximum number of times to retry command if it fails due to a exception. DeviceNotResponsiveException will be thrown if retryAttempts are performed without success.

退貨
CommandResult

投擲
DeviceNotAvailableException

fastbootWipePartition

public CommandResult fastbootWipePartition (String partition)

Helper method which wipes a partition for the device.

If getUseFastbootErase() is true , then fastboot erase will be used to wipe the partition. The device must then create a filesystem the next time the device boots. Otherwise, fastboot format is used which will create a new filesystem on the device.

Expected to be used when device is already in fastboot mode.

參數
partition String : the partition to wipe

退貨
CommandResult the CommandResult containing output of command

投擲
DeviceNotAvailableException

getActiveApexes

public  getActiveApexes ()

Fetch the information about APEXes activated on the device.

退貨
ERROR(/Set) of ApexInfo currently activated on the device

投擲
DeviceNotAvailableException

getAllSettings

public  getAllSettings (String namespace)

Return key value pairs of requested namespace.

參數
namespace String : must be one of {"system", "secure", "global"}

退貨
the map of key value pairs. Null if namespace is not supported.

投擲
DeviceNotAvailableException

getAllocationState

public DeviceAllocationState getAllocationState ()

Return the current allocation state of device

退貨
DeviceAllocationState

getAndroidId

public String getAndroidId (int userId)

Find and return the android-id associated to a userId, null if not found.

參數
userId int

退貨
String

投擲
DeviceNotAvailableException

getAndroidIds

public  getAndroidIds ()

Create a Map of android ids found matching user ids. There is no insurance that each user id will found an android id associated in this function so some user ids may match null.

退貨
Map of android ids found matching user ids.

投擲
DeviceNotAvailableException

getApiLevel

public int getApiLevel ()

Get the device API Level. Defaults to UNKNOWN_API_LEVEL .

退貨
int an integer indicating the API Level of device

投擲
DeviceNotAvailableException

getAppPackageInfo

public PackageInfo getAppPackageInfo (String packageName)

Fetch information about a package installed on device.

參數
packageName String

退貨
PackageInfo the PackageInfo or null if information could not be retrieved

投擲
DeviceNotAvailableException

getAppPackageInfos

public  getAppPackageInfos ()

Fetch information of packages installed on the device.

退貨
ERROR(/List) of PackageInfo s installed on the device.

投擲
DeviceNotAvailableException

getBasebandVersion

public String getBasebandVersion ()

Convenience method to get baseband (radio) version of this device. Getting the radio version is device specific, so it might not return the correct information for all devices. This method relies on the gsm.version.baseband propery to return the correct version information. This is not accurate for some CDMA devices and the version returned here might not match the version reported from fastboot and might not return the version for the CDMA radio. TL;DR this method only reports accurate version if the gsm.version.baseband property is the same as the version returned by fastboot getvar version-baseband .

退貨
String the String baseband version or null if it cannot be determined (device has no radio or version string cannot be read)

投擲
DeviceNotAvailableException

getBattery

public Integer getBattery ()

Returns the current battery level of a device or Null if battery level unavailable.

退貨
Integer

getBooleanProperty

public boolean getBooleanProperty (String name, 
                boolean defaultValue)

Returns boolean value of the given property.

參數
name String : the property name

defaultValue boolean : default value to return if property is empty or doesn't exist.

退貨
boolean true if the property has value "1" , "y" , "yes" , "on" , or "true" , false if the property has value of "0" , "n" , "no" , "off" , "false" , or defaultValue otherwise.

投擲
DeviceNotAvailableException

getBootHistory

public  getBootHistory ()

Helper method collects the boot history map with boot time and boot reason.

退貨
Map of boot time (UTC time in second since Epoch) and boot reason

投擲
DeviceNotAvailableException

getBootHistorySince

public  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

Helper method collects the boot history map with boot time and boot reason since the given time since epoch from device and the time unit specified. The current device utcEpochTime in Millisecond can be obtained by method getDeviceDate() .

參數
utcEpochTime long : the device time since Epoch.

timeUnit TimeUnit : the time unit TimeUnit .

退貨
Map of boot time (UTC time in second since Epoch) and boot reason

投擲
DeviceNotAvailableException

getBootloaderVersion

public String getBootloaderVersion ()

Convenience method to get the bootloader version of this device.

Will attempt to retrieve bootloader version from the device's current state. (ie if device is in fastboot mode, it will attempt to retrieve version from fastboot)

退貨
String the String bootloader version or null if it cannot be found

投擲
DeviceNotAvailableException

getBugreport

public InputStreamSource getBugreport ()

Retrieves a bugreport from the device.

The implementation of this is guaranteed to continue to work on a device without an sdcard (or where the sdcard is not yet mounted).

退貨
InputStreamSource An InputStreamSource which will produce the bugreport contents on demand. In case of failure, the InputStreamSource will produce an empty ERROR(/InputStream) .

getBugreportz

public InputStreamSource getBugreportz ()

Retrieves a bugreportz from the device. Zip format bugreport contains the main bugreport and other log files that are useful for debugging.

Only supported for 'adb version' > 1.0.36

退貨
InputStreamSource a InputStreamSource of the zip file containing the bugreportz, return null in case of failure.

getBuildAlias

public String getBuildAlias ()

Retrieve the alias of the build that the device is currently running.

Build alias is usually a more readable string than build id (typically a number for Nexus builds). For example, final Android 4.2 release has build alias JDQ39, and build id 573038

退貨
String the build alias or fall back to build id if it could not be retrieved

投擲
DeviceNotAvailableException

getBuildFlavor

public String getBuildFlavor ()

Retrieve the build flavor for the device.

退貨
String the build flavor or null if it could not be retrieved

投擲
DeviceNotAvailableException

getBuildId

public String getBuildId ()

Retrieve the build the device is currently running.

退貨
String the build id or IBuildInfo#UNKNOWN_BUILD_ID if it could not be retrieved

投擲
DeviceNotAvailableException

getBuildSigningKeys

public String getBuildSigningKeys ()

Returns the key type used to sign the device image

Typically Android devices may be signed with test-keys (like in AOSP) or release-keys (controlled by individual device manufacturers)

退貨
String The signing key if found, null otherwise.

投擲
DeviceNotAvailableException

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor ()

Returns a cached DeviceDescriptor if the device is allocated, otherwise returns the current DeviceDescriptor .

退貨
DeviceDescriptor

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

Returns a cached DeviceDescriptor if the device is allocated, otherwise returns the current DeviceDescriptor .

參數
shortDescriptor boolean : Whether or not to limit descriptor to bare minimum info

退貨
DeviceDescriptor

getChildren

public String[] getChildren (String path)

Alternative to using IFileEntry that sometimes won't work because of permissions.

參數
path String : is the path on the device where to do the search

退貨
String[] Array of string containing all the file in a path on the device.

投擲
DeviceNotAvailableException

getCurrentFoldableState

public DeviceFoldableState getCurrentFoldableState ()

Returns the current foldable state of the device or null if some issues occurred.

退貨
DeviceFoldableState

投擲
DeviceNotAvailableException

getCurrentUser

public int getCurrentUser ()

Return the id of the current running user. In case of error, return -10000.

退貨
int

投擲
DeviceNotAvailableException

getDeviceClass

public String getDeviceClass ()

Get the device class.

退貨
String the String device class.

getDeviceDate

public long getDeviceDate ()

Return the date of the device in millisecond since epoch.

退貨
long the date of the device in epoch format.

投擲
DeviceNotAvailableException

getDeviceDescriptor

public DeviceDescriptor getDeviceDescriptor ()

Return a DeviceDescriptor from the device information to get info on it without passing the actual device object.

退貨
DeviceDescriptor

getDeviceDescriptor

public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

Return a DeviceDescriptor from the device information to get info on it without passing the actual device object.

參數
shortDescriptor boolean : Whether or not to limit descriptor to bare minimum info

退貨
DeviceDescriptor

getDeviceState

public TestDeviceState getDeviceState ()

Get the device's state.

退貨
TestDeviceState

getDeviceTimeOffset

public long getDeviceTimeOffset (Date date)

Helper to get the time difference between the device and a given ERROR(/Date) . Use Epoch time internally.

參數
date Date

退貨
long the difference in milliseconds

投擲
DeviceNotAvailableException

getEmulatorOutput

public InputStreamSource getEmulatorOutput ()

Get the stream of emulator stdout and stderr

退貨
InputStreamSource emulator output

getEmulatorProcess

public Process getEmulatorProcess ()

Return the Process corresponding to this emulator.

退貨
Process the Process or null

getExecuteShellCommandLog

public final File getExecuteShellCommandLog ()

The log that contains all the executeShellCommand(String) logs.

退貨
File

getExternalStoreFreeSpace

public long getExternalStoreFreeSpace ()

Helper method to determine amount of free space on device external storage.

退貨
long the amount of free space in KB

投擲
DeviceNotAvailableException

getFastbootPath

public String getFastbootPath ()

Returns the path of the fastboot binary being used. Still requires isFastbootEnabled() to be true, to have fastboot functions enabled.

退貨
String

getFastbootProductType

public String getFastbootProductType ()

Convenience method to get the product type of this device when its in fastboot mode.

This method should only be used if device should be in fastboot. Its a bit safer variant than the generic getProductType() method in this case, because ITestDevice will know to recover device into fastboot if device is in incorrect state or is unresponsive.

退貨
String the String product type name or null if it cannot be determined

投擲
DeviceNotAvailableException

getFastbootProductVariant

public String getFastbootProductVariant ()

Convenience method to get the product type of this device when its in fastboot mode.

This method should only be used if device should be in fastboot. Its a bit safer variant than the generic getProductType() method in this case, because ITestDevice will know to recover device into fastboot if device is in incorrect state or is unresponsive.

退貨
String the String product type name or null if it cannot be determined

投擲
DeviceNotAvailableException

getFastbootSerialNumber

public String getFastbootSerialNumber ()

Returns the fastboot mode serial number.

退貨
String

getFastbootVariable

public String getFastbootVariable (String variableName)

Retrieve the given fastboot variable value from the device.

參數
variableName String : the variable name

退貨
String the property value or null if it does not exist

投擲
DeviceNotAvailableException

getFastbootVersion

public String getFastbootVersion ()

Returns the version string of the fastboot binary being used. Or null if something goes wrong.

退貨
String

getFileEntry

public IFileEntry getFileEntry (String path)

Retrieve a reference to a remote file on device.

參數
path String : the file path to retrieve. Can be an absolute path or path relative to '/'. (ie both "/system" and "system" syntax is supported)

退貨
IFileEntry the IFileEntry or null if file at given path cannot be found

投擲
DeviceNotAvailableException

getFileEntry

public IFileEntry getFileEntry (FileListingService.FileEntry entry)

Unofficial helper to get a FileEntry from a non-root path. FIXME: Refactor the FileEntry system to have it available from any path. (even non root).

參數
entry FileListingService.FileEntry : a FileEntry not necessarily root as Ddmlib requires.

退貨
IFileEntry a FileEntryWrapper representing the FileEntry.

投擲
DeviceNotAvailableException

getFoldableStates

public  getFoldableStates ()

Returns the list of foldable states on the device. Can be obtained with "cmd device_state print-states".

退貨

投擲
DeviceNotAvailableException

getIDevice

public IDevice getIDevice ()

Returns a reference to the associated ddmlib IDevice .

A new IDevice may be allocated by DDMS each time the device disconnects and reconnects from adb. Thus callers should not keep a reference to the IDevice , because that reference may become stale.

退貨
IDevice the IDevice

getInstalledPackageNames

public  getInstalledPackageNames ()

Fetch the application package names present on the device.

退貨
ERROR(/Set) of String package names currently installed on the device.

投擲
DeviceNotAvailableException

getIntProperty

public long getIntProperty (String name, 
                long defaultValue)

Returns integer value of the given property from the device.

參數
name String : the property name

defaultValue long : default value to return if property is empty or doesn't exist.

退貨
long the property value or defaultValue if the property is empty, doesn't exist, or doesn't have an integer value.

投擲
DeviceNotAvailableException

getIpAddress

public String getIpAddress ()

Gets the device's IP address.

退貨
String the device's IP address, or null if device has no IP address

投擲
DeviceNotAvailableException

getKeyguardState

public KeyguardControllerState getKeyguardState ()

Return an object to get the current state of the keyguard or null if not supported.

退貨
KeyguardControllerState a KeyguardControllerState containing a snapshot of the state of the keyguard and returns Null if the Keyguard query is not supported.

投擲
DeviceNotAvailableException

getLastExpectedRebootTimeMillis

public long getLastExpectedRebootTimeMillis ()

Returns the last time Tradefed APIs triggered a reboot in milliseconds since EPOCH as returned by System.currentTimeMillis() .

退貨
long

getLaunchApiLevel

public int getLaunchApiLevel ()

Get the device's first launched API Level. Defaults to UNKNOWN_API_LEVEL .

退貨
int an integer indicating the first launched API Level of device

投擲
DeviceNotAvailableException

getLogcat

public InputStreamSource getLogcat ()

Grabs a snapshot stream of the logcat data.

Works in two modes:

  • If the logcat is currently being captured in the background, will return up to TestDeviceOptions.getMaxLogcatDataSize() bytes of the current contents of the background logcat capture
  • Otherwise, will return a static dump of the logcat data if device is currently responding

    退貨
    InputStreamSource

  • getLogcat

    public InputStreamSource getLogcat (int maxBytes)

    Grabs a snapshot stream of the last maxBytes of captured logcat data.

    Useful for cases when you want to capture frequent snapshots of the captured logcat data without incurring the potentially big disk space penalty of getting the entire getLogcat() snapshot.

    參數
    maxBytes int : the maximum amount of data to return. Should be an amount that can comfortably fit in memory

    退貨
    InputStreamSource

    getLogcatDump

    public InputStreamSource getLogcatDump ()

    Get a dump of the current logcat for device. Unlike getLogcat() , this method will always return a static dump of the logcat.

    Has the disadvantage that nothing will be returned if device is not reachable.

    退貨
    InputStreamSource a InputStreamSource of the logcat data. An empty stream is returned if fail to capture logcat data.

    getLogcatSince

    public InputStreamSource getLogcatSince (long date)

    Grabs a snapshot stream of captured logcat data starting the date provided. The time on the device should be used getDeviceDate() .

    參數
    date long : in millisecond since epoch format of when to start the snapshot until present. (can be be obtained using 'date +%s')

    退貨
    InputStreamSource

    getMacAddress

    public String getMacAddress ()

    Returns the MAC address of the device, null if it fails to query from the device.

    退貨
    String

    getMainlineModuleInfo

    public  getMainlineModuleInfo ()

    Get the information about the mainline modules installed on the device.

    退貨
    ERROR(/Set) of String mainline modules currently installed on the device.

    投擲
    DeviceNotAvailableException

    getMaxNumberOfRunningUsersSupported

    public int getMaxNumberOfRunningUsersSupported ()

    Get the maximum number of supported simultaneously running users. Defaults to 0.

    退貨
    int an integer indicating the number of simultaneously running users

    投擲
    DeviceNotAvailableException

    getMaxNumberOfUsersSupported

    public int getMaxNumberOfUsersSupported ()

    Get the maximum number of supported users. Defaults to 0.

    退貨
    int an integer indicating the number of supported users

    投擲
    DeviceNotAvailableException

    getMonitor

    public IDeviceStateMonitor getMonitor ()

    Return the IDeviceStateMonitor associated with device.

    退貨
    IDeviceStateMonitor

    getMountPoint

    public String getMountPoint (String mountName)

    Returns a mount point.

    Queries the device directly if the cached info in IDevice is not available.

    TODO: move this behavior to IDevice#getMountPoint(String)

    參數
    mountName String : the name of the mount point

    退貨
    String the mount point or null

    getMountPointInfo

    public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    Returns a MountPointInfo corresponding to the specified mountpoint path, or null if that path has nothing mounted or otherwise does not appear in /proc/mounts as a mountpoint.

    參數
    mountpoint String

    退貨
    ITestDevice.MountPointInfo A ERROR(/List) of MountPointInfo containing the information in "/proc/mounts"

    投擲
    DeviceNotAvailableException

    getMountPointInfo

    public  getMountPointInfo ()

    Returns a parsed version of the information in /proc/mounts on the device

    退貨
    A ERROR(/List) of MountPointInfo containing the information in "/proc/mounts"

    投擲
    DeviceNotAvailableException

    getOptions

    public TestDeviceOptions getOptions ()

    Fetch the test options for the device.

    退貨
    TestDeviceOptions TestDeviceOptions related to the device under test.

    getPartitionFreeSpace

    public long getPartitionFreeSpace (String partition)

    Helper method to determine amount of free space on device partition.

    參數
    partition String

    退貨
    long the amount of free space in KB

    投擲
    DeviceNotAvailableException

    getPrimaryUserId

    public Integer getPrimaryUserId ()

    Returns the primary user id.

    退貨
    Integer the userId of the primary user if there is one, and null if there is no primary user.

    投擲
    DeviceNotAvailableException

    getProcessByName

    public ProcessInfo getProcessByName (String processName)

    Helper method runs the "pidof" and "stat" command and returns ProcessInfo object with PID and process start time of the given process.

    參數
    processName String : the proces name String.

    退貨
    ProcessInfo ProcessInfo of given processName

    投擲
    DeviceNotAvailableException

    getProcessPid

    public String getProcessPid (String process)

    Returns the pid of the service or null if something went wrong.

    參數
    process String : The proces name String.

    退貨
    String

    投擲
    DeviceNotAvailableException

    getProductType

    public String getProductType ()

    Convenience method to get the product type of this device.

    This method will work if device is in either adb or fastboot mode.

    退貨
    String the String product type name. Will not be null

    投擲
    DeviceNotAvailableException

    getProductVariant

    public String getProductVariant ()

    Convenience method to get the product variant of this device.

    This method will work if device is in either adb or fastboot mode.

    退貨
    String the String product variant name or null if it cannot be determined

    投擲
    DeviceNotAvailableException

    getProperty

    public String getProperty (String name)

    Retrieve the given property value from the device.

    參數
    name String : the property name

    退貨
    String the property value or null if it does not exist

    投擲
    DeviceNotAvailableException

    getRecoveryMode

    public ITestDevice.RecoveryMode getRecoveryMode ()

    Get the current recovery mode used for the device.

    退貨
    ITestDevice.RecoveryMode the current recovery mode used for the device.

    getScreenshot

    public InputStreamSource getScreenshot (String format)

    Grabs a screenshot from the device. Recommended to use getScreenshot(format) instead with JPEG encoding for smaller size

    參數
    format String : supported PNG, JPEG

    退貨
    InputStreamSource a InputStreamSource of the screenshot in format, or null if the screenshot was not successful.

    投擲
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot (long displayId)

    Grabs a screenshot from the device given display id. Format is PNG.

    TODO: extend the implementations above to support 'format' and 'rescale'

    參數
    displayId long : the display id of the screen to get screenshot from.

    退貨
    InputStreamSource a InputStreamSource of the screenshot in format, or null if the screenshot was not successful.

    投擲
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot (String format, 
                    boolean rescale)

    Grabs a screenshot from the device. Recommended to use getScreenshot(String) instead with JPEG encoding for smaller size.

    參數
    format String : supported PNG, JPEG

    rescale boolean : if screenshot should be rescaled to reduce the size of resulting image

    退貨
    InputStreamSource a InputStreamSource of the screenshot in format, or null if the screenshot was not successful.

    投擲
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot ()

    Grabs a screenshot from the device.

    退貨
    InputStreamSource a InputStreamSource of the screenshot in png format, or null if the screenshot was not successful.

    投擲
    DeviceNotAvailableException

    getSerialNumber

    public String getSerialNumber ()

    Convenience method to get serial number of this device.

    退貨
    String the String serial number

    getSetting

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

    Return the value of the requested setting. namespace must be one of: {"system", "secure", "global"}

    參數
    userId int

    namespace String

    key String

    退貨
    String the value associated with the namespace:key of a user. Null if not found.

    投擲
    DeviceNotAvailableException

    getSetting

    public String getSetting (String namespace, 
                    String key)

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

    參數
    namespace String

    key String

    退貨
    String

    投擲
    DeviceNotAvailableException

    getSimOperator

    public String getSimOperator ()

    Return the SIM card operator or null if not available or if device is not available.

    退貨
    String

    getSimState

    public String getSimState ()

    Return the SIM card state or null if not available or device is not available.

    退貨
    String

    getTombstones

    public  getTombstones ()

    Fetch and return the list of tombstones from the devices. Requires root.

    method is best-effort so if one tombstone fails to be pulled for any reason it will be missing from the list. Only a DeviceNotAvailableException will terminate the method early.

    退貨
    A list of tombstone files, empty if no tombstone.

    投擲
    DeviceNotAvailableException

    getTotalMemory

    public long getTotalMemory ()

    Returns total physical memory size in bytes or -1 in case of internal error

    退貨
    long

    getUninstallablePackageNames

    public  getUninstallablePackageNames ()

    Fetch the application package names that can be uninstalled. This is presently defined as non-system packages, and updated system packages.

    退貨
    ERROR(/Set) of uninstallable String package names currently installed on the device.

    投擲
    DeviceNotAvailableException

    getUseFastbootErase

    public boolean getUseFastbootErase ()

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

    退貨
    boolean true if fastboot erase will be used or false if fastboot format will be used.

    getUserFlags

    public int getUserFlags (int userId)

    Find and return the flags of a given user. Flags are defined in "android.content.pm.UserInfo" class in Android Open Source Project.

    參數
    userId int

    退貨
    int the flags associated with the userId provided if found, -10000 in any other cases.

    投擲
    DeviceNotAvailableException

    getUserInfos

    public  getUserInfos ()

    Gets the Map of useId to UserInfo on the device. Will throw DeviceRuntimeException if output from device is not as expected.

    退貨
    the list of UserInfo objects.

    投擲
    DeviceNotAvailableException

    getUserSerialNumber

    public int getUserSerialNumber (int userId)

    Return the serial number associated to the userId if found, -10000 in any other cases.

    參數
    userId int

    退貨
    int

    投擲
    DeviceNotAvailableException

    handleAllocationEvent

    public IManagedTestDevice.DeviceEventResponse handleAllocationEvent (DeviceEvent event)

    Process the given DeviceEvent . May transition device to new state. Will inform the IDeviceMonitor of any state transitions.

    Process the DeviceEvent, which may or may not transition this device to a new allocation state.

    參數
    event DeviceEvent

    退貨
    IManagedTestDevice.DeviceEventResponse

    hasFeature

    public boolean hasFeature (String feature)

    Check if a feature is available on a device.

    參數
    feature String : which format should be "feature: " or " " directly.

    退貨
    boolean True if feature is found, false otherwise.

    投擲
    DeviceNotAvailableException

    installPackage

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

    Install an Android package on device.

    參數
    packageFile File : the apk file to install

    reinstall boolean : true if a reinstall should be performed

    extraArgs String : optional extra arguments to pass. See 'adb shell pm -h' for available options.

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

    投擲
    DeviceNotAvailableException

    installPackage

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

    Install an Android package on device.

    Note: Only use cases that requires explicit control of granting runtime permission at install time should call this function.

    參數
    packageFile File : the apk file to install

    reinstall boolean : true if a reinstall should be performed

    grantPermissions boolean : if all runtime permissions should be granted at install time

    extraArgs String : optional extra arguments to pass. See 'adb shell pm -h' for available options.

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

    投擲
    DeviceNotAvailableException

    installPackageForUser

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

    Install an Android package on device for a given user.

    參數
    packageFile File : the apk file to install

    reinstall boolean : true if a reinstall should be performed

    userId int : the integer user id to install for.

    extraArgs String : optional extra arguments to pass. See 'adb shell pm -h' for available options.

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

    投擲
    DeviceNotAvailableException

    installPackageForUser

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

    Install an Android package on device for a given user.

    Note: Only use cases that requires explicit control of granting runtime permission at install time should call this function.

    參數
    packageFile File : the apk file to install

    reinstall boolean : true if a reinstall should be performed

    grantPermissions boolean : if all runtime permissions should be granted at install time

    userId int : the integer user id to install for.

    extraArgs String : optional extra arguments to pass. See 'adb shell pm -h' for available options.

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

    投擲
    DeviceNotAvailableException

    isAdbRoot

    public boolean isAdbRoot ()

    退貨
    boolean

    投擲
    DeviceNotAvailableException

    isAdbTcp

    public boolean isAdbTcp ()

    退貨
    boolean

    isAppEnumerationSupported

    public boolean isAppEnumerationSupported ()

    Check whether platform on device supports app enumeration

    退貨
    boolean True if app enumeration is supported, false otherwise

    投擲
    DeviceNotAvailableException

    isDeviceEncrypted

    public boolean isDeviceEncrypted ()

    Returns if the device is encrypted.

    退貨
    boolean true if the device is encrypted.

    投擲
    DeviceNotAvailableException

    isDirectory

    public boolean isDirectory (String path)

    Return True if the path on the device is a directory, false otherwise.

    參數
    path String

    退貨
    boolean

    投擲
    DeviceNotAvailableException

    isEnableAdbRoot

    public boolean isEnableAdbRoot ()

    退貨
    boolean true if adb root should be enabled on device

    isEncryptionSupported

    public boolean isEncryptionSupported ()

    Returns if encryption is supported on the device.

    退貨
    boolean true if the device supports encryption.

    投擲
    DeviceNotAvailableException

    isExecutable

    public boolean isExecutable (String fullPath)

    Returns True if the file path on the device is an executable file, false otherwise.

    參數
    fullPath String

    退貨
    boolean

    投擲
    DeviceNotAvailableException

    isFastbootEnabled

    public boolean isFastbootEnabled ()

    Return if fastboot is available for the device.

    退貨
    boolean

    isHeadless

    public boolean isHeadless ()

    Return true if the device is headless (no screen), false otherwise.

    退貨
    boolean

    投擲
    DeviceNotAvailableException

    isMultiUserSupported

    public boolean isMultiUserSupported ()

    Determines if multi user is supported.

    退貨
    boolean true if multi user is supported, false otherwise

    投擲
    DeviceNotAvailableException

    isPackageInstalled

    public boolean isPackageInstalled (String packageName, 
                    String userId)

    Query the device for a given package name and given user id to check if it's currently installed or not for that user.

    參數
    packageName String : the package we are checking if it's installed.

    userId String : The user id we are checking the package is installed for. If null, primary user zero will be used.

    退貨
    boolean True if the package is reported as installed. False otherwise.

    投擲
    DeviceNotAvailableException

    isPackageInstalled

    public boolean isPackageInstalled (String packageName)

    Query the device for a given package name to check if it's currently installed or not.

    參數
    packageName String

    退貨
    boolean True if the package is reported as installed. False otherwise.

    投擲
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public boolean isRuntimePermissionSupported ()

    Check whether platform on device supports runtime permission granting

    退貨
    boolean True if runtime permission are supported, false otherwise.

    投擲
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public boolean isStateBootloaderOrFastbootd ()

    Returns true if device is in TestDeviceState#FASTBOOT or TestDeviceState.FASTBOOTD .

    退貨
    boolean

    isUserRunning

    public boolean isUserRunning (int userId)

    Check if a given user is running.

    參數
    userId int

    退貨
    boolean True if the user is running, false in every other cases.

    投擲
    DeviceNotAvailableException

    isUserSecondary

    public boolean isUserSecondary (int userId)

    Return whether the specified user is a secondary user according to it's flags.

    參數
    userId int

    退貨
    boolean true if the user is secondary, false otherwise.

    投擲
    DeviceNotAvailableException

    isWifiEnabled

    public boolean isWifiEnabled ()

    Test if wifi is enabled.

    Checks if wifi is enabled on device. Useful for asserting wifi status before tests that shouldn't run with wifi, eg mobile data tests.

    退貨
    boolean true if wifi is enabled. false if disabled

    投擲
    DeviceNotAvailableException

    listDisplayIds

    public  listDisplayIds ()

    Collect the list of available displays id on the device as reported by "dumpsys SurfaceFlinger".

    退貨
    The list of displays. Default always returns the default display 0.

    投擲
    DeviceNotAvailableException

    listUsers

    public  listUsers ()

    Gets the list of users on the device. Will throw DeviceRuntimeException if output from device is not as expected.

    退貨
    the list of user ids.

    投擲
    DeviceNotAvailableException

    logAnrs

    public boolean logAnrs (ITestLogger logger)

    Collects and log ANRs from the device.

    參數
    logger ITestLogger : an ITestLogger to log the ANRs.

    退貨
    boolean True if the logging was successful, false otherwise.

    投擲
    DeviceNotAvailableException

    logBugreport

    public boolean logBugreport (String dataName, 
                    ITestLogger listener)

    Helper method to take a bugreport and log it to the reporters.

    參數
    dataName String : name under which the bugreport will be reported.

    listener ITestLogger : an ITestLogger to log the bugreport.

    退貨
    boolean True if the logging was successful, false otherwise.

    logOnDevice

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

    Log a message in the logcat of the device. This is a safe call that will not throw even if the logging fails.

    參數
    tag String : The tag under which we log our message in the logcat.

    level Log.LogLevel : The debug level of the message in the logcat.

    format String : The message format.

    args Object : the args to be replaced via String.format().

    nonBlockingReboot

    public void nonBlockingReboot ()

    Issues a command to reboot device and returns on command complete and when device is no longer visible to adb.

    投擲
    DeviceNotAvailableException

    postAdbRootAction

    public void postAdbRootAction ()

    Override if the device needs some specific actions to be taken after adb root and before the device is back online. Default implementation doesn't include any addition actions. adb root is not guaranteed to be enabled at this stage.

    投擲
    DeviceNotAvailableException

    postAdbUnrootAction

    public void postAdbUnrootAction ()

    Override if the device needs some specific actions to be taken after adb unroot and before the device is back online. Default implementation doesn't include any additional actions. adb root is not guaranteed to be disabled at this stage.

    投擲
    DeviceNotAvailableException

    postBootSetup

    public void postBootSetup ()

    Perform instructions to configure device for testing that after every boot.

    Should be called after device is fully booted/available

    In normal circumstances this method doesn't need to be called explicitly, as implementations should perform these steps automatically when performing a reboot.

    Where it may need to be called is when device reboots due to other events (eg when a fastboot update command has completed)

    投擲
    DeviceNotAvailableException

    postInvocationTearDown

    public void postInvocationTearDown (Throwable exception)

    Extra steps for device specific required clean up that will be executed after the invocation is done.

    參數
    exception Throwable : if any, the final exception raised by the invocation failure.

    preInvocationSetup

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

    Extra steps for device specific required setup that will be executed on the device prior to the invocation flow.

    參數
    info IBuildInfo : The IBuildInfo of the device.

    attributes MultiMap : The attributes stored in the invocation context

    投擲
    DeviceNotAvailableException
    TargetSetupError

    pullDir

    public boolean pullDir (String deviceFilePath, 
                    File localDir)

    Recursively pull directory contents from device.

    參數
    deviceFilePath String : the absolute file path of the remote source

    localDir File : the local directory to pull files into

    退貨
    boolean true if file was pulled successfully. false otherwise.

    投擲
    DeviceNotAvailableException

    pullFile

    public boolean pullFile (String remoteFilePath, 
                    File localFile)

    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.

    退貨
    boolean true if file was retrieved successfully. false otherwise.

    投擲
    DeviceNotAvailableException

    pullFile

    public File pullFile (String remoteFilePath, 
                    int userId)

    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.

    userId int : The user id to pull from

    退貨
    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

    pullFile

    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

    pullFile

    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 otherwise.

    投擲
    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 otherwise.

    投擲
    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 otherwise.

    投擲
    DeviceNotAvailableException

    pushFile

    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 otherwise.

    投擲
    DeviceNotAvailableException

    pushFile

    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 otherwise.

    投擲
    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 otherwise.

    投擲
    DeviceNotAvailableException

    reboot

    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

    reboot

    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.

    WARNING. 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

    remountSystemWritable

    public void remountSystemWritable ()

    Make the system partition on the device writable. 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

    removeUser

    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, 
                    ITestLifeCycleReceiver... listeners)

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

    參數
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    退貨
    boolean

    投擲
    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

    setConfiguration

    public void setConfiguration (IConfiguration configuration)

    Injects the IConfiguration in use.

    參數
    configuration IConfiguration

    setDate

    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

    setOptions

    public void setOptions (TestDeviceOptions options)

    Set the TestDeviceOptions for the device

    參數
    options TestDeviceOptions

    setProperty

    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.

    setSetting

    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

    setSetting

    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

    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

    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.

    stopUser

    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

    stopUser

    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

    switchUser

    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. False otherwise.

    投擲
    DeviceNotAvailableException

    switchUser

    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. False otherwise.

    投擲
    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 otherwise.

    投擲
    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

    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

    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 otherwise

    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 otherwise

    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 otherwise

    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.

    受保護的方法

    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 .

    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.

    投擲
    DeviceNotAvailableException

    ensureRuntimePermissionSupported

    protected void ensureRuntimePermissionSupported ()

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

    投擲
    DeviceNotAvailableException

    getBugreportInternal

    protected InputStreamSource getBugreportInternal ()

    退貨
    InputStreamSource

    getBugreportzInternal

    protected File getBugreportzInternal ()

    Internal Helper method to get the bugreportz zip file as a ERROR(/File) .

    退貨
    File

    getRunUtil

    protected IRunUtil getRunUtil ()

    Get the RunUtil instance to use.

    退貨
    IRunUtil

    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

    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

    performDeviceAction

    protected boolean performDeviceAction (String actionDescription, 
                    com.android.tradefed.device.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 com.android.tradefed.device.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.

    投擲
    DeviceNotAvailableException

    prePostBootSetup

    protected void prePostBootSetup ()

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

    投擲
    DeviceNotAvailableException

    pullFileInternal

    protected boolean pullFileInternal (String remoteFilePath, 
                    File localFile)

    參數
    remoteFilePath String

    localFile File

    退貨
    boolean

    投擲
    DeviceNotAvailableException

    setClock

    protected void setClock (Clock clock)

    Set the Clock instance to use.

    參數
    clock Clock

    setLogStartDelay

    protected 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

    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.