本地設備

public interface INativeDevice

com.android.tradefed.device.INativeDevice


為 ddmlib IDevice提供可靠且級別稍高的 API。

重試設備命令可配置的次數,並為無響應的設備提供設備恢復接口。

概括

常數

int UNKNOWN_API_LEVEL

無法檢測API Level時的默認值

公共方法

abstract boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

檢查當前是否支持給定最低支持級別的功能。

abstract void clearLogcat ()

刪除所有累積的 logcat 數據。

abstract void deleteFile (String deviceFilePath)

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

abstract boolean deviceSoftRestarted ( ProcessInfo prevSystemServerProcess)

通過將當前 system_server 與以前的 system_server ProcessInfo進行比較來檢查設備是否軟重啟的幫助程序方法。

abstract boolean deviceSoftRestartedSince (long utcEpochTime, TimeUnit timeUnit)

用於檢查設備是否自 UTC 時間以來設備及其ERROR(/TimeUnit)軟重啟的方法。

abstract boolean disableAdbRoot ()

關閉 adb root。

abstract boolean doesFileExist (String deviceFilePath)

確定設備上的文件是否存在的幫助程序方法。

abstract boolean enableAdbRoot ()

打開 adb root。

abstract String executeAdbCommand (long timeout, String... commandArgs)

將 adb 命令作為具有指定超時的系統命令執行的幫助程序方法。

abstract String executeAdbCommand (String... commandArgs)

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

abstract String executeAdbCommand (long timeout, envMap, String... commandArgs) executeAdbCommand (long timeout, envMap, String... commandArgs)

將 adb 命令作為具有指定超時的系統命令執行的幫助程序方法。

abstract CommandResult executeFastbootCommand (long timeout, String... commandArgs)

將 fastboot 命令作為系統命令執行的幫助程序方法。

abstract CommandResult executeFastbootCommand (String... commandArgs)

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

abstract CommandResult executeLongFastbootCommand (String... commandArgs)

將長時間運行的 fastboot 命令作為系統命令執行的幫助程序方法。

abstract CommandResult executeLongFastbootCommand ( envVarMap, String... commandArgs) executeLongFastbootCommand ( envVarMap, String... commandArgs)

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

abstract String executeShellCommand (String command)

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

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

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

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

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

abstract void executeShellCommand (String command, IShellOutputReceiver receiver)

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

abstract CommandResult executeShellV2Command (String command)

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

abstract CommandResult executeShellV2Command (String command, OutputStream pipeToOutput)

執行 adb shell 命令並將結果作為CommandResult返回的幫助程序方法,其中正確填充了命令狀態輸出和 stderr。

abstract CommandResult executeShellV2Command (String command, File pipeAsInput)

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

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

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

abstract CommandResult executeShellV2Command (String command, long maxTimeoutForCommand, TimeUnit timeUnit)

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

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

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

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

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

abstract CommandResult fastbootWipePartition (String partition)

擦除設備分區的輔助方法。

abstract int getApiLevel ()

獲取設備 API 級別。

abstract String getBasebandVersion ()

獲取該設備的基帶(無線電)版本的便捷方法。

abstract Integer getBattery ()

返回設備的當前電池電量,如果電池電量不可用,則返回 Null。

abstract boolean getBooleanProperty (String name, boolean defaultValue)

返回給定屬性的布爾值。

abstract getBootHistory ()

Helper 方法收集帶有啟動時間和啟動原因的啟動歷史記錄圖。

abstract getBootHistorySince (long utcEpochTime, TimeUnit timeUnit)

幫助程序方法收集啟動歷史記錄圖,其中包含自設備紀元以來的給定時間和指定的時間單位以來的啟動時間和啟動原因。

abstract String getBootloaderVersion ()

獲取該設備的引導加載程序版本的便捷方法。

abstract String getBuildAlias ()

檢索設備當前正在運行的構建的別名。

abstract String getBuildFlavor ()

檢索設備的構建風格。

abstract String getBuildId ()

檢索設備當前正在運行的版本。

abstract String getBuildSigningKeys ()

返回用於簽署設備映像的密鑰類型

通常,Android 設備可以使用測試密鑰(如 AOSP 中)或發布密鑰(由各個設備製造商控制)進行簽名

abstract DeviceDescriptor getCachedDeviceDescriptor ()

如果設備已分配,則返回緩存的DeviceDescriptor ,否則返回當前的DeviceDescriptor

abstract DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

如果設備已分配,則返回緩存的DeviceDescriptor ,否則返回當前的DeviceDescriptor

abstract String[] getChildren (String deviceFilePath)

使用IFileEntry的替代方案有時由於權限問題而無法工作。

abstract AbstractConnection getConnection ()

返回與設備關聯的連接。

abstract String getDeviceClass ()

獲取設備類別。

abstract long getDeviceDate ()

返回設備的日期(自紀元以來的毫秒數)。

abstract DeviceDescriptor getDeviceDescriptor ()

從設備信息中返回DeviceDescriptor以獲取其信息,而無需傳遞實際的設備對象。

abstract DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

從設備信息中返回DeviceDescriptor以獲取其信息,而無需傳遞實際的設備對象。

abstract TestDeviceState getDeviceState ()

獲取設備的狀態。

abstract long getDeviceTimeOffset (Date date)

幫助獲取設備與給定ERROR(/Date)之間的時差。

abstract InputStreamSource getEmulatorOutput ()

獲取模擬器stdout和stderr的流

abstract long getExternalStoreFreeSpace ()

用於確定設備外部存儲上的可用空間量的幫助程序方法。

abstract String getFastbootProductType ()

當設備處於快速啟動模式時獲取該設備的產品類型的便捷方法。

abstract String getFastbootProductVariant ()

當設備處於快速啟動模式時獲取該設備的產品類型的便捷方法。

abstract String getFastbootSerialNumber ()

返回快速啟動模式序列號。

abstract String getFastbootVariable (String variableName)

從設備檢索給定的 fastboot 變量值。

abstract IFileEntry getFileEntry (String path)

檢索設備上遠程文件的引用。

abstract IDevice getIDevice ()

返回對關聯 ddmlib IDevice引用。

abstract long getIntProperty (String name, long defaultValue)

從設備返回給定屬性的整數值。

abstract long getLastExpectedRebootTimeMillis ()

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

abstract int getLaunchApiLevel ()

獲取設備首次啟動的 API 級別。

abstract InputStreamSource getLogcat ()

獲取 logcat 數據的快照流。

abstract InputStreamSource getLogcat (int maxBytes)

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

abstract InputStreamSource getLogcatDump ()

獲取設備當前 logcat 的轉儲。

abstract InputStreamSource getLogcatSince (long date)

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

abstract String getMountPoint (String mountName)

返回一個掛載點。

abstract ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

返回與指定掛載點路徑相對應的MountPointInfo ,如果該路徑沒有掛載任何內容,或者未作為掛載點出現在 /proc/mounts 中,則返回null

abstract getMountPointInfo ()

返回設備上 /proc/mounts 中信息的已解析版本

abstract long getPartitionFreeSpace (String partition)

確定設備分區上的可用空間量的幫助程序方法。

abstract ProcessInfo getProcessByName (String processName)

Helper 方法運行“pidof”和“stat”命令,並返回帶有給定進程的 PID 和進程啟動時間的ProcessInfo對象。

abstract String getProcessPid (String process)

返回服務的 pid,如果出現問題則返回 null。

abstract String getProductType ()

獲取該設備的產品類型的便捷方法。

abstract String getProductVariant ()

獲取該設備的產品變型的便捷方法。

abstract String getProperty (String name)

從設備中檢索給定的屬性值。

abstract ITestDevice.RecoveryMode getRecoveryMode ()

獲取設備當前使用的恢復模式。

abstract String getSerialNumber ()

獲取該設備序列號的便捷方法。

abstract getTombstones ()

從設備中獲取並返回邏輯刪除列表。

abstract long getTotalMemory ()

返回總物理內存大小(以字節為單位),如果出現內部錯誤,則返回 -1

abstract boolean getUseFastbootErase ()

獲取是否使用 fastboot 擦除或 fastboot 格式來擦除設備上的分區。

abstract boolean isAdbRoot ()
abstract boolean isAdbTcp ()
abstract boolean isAppEnumerationSupported ()

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

abstract boolean isBypassLowTargetSdkBlockSupported ()

檢查設備上的平台是否支持繞過應用程序安裝時的低目標 sdk 塊

abstract boolean isDeviceEncrypted ()

返回設備是否已加密。

abstract boolean isDirectory (String deviceFilePath)

如果設備上的路徑是目錄,則返回 True,否則返回 false。

abstract boolean isEncryptionSupported ()

返回設備是否支持加密。

abstract boolean isExecutable (String fullPath)

如果設備上的文件路徑是可執行文件,則返回 True,否則返回 false。

abstract boolean isHeadless ()

如果設備是無頭的(無屏幕),則返回 true,否則返回 false。

abstract boolean isRuntimePermissionSupported ()

檢查設備平台是否支持運行時權限授予

abstract boolean isStateBootloaderOrFastbootd ()

如果設備處於TestDeviceState#FASTBOOTTestDeviceState.FASTBOOTD狀態,則返回 true。

abstract boolean logAnrs ( ITestLogger logger)

從設備收集並記錄 ANR。

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

在設備的 logcat 中記錄消息。

abstract void nonBlockingReboot ()

發出重新啟動設備的命令,並在命令完成時以及設備不再對 adb 可見時返回。

abstract void postBootSetup ()

執行說明來配置設備,以便在每次啟動後進行測試。

default void postInvocationTearDown ()

此方法已被棄用。請改用postInvocationTearDown(Throwable)

abstract void postInvocationTearDown (Throwable invocationException)

設備特定所需清理的額外步驟將在調用完成後執行。

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

設備特定所需設置的額外步驟將在調用流程之前在設備上執行。

abstract boolean pullDir (String deviceFilePath, File localDir)

從設備中遞歸提取目錄內容。

abstract File pullFile (String remoteFilePath, int userId)

從設備上檢索文件,將其存儲在本地臨時ERROR(/File)中,然後返回該File

abstract File pullFile (String remoteFilePath)

從設備上檢索文件,將其存儲在本地臨時ERROR(/File)中,然後返回該File

abstract boolean pullFile (String remoteFilePath, File localFile)

從設備上檢索文件。

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

從設備上檢索文件。

abstract String pullFileContents (String remoteFilePath)

從設備上檢索文件並返回內容。

abstract File pullFileFromExternal (String remoteFilePath)

一種從設備的外部存儲檢索文件、將其存儲在本地臨時ERROR(/File)中並返回對該File的引用的便捷方法。

abstract boolean pushDir (File localDir, String deviceFilePath, excludedDirectories) pushDir (File localDir, String deviceFilePath, excludedDirectories)

將目錄內容遞歸推送到設備,同時排除一些被過濾的目錄。

abstract boolean pushDir (File localDir, String deviceFilePath)

遞歸地將目錄內容推送到設備。

abstract boolean pushFile (File localFile, String deviceFilePath, boolean evaluateContentProviderNeeded)

pushFile(File, String)的變體,可以選擇考慮評估內容提供者的需求。

abstract boolean pushFile (File localFile, String deviceFilePath)

將文件推送到設備。

abstract boolean pushString (String contents, String deviceFilePath)

將根據字符串創建的文件推送到設備

abstract void reboot ()

將設備重新啟動至 adb 模式。

abstract void reboot (String reason)

將設備重新啟動到 adb 模式,並給出在重新啟動後保留的reason

abstract void rebootIntoBootloader ()

將設備重新啟動至引導加載程序模式。

abstract void rebootIntoFastbootd ()

將設備重新啟動至 fastbootd 模式。

abstract void rebootIntoRecovery ()

將設備重新啟動至 adb 恢復模式。

abstract void rebootIntoSideload (boolean autoReboot)

重新啟動設備進入 adb sideload 模式(請注意,這是恢復下的特殊模式)

阻塞直到設備進入旁加載模式

abstract void rebootIntoSideload ()

重新啟動設備進入 adb sideload 模式(請注意,這是恢復下的特殊模式)

阻塞直到設備進入旁加載模式

abstract void rebootUntilOnline ()

reboot()的替代方法,僅在設備在線(即對 adb 可見)之前阻塞。

abstract void rebootUntilOnline (String reason)

reboot()的替代方法,僅在設備在線(即對 adb 可見)之前阻塞。

abstract void rebootUserspace ()

僅重新啟動設備的用戶空間部分。

abstract void rebootUserspaceUntilOnline ()

rebootUserspace() ()} 的替代方案,僅在設備在線(即對 adb 可見)之前阻塞。

abstract void remountSystemReadOnly ()

將設備上的系統分區設置為只讀。

abstract void remountSystemWritable ()

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

abstract void remountVendorReadOnly ()

將設備上的供應商分區設置為只讀。

abstract void remountVendorWritable ()

使設備上的供應商分區可寫。

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

使用作為參數傳遞的一個或多個偵聽器來執行ERROR(/#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection))的便捷方法。

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

運行儀器測試並提供設備恢復。

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

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

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

abstract void setDate (Date date)

設置設備上的日期

注意:在設備上設置日期需要root

abstract void setOptions ( TestDeviceOptions options)

設置設備的TestDeviceOptions

abstract boolean setProperty (String propKey, String propValue)

設置設備上給定的屬性值。

abstract void setRecovery ( IDeviceRecovery recovery)

設置用於此設備的IDeviceRecovery

abstract void setRecoveryMode ( ITestDevice.RecoveryMode mode)

設置設備使用的當前恢復模式。

abstract void setUseFastbootErase (boolean useFastbootErase)

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

abstract void startLogcat ()

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

abstract void stopEmulatorOutput ()

關閉並刪除模擬器輸出。

abstract void stopLogcat ()

停止從設備捕獲 logcat 輸出,並丟棄當前保存的 logcat 數據。

abstract String switchToAdbTcp ()

將設備切換到 adb-over-tcp 模式。

abstract boolean switchToAdbUsb ()

將設備切換到 adb over usb 模式。

abstract boolean syncFiles (File localFileDir, String deviceFilePath)

將本地文件目錄的內容增量同步到設備。

abstract boolean unlockDevice ()

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

abstract boolean waitForBootComplete (long timeOut)

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

abstract boolean waitForDeviceAvailable ()

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

abstract boolean waitForDeviceAvailable (long waitTime)

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

abstract boolean waitForDeviceAvailableInRecoverPath (long waitTime)

等待設備響應並可用,而不考慮恢復路徑。

abstract void waitForDeviceBootloader ()

阻塞直到設備通過 fastboot 可見。

abstract boolean waitForDeviceInRecovery (long waitTime)

阻止設備處於“adb recovery”狀態(請注意,這與IDeviceRecovery不同)。

abstract boolean waitForDeviceInSideload (long waitTime)

阻止設備處於“adb sideload”狀態

abstract boolean waitForDeviceNotAvailable (long waitTime)

設備不可用的塊,即 adb 中丟失的塊

abstract void waitForDeviceOnline ()

阻塞直到設備通過 adb 可見。

abstract void waitForDeviceOnline (long waitTime)

阻塞直到設備通過 adb 可見。

abstract boolean waitForDeviceShell (long waitTime)

等待設備響應基本的 adb shell 命令。

常數

UNKNOWN_API_LEVEL

public static final int UNKNOWN_API_LEVEL

無法檢測API Level時的默認值

常量值:-1 (0xffffffff)

公共方法

檢查 ApiLevelAgainstNextRelease

public abstract boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

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

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

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

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

清除Logcat

public abstract void clearLogcat ()

刪除所有累積的 logcat 數據。

當您想要確保ITestDevice#getLogcat()僅返回在某個點之後(例如刷新新設備版本後等)生成的日誌數據時,這非常有用。

刪除文件

public abstract void deleteFile (String deviceFilePath)

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

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

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

設備軟重啟

public abstract boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

通過將當前 system_server 與以前的 system_server ProcessInfo進行比較來檢查設備是否軟重啟的幫助程序方法。使用getProcessByName(String)獲取ProcessInfo

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

退貨
boolean如果設備軟重啟true

投擲
RuntimeException如果設備有異常啟動原因
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

設備軟重啟以來

public abstract boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

用於檢查設備是否自 UTC 時間以來設備及其ERROR(/TimeUnit)軟重啟的方法。軟重啟是指在設備硬重啟之外重新啟動的 system_server(例如:請求重啟)。可以通過getDeviceDate()方法獲取當前設備的 utcEpochTime(以毫秒為單位)。

參數
utcEpochTime long :自紀元以來的設備時間(以秒為單位)。

timeUnit TimeUnit :給定 utcEpochTime 的時間單位TimeUnit

退貨
boolean如果設備軟重啟true

投擲
RuntimeException如果設備有異常啟動原因
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

禁用AdbRoot

public abstract boolean disableAdbRoot ()

關閉 adb root。

禁用 adb root 可能會導致設備與 adb 斷開連接。此方法將阻塞,直到設備可用。

退貨
boolean如果成功則為true

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

文件是否存在

public abstract boolean doesFileExist (String deviceFilePath)

確定設備上的文件是否存在的幫助程序方法。

參數
deviceFilePath String : 要檢查的設備上文件的絕對路徑

退貨
boolean如果文件存在true ,否則為false

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

啟用AdbRoot

public abstract boolean enableAdbRoot ()

打開 adb root。如果“enable-root”設置為“false”,將記錄一條消息並返回而不啟用 root。

啟用 adb root 可能會導致設備與 adb 斷開連接。此方法將阻塞,直到設備可用。

退貨
boolean如果成功則為true

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Adb命令

public abstract String executeAdbCommand (long timeout, 
                String... commandArgs)

將 adb 命令作為具有指定超時的系統命令執行的幫助程序方法。

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

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

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

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

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Adb命令

public abstract String executeAdbCommand (String... commandArgs)

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

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

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

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

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Adb命令

public abstract String executeAdbCommand (long timeout, 
                 envMap, 
                String... commandArgs)

將 adb 命令作為具有指定超時的系統命令執行的幫助程序方法。

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

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

envMap :為命令設置的環境

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

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

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Fastboot命令

public abstract CommandResult executeFastbootCommand (long timeout, 
                String... commandArgs)

將 fastboot 命令作為系統命令執行的幫助程序方法。

預計在設備已處於快速啟動模式時使用。

參數
timeout long :命令過期前的時間(以毫秒為單位)

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

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Fastboot命令

public abstract CommandResult executeFastbootCommand (String... commandArgs)

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

預計在設備已處於快速啟動模式時使用。

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

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行LongFastboot命令

public abstract CommandResult executeLongFastbootCommand (String... commandArgs)

將長時間運行的 fastboot 命令作為系統命令執行的幫助程序方法。

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

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

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行LongFastboot命令

public abstract CommandResult executeLongFastbootCommand ( envVarMap, 
                String... commandArgs)

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

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

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

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

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Shell命令

public abstract String executeShellCommand (String command)

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

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

退貨
String外殼輸出

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行Shell命令

public abstract 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如果與設備的連接丟失且無法恢復。

執行Shell命令

public abstract 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如果與設備的連接丟失且無法恢復。

執行Shell命令

public abstract 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 abstract CommandResult executeShellV2Command (String command)

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

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

退貨
CommandResult結果在CommandResult中。

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

public abstract CommandResult executeShellV2Command (String command, 
                OutputStream pipeToOutput)

執行 adb shell 命令並將結果作為CommandResult返回的幫助程序方法,其中正確填充了命令狀態輸出和 stderr。 stdout 定向到指定的流。

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

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

退貨
CommandResult結果在CommandResult中。

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput)

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

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

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

退貨
CommandResult結果在CommandResult中。

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

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

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

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

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

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

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

退貨
CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

public abstract CommandResult executeShellV2Command (String command, 
                long maxTimeoutForCommand, 
                TimeUnit timeUnit)

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

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

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

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

退貨
CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

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

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

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

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

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

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

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

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

退貨
CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

執行ShellV2命令

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

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

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

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

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

pipeToError OutputStream : ERROR(/OutputStream)其中 std 錯誤將被重定向,或者為 null。

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

timeUnit TimeUnit : maxTimeToOutputShellResponse的單位

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

退貨
CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

fastboot擦除分區

public abstract CommandResult fastbootWipePartition (String partition)

擦除設備分區的輔助方法。

如果getUseFastbootErase()true ,則將使用 fastboot Erase 來擦除分區。然後,設備必須在下次啟動時創建文件系統。否則,將使用 fastboot 格式,這將在設備上創建新的文件系統。

預計在設備已處於快速啟動模式時使用。

參數
partition String : 要擦除的分區

退貨
CommandResult包含命令輸出的 CommandResult

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取API級別

public abstract int getApiLevel ()

獲取設備 API 級別。默認為UNKNOWN_API_LEVEL

退貨
int指示設備 API 級別的整數

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取基帶版本

public abstract String getBasebandVersion ()

獲取該設備的基帶(無線電)版本的便捷方法。獲取無線電版本是特定於設備的,因此它可能無法返回所有設備的正確信息。此方法依賴 gsm.version.baseband 屬性來返回正確的版本信息。這對於某些 CDMA 設備來說並不准確,並且此處返回的版本可能與 fastboot 報告的版本不匹配,並且可能不會返回 CDMA 無線電的版本。 TL;DR 如果 gsm.version.baseband 屬性與fastboot getvar version-baseband返回的版本相同,則此方法僅報告準確的版本。

退貨
String String基帶版本,如果無法確定則為null (設備沒有無線電或無法讀取版本字符串)

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取電池

public abstract Integer getBattery ()

返回設備的當前電池電量,如果電池電量不可用,則返回 Null。

退貨
Integer

獲取布爾屬性

public abstract boolean getBooleanProperty (String name, 
                boolean defaultValue)

返回給定屬性的布爾值。

參數
name String : 屬性名稱

defaultValue boolean :如果屬性為空或不存在,則返回默認值。

退貨
boolean如果屬性值為"1""y""yes""on""true" ,則為true ;如果屬性值為"0""n""no""off" ,則為false"false" ,否則為defaultValue

投擲
DeviceNotAvailableException

獲取啟動歷史記錄

public abstract  getBootHistory ()

Helper 方法收集帶有啟動時間和啟動原因的啟動歷史記錄圖。

退貨
啟動時間圖(自紀元以來以秒為單位的 UTC 時間)和啟動原因

投擲
DeviceNotAvailableException

獲取啟動歷史記錄

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

幫助程序方法收集啟動歷史記錄圖,其中包含自設備紀元以來的給定時間和指定的時間單位以來的啟動時間和啟動原因。當前設備的 utcEpochTime(以毫秒為單位)可以通過方法getDeviceDate()獲取。

參數
utcEpochTime long :自 Epoch 以來的設備時間。

timeUnit TimeUnit :時間單位TimeUnit

退貨
啟動時間圖(自紀元以來以秒為單位的 UTC 時間)和啟動原因

投擲
DeviceNotAvailableException

獲取Bootloader版本

public abstract String getBootloaderVersion ()

獲取該設備的引導加載程序版本的便捷方法。

將嘗試從設備的當前狀態檢索引導加載程序版本。 (即如果設備處於快速啟動模式,它將嘗試從快速啟動檢索版本)

退貨
String String引導加載程序版本,如果找不到則為null

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取構建別名

public abstract String getBuildAlias ()

檢索設備當前正在運行的構建的別名。

構建別名通常是比構建 ID(通常是 Nexus 構建的數字)更可讀的字符串。例如,最終的 Android 4.2 版本的構建別名為 JDQ39,構建 ID 為 573038

退貨
String構建別名或如果無法檢索則回退到構建 ID

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取BuildFlavor

public abstract String getBuildFlavor ()

檢索設備的構建風格。

退貨
String構建風格,如果無法檢索則為 null

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取構建ID

public abstract String getBuildId ()

檢索設備當前正在運行的版本。

退貨
String構建 ID 或IBuildInfo#UNKNOWN_BUILD_ID (如果無法檢索)

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取構建簽名密鑰

public abstract String getBuildSigningKeys ()

返回用於簽署設備映像的密鑰類型

通常,Android 設備可以使用測試密鑰(如 AOSP 中)或發布密鑰(由各個設備製造商控制)進行簽名

退貨
String如果找到則為簽名密鑰,否則為 null。

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取緩存設備描述符

public abstract DeviceDescriptor getCachedDeviceDescriptor ()

如果設備已分配,則返回緩存的DeviceDescriptor ,否則返回當前的DeviceDescriptor

退貨
DeviceDescriptor

獲取緩存設備描述符

public abstract DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

如果設備已分配,則返回緩存的DeviceDescriptor ,否則返回當前的DeviceDescriptor

參數
shortDescriptor boolean :是否將描述符限制為最低限度的信息

退貨
DeviceDescriptor

獲取孩子

public abstract String[] getChildren (String deviceFilePath)

使用IFileEntry的替代方案有時由於權限問題而無法工作。

參數
deviceFilePath String :是設備上進行搜索的路徑

退貨
String[]包含設備上路徑中的所有文件的字符串數組。

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取連接

public abstract AbstractConnection getConnection ()

返回與設備關聯的連接。

退貨
AbstractConnection

獲取設備類

public abstract String getDeviceClass ()

獲取設備類別。

退貨
String String設備類。

獲取設備日期

public abstract long getDeviceDate ()

返回設備的日期(自紀元以來的毫秒數)。

退貨
long設備的日期(紀元格式)。

投擲
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

獲取設備描述符

public abstract DeviceDescriptor getDeviceDescriptor ()

從設備信息中返回DeviceDescriptor以獲取其信息,而無需傳遞實際的設備對象。

退貨
DeviceDescriptor

獲取設備描述符

public abstract DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

從設備信息中返回DeviceDescriptor以獲取其信息,而無需傳遞實際的設備對象。

參數
shortDescriptor boolean :是否將描述符限制為最低限度的信息

退貨
DeviceDescriptor

獲取設備狀態

public abstract TestDeviceState getDeviceState ()

獲取設備的狀態。

退貨
TestDeviceState

獲取設備時間偏移

public abstract long getDeviceTimeOffset (Date date)

幫助獲取設備與給定ERROR(/Date)之間的時差。內部使用紀元時間。

參數
date Date

退貨
long以毫秒為單位的差異

投擲
DeviceNotAvailableException

獲取模擬器輸出

public abstract InputStreamSource getEmulatorOutput ()

獲取模擬器stdout和stderr的流

退貨
InputStreamSource仿真器輸出

獲取外部存儲可用空間

public abstract long getExternalStoreFreeSpace ()

用於確定設備外部存儲上的可用空間量的幫助程序方法。

退貨
long可用空間量(以 KB 為單位)

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取FastbootProductType

public abstract String getFastbootProductType ()

當設備處於快速啟動模式時獲取該設備的產品類型的便捷方法。

僅當設備處於快速啟動狀態時才應使用此方法。在這種情況下,它比通用getProductType()方法更安全一些,因為如果設備處於不正確狀態或無響應,ITestDevice 會知道將設備恢復到快速啟動。

退貨
String String產品類型名稱,如果無法確定則為null

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取FastbootProductVariant

public abstract String getFastbootProductVariant ()

當設備處於快速啟動模式時獲取該設備的產品類型的便捷方法。

僅當設備處於快速啟動狀態時才應使用此方法。在這種情況下,它比通用getProductType()方法更安全一些,因為如果設備處於不正確狀態或無響應,ITestDevice 會知道將設備恢復到快速啟動。

退貨
String String產品類型名稱,如果無法確定則為null

投擲
DeviceNotAvailableException如果與設備的連接丟失且無法恢復。

獲取Fastboot序列號

public abstract String getFastbootSerialNumber ()

返回快速啟動模式序列號。

退貨
String

獲取Fastboot變量

public abstract String getFastbootVariable (String variableName)

從設備檢索給定的 fastboot 變量值。

參數
variableName String :變量名

退貨
String屬性值,如果不存在則為null

投擲
不支持的操作異常
DeviceNotAvailableException

getFileEntry

public abstract IFileEntry getFileEntry (String path)

Retrieve a reference to a remote file on device.

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

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

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getIDevice

public abstract 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.

Returns
IDevice the IDevice

getIntProperty

public abstract long getIntProperty (String name, 
                long defaultValue)

Returns integer value of the given property from the device.

Parameters
name String : the property name

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

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

Throws
DeviceNotAvailableException

getLastExpectedRebootTimeMillis

public abstract long getLastExpectedRebootTimeMillis ()

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

Returns
long

getLaunchApiLevel

public abstract int getLaunchApiLevel ()

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

Returns
int an integer indicating the first launched API Level of device

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getLogcat

public abstract 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

    Returns
    InputStreamSource

  • getLogcat

    public abstract 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.

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

    Returns
    InputStreamSource

    getLogcatDump

    public abstract 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.

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

    getLogcatSince

    public abstract 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() .

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

    Returns
    InputStreamSource

    getMountPoint

    public abstract 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)

    Parameters
    mountName String : the name of the mount point

    Returns
    String the mount point or null

    getMountPointInfo

    public abstract 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.

    Parameters
    mountpoint String

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

    Throws
    DeviceNotAvailableException

    getMountPointInfo

    public abstract  getMountPointInfo ()

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

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

    Throws
    DeviceNotAvailableException

    getPartitionFreeSpace

    public abstract long getPartitionFreeSpace (String partition)

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

    Parameters
    partition String

    Returns
    long the amount of free space in KB

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    getProcessByName

    public abstract 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.

    Parameters
    processName String : the proces name String.

    Returns
    ProcessInfo ProcessInfo of given processName

    Throws
    DeviceNotAvailableException

    getProcessPid

    public abstract String getProcessPid (String process)

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

    Parameters
    process String : The proces name String.

    Returns
    String

    Throws
    DeviceNotAvailableException

    getProductType

    public abstract 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.

    Returns
    String the String product type name. Will not be null

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered, or if product type can not be determined

    getProductVariant

    public abstract 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.

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    getProperty

    public abstract String getProperty (String name)

    Retrieve the given property value from the device.

    Parameters
    name String : the property name

    Returns
    String the property value or null if it does not exist

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    getRecoveryMode

    public abstract ITestDevice.RecoveryMode getRecoveryMode ()

    Get the current recovery mode used for the device.

    Returns
    ITestDevice.RecoveryMode the current recovery mode used for the device.

    getSerialNumber

    public abstract String getSerialNumber ()

    Convenience method to get serial number of this device.

    Returns
    String the String serial number

    getTombstones

    public abstract  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.

    Returns
    A list of tombstone files, empty if no tombstone.

    Throws
    DeviceNotAvailableException

    getTotalMemory

    public abstract long getTotalMemory ()

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

    Returns
    long

    getUseFastbootErase

    public abstract boolean getUseFastbootErase ()

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

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

    isAdbRoot

    public abstract boolean isAdbRoot ()

    Returns
    boolean true if device currently has adb root, false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    isAdbTcp

    public abstract boolean isAdbTcp ()

    Returns
    boolean true if device is connected to adb-over-tcp, false otherwise.

    isAppEnumerationSupported

    public abstract boolean isAppEnumerationSupported ()

    Check whether platform on device supports app enumeration

    Returns
    boolean True if app enumeration is supported, false otherwise

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isBypassLowTargetSdkBlockSupported

    public abstract boolean isBypassLowTargetSdkBlockSupported ()

    Check whether platform on device supports bypassing low target sdk block on app installs

    Returns
    boolean True if bypass low target sdk block is supported, false otherwise

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isDeviceEncrypted

    public abstract boolean isDeviceEncrypted ()

    Returns if the device is encrypted.

    Returns
    boolean true if the device is encrypted.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    isDirectory

    public abstract boolean isDirectory (String deviceFilePath)

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

    Parameters
    deviceFilePath String

    Returns
    boolean

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isEncryptionSupported

    public abstract boolean isEncryptionSupported ()

    Returns if encryption is supported on the device.

    Returns
    boolean true if the device supports encryption.

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isExecutable

    public abstract boolean isExecutable (String fullPath)

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

    Parameters
    fullPath String

    Returns
    boolean

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isHeadless

    public abstract boolean isHeadless ()

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

    Returns
    boolean

    Throws
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public abstract boolean isRuntimePermissionSupported ()

    Check whether platform on device supports runtime permission granting

    Returns
    boolean True if runtime permission are supported, false otherwise.

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public abstract boolean isStateBootloaderOrFastbootd ()

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

    Returns
    boolean

    logAnrs

    public abstract boolean logAnrs (ITestLogger logger)

    Collects and log ANRs from the device.

    Parameters
    logger ITestLogger : an ITestLogger to log the ANRs.

    Returns
    boolean True if the logging was successful, false otherwise.

    Throws
    DeviceNotAvailableException

    logOnDevice

    public abstract 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.

    Parameters
    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 abstract void nonBlockingReboot ()

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    postBootSetup

    public abstract 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)

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    postInvocationTearDown

    public void postInvocationTearDown ()

    This method is deprecated.
    Use postInvocationTearDown(Throwable) instead.

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

    postInvocationTearDown

    public abstract void postInvocationTearDown (Throwable invocationException)

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

    Parameters
    invocationException 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.

    Parameters
    info IBuildInfo : The IBuildInfo of the device.

    attributes MultiMap : The attributes stored in the invocation context

    Throws
    com.android.tradefed.targetprep.TargetSetupError
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException
    TargetSetupError

    pullDir

    public abstract boolean pullDir (String deviceFilePath, 
                    File localDir)

    Recursively pull directory contents from device.

    Parameters
    deviceFilePath String : the absolute file path of the remote source

    localDir File : the local directory to pull files into

    Returns
    boolean true if file was pulled successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pullFile

    public abstract File pullFile (String remoteFilePath, 
                    int userId)

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

    Parameters
    remoteFilePath String : the absolute path to file on device.

    userId int : The user id to pull from

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pullFile

    public abstract File pullFile (String remoteFilePath)

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

    Parameters
    remoteFilePath String : the absolute path to file on device.

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pullFile

    public abstract boolean pullFile (String remoteFilePath, 
                    File localFile)

    Retrieves a file off device.

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

    Returns
    boolean true if file was retrieved successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pullFile

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

    Retrieves a file off device.

    Parameters
    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

    Returns
    boolean true if file was retrieved successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pullFileContents

    public abstract String pullFileContents (String remoteFilePath)

    Retrieves a file off device, and returns the contents.

    Parameters
    remoteFilePath String : the absolute path to file on device.

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

    Throws
    DeviceNotAvailableException

    pullFileFromExternal

    public abstract 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 .

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

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pushDir

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath, 
                     excludedDirectories)

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

    Parameters
    localDir 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.

    Returns
    boolean true if file was pushed successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pushDir

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath)

    Recursively push directory contents to device.

    Parameters
    localDir File : the local directory to push

    deviceFilePath String : the absolute file path of the remote destination

    Returns
    boolean true if file was pushed successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath, 
                    boolean evaluateContentProviderNeeded)

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

    Parameters
    localFile File : the local file to push

    deviceFilePath String : the remote destination absolute file path

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

    Returns
    boolean true if file was pushed successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath)

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

    Parameters
    localFile File : the local file to push

    deviceFilePath String : the remote destination absolute file path

    Returns
    boolean true if file was pushed successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    pushString

    public abstract boolean pushString (String contents, 
                    String deviceFilePath)

    Push file created from a string to device

    Parameters
    contents String : the contents of the file to push

    deviceFilePath String : the remote destination absolute file path

    Returns
    boolean true if string was pushed successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    reboot

    public abstract void reboot ()

    Reboots the device into adb mode.

    Blocks until device becomes available.

    Throws
    DeviceNotAvailableException if device is not available after reboot

    reboot

    public abstract 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.

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

    Throws
    DeviceNotAvailableException if device is not available after reboot

    rebootIntoBootloader

    public abstract void rebootIntoBootloader ()

    Reboots the device into bootloader mode.

    Blocks until device is in bootloader mode.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    rebootIntoFastbootd

    public abstract void rebootIntoFastbootd ()

    Reboots the device into fastbootd mode.

    Blocks until device is in fastbootd mode.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    rebootIntoRecovery

    public abstract void rebootIntoRecovery ()

    Reboots the device into adb recovery mode.

    Blocks until device enters recovery

    Throws
    DeviceNotAvailableException if device is not available after reboot

    rebootIntoSideload

    public abstract 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

    Parameters
    autoReboot boolean : whether to automatically reboot the device after sideload

    Throws
    DeviceNotAvailableException if device is not in sideload after reboot

    rebootIntoSideload

    public abstract void rebootIntoSideload ()

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

    Blocks until device enters sideload mode

    Throws
    DeviceNotAvailableException if device is not in sideload after reboot

    rebootUntilOnline

    public abstract void rebootUntilOnline ()

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

    Throws
    DeviceNotAvailableException if device is not available after reboot

    rebootUntilOnline

    public abstract void rebootUntilOnline (String reason)

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

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

    Throws
    DeviceNotAvailableException if device is not available after reboot

    See also:

    rebootUserspace

    public abstract 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.

    Throws
    DeviceNotAvailableException if device is not available after reboot

    rebootUserspaceUntilOnline

    public abstract void rebootUserspaceUntilOnline ()

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

    Throws
    DeviceNotAvailableException if device is not available after reboot

    remountSystemReadOnly

    public abstract void remountSystemReadOnly ()

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountSystemWritable

    public abstract void remountSystemWritable ()

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountVendorReadOnly

    public abstract void remountVendorReadOnly ()

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountVendorWritable

    public abstract void remountVendorWritable ()

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    runInstrumentationTests

    public abstract 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.

    Parameters
    runner IRemoteAndroidTestRunner : the IRemoteAndroidTestRunner which runs the tests

    listeners ITestLifeCycleReceiver : the test result listener(s)

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered. ie test command failed to complete and recovery failed.

    runInstrumentationTests

    public abstract 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.

    Parameters
    runner IRemoteAndroidTestRunner : the IRemoteAndroidTestRunner which runs the tests

    listeners : the test result listeners

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered. ie test command failed to complete and recovery failed.

    runInstrumentationTestsAsUser

    public abstract 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.

    Parameters
    runner IRemoteAndroidTestRunner

    userId int

    listeners

    Returns
    boolean

    Throws
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

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

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

    Parameters
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    Returns
    boolean

    Throws
    DeviceNotAvailableException

    setDate

    public abstract void setDate (Date date)

    Sets the date on device

    Note: setting date on device requires root

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setOptions

    public abstract void setOptions (TestDeviceOptions options)

    Set the TestDeviceOptions for the device

    Parameters
    options TestDeviceOptions

    setProperty

    public abstract boolean setProperty (String propKey, 
                    String propValue)

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

    Parameters
    propKey String : The key targeted to be set.

    propValue String : The property value to be set.

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setRecovery

    public abstract void setRecovery (IDeviceRecovery recovery)

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

    Parameters
    recovery IDeviceRecovery : the IDeviceRecovery

    setRecoveryMode

    public abstract 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

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

    setUseFastbootErase

    public abstract void setUseFastbootErase (boolean useFastbootErase)

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

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

    startLogcat

    public abstract 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.

    stopEmulatorOutput

    public abstract void stopEmulatorOutput ()

    Close and delete the emulator output.

    stopLogcat

    public abstract 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.

    switchToAdbTcp

    public abstract String switchToAdbTcp ()

    Switch device to adb-over-tcp mode.

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    switchToAdbUsb

    public abstract boolean switchToAdbUsb ()

    Switch device to adb over usb mode.

    Returns
    boolean true if switch was successful, false otherwise.

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    syncFiles

    public abstract 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.

    Parameters
    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

    Returns
    boolean true if files were synced successfully. false otherwise.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    unlockDevice

    public abstract 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.

    Returns
    boolean true if successful or if the device is unencrypted.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.
    UnsupportedOperationException if encryption is not supported on the device.

    waitForBootComplete

    public abstract boolean waitForBootComplete (long timeOut)

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

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

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

    Throws
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable ()

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

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable (long waitTime)

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

    Parameters
    waitTime long : the time in ms to wait

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

    Throws
    DeviceNotAvailableException if device is still unresponsive after waitTime expires.

    waitForDeviceAvailableInRecoverPath

    public abstract boolean waitForDeviceAvailableInRecoverPath (long waitTime)

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

    Parameters
    waitTime long

    Returns
    boolean True if device is available, False if unavailable.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    waitForDeviceBootloader

    public abstract void waitForDeviceBootloader ()

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

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    waitForDeviceInRecovery

    public abstract boolean waitForDeviceInRecovery (long waitTime)

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

    Parameters
    waitTime long : the time in ms to wait

    Returns
    boolean true if device boots into recovery before time expires. false otherwise

    waitForDeviceInSideload

    public abstract boolean waitForDeviceInSideload (long waitTime)

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

    Parameters
    waitTime long : the time in ms to wait

    Returns
    boolean true if device boots into sideload before time expires. false otherwise

    waitForDeviceNotAvailable

    public abstract boolean waitForDeviceNotAvailable (long waitTime)

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

    Parameters
    waitTime long : the time in ms to wait

    Returns
    boolean true if device becomes not available before time expires. false otherwise

    waitForDeviceOnline

    public abstract 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.

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    waitForDeviceOnline

    public abstract 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.

    Parameters
    waitTime long : the time in ms to wait

    Throws
    DeviceNotAvailableException if connection with device is lost and cannot be recovered.

    waitForDeviceShell

    public abstract boolean waitForDeviceShell (long waitTime)

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

    Parameters
    waitTime long : the time in ms to wait

    Returns
    boolean true if device becomes responsive before waitTime elapses.