INativeDevice

public interface INativeDevice

com.android.tradefed.device.INativeDevice


提供可靠且稍高層級的 API 給 ddmlib IDevice

可設定裝置指令的重試次數,並為沒有回應的裝置提供裝置復原介面。

摘要

常數

int UNKNOWN_API_LEVEL

無法偵測 API 級別時的預設值

公用方法

abstract boolean checkApiLevelAgainstNextRelease(int strictMinLevel)

根據最低支援等級,檢查目前是否支援某項功能。

abstract void clearLogcat()

刪除所有累積的 logcat 資料。

abstract void deleteFile(String deviceFilePath)

輔助方法,用於刪除裝置上的檔案或目錄。

abstract void deleteFile(String deviceFilePath, int userId)

輔助方法,用於刪除裝置上的檔案或目錄。

abstract boolean deviceSoftRestarted(ProcessInfo prevSystemServerProcess)

Helper method to check if device soft-restarted by comparing current system_server with previous system_server ProcessInfo.

abstract boolean deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)

輔助方法,用於檢查裝置是否自 Epoch 紀元時間起算 (採用世界標準時間) 重新啟動,以及裝置的 ERROR(/TimeUnit)

abstract boolean disableAdbRoot()

關閉 adb 根層級存取權。

abstract boolean doesFileExist(String deviceFilePath)

輔助方法,用於判斷裝置上是否有檔案。

abstract boolean enableAdbRoot()

開啟 adb 根層級存取權。

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

Helper method which executes a adb command as a system command with a specified timeout.

abstract String executeAdbCommand(String... commandArgs)

輔助方法,可將 adb 指令做為系統指令執行。

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

Helper method which executes a adb command as a system command with a specified timeout.

abstract CommandResult executeAdbV2Command(long timeout, envMap, String... commandArgs)

Helper method which executes a adb command as a system command with a specified timeout.

abstract CommandResult executeAdbV2Command(String... commandArgs)

輔助方法,可將 adb 指令做為系統指令執行。

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

Helper method which executes a adb command as a system command with a specified timeout.

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)

Helper method which executes a long running fastboot command as a system command with system environment variables.

abstract String executeShellCommand(String command)

這個輔助方法會執行 adb shell 指令,並以 String 形式傳回輸出內容。

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 指令,並以指令狀態輸出、stdout 和 stderr 正確填入的內容,將結果做為 CommandResult 傳回。

abstract CommandResult executeShellV2Command(String command, OutputStream pipeToOutput)

輔助方法,可執行 adb shell 指令,並以指令狀態輸出和 stderr 正確填入 CommandResult,然後傳回結果。

abstract CommandResult executeShellV2Command(String command, File pipeAsInput)

輔助方法,可執行 adb shell 指令,並以指令狀態輸出、stdout 和 stderr 正確填入的 CommandResult 形式傳回結果。

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

Convenience method to get baseband (radio) version of this device.

abstract Integer getBattery()

傳回裝置目前的電池電量,如果無法取得電池電量,則傳回 Null。

abstract boolean getBooleanProperty(String name, boolean defaultValue)

傳回指定屬性的布林值。

abstract getBootHistory()

輔助方法會收集啟動時間和啟動原因的啟動記錄地圖。

abstract getBootHistorySince(long utcEpochTime, TimeUnit timeUnit)

輔助方法會從裝置收集自指定時間 (自 Epoch 以來) 的啟動記錄地圖,包括啟動時間和啟動原因,以及指定的時間單位。

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

傳回裝置日期 (以 Epoch 紀元時間起算的毫秒數表示)。

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

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

abstract String getFastbootProductType()

在快速啟動模式下取得裝置產品類型的便利方法。

abstract String getFastbootProductVariant()

在快速啟動模式下取得裝置產品類型的便利方法。

abstract String getFastbootSerialNumber()

傳回快速啟動模式序號。

abstract String getFastbootVariable(String variableName)

從裝置擷取指定的快速啟動變數值。

abstract IFileEntry getFileEntry(String path)

在裝置上擷取遠端檔案的參照。

abstract IDevice getIDevice()

傳回相關聯 ddmlib 的參照 IDevice

abstract long getIntProperty(String name, long defaultValue)

從裝置傳回指定屬性的整數值。

abstract long getLastExpectedRebootTimeMillis()

傳回 Tradefed API 上次觸發重新啟動的時間,以自 EPOCH 起算的毫秒數表示,如 System.currentTimeMillis() 傳回的值。

abstract int getLaunchApiLevel()

取得裝置首次啟用的 API 級別。

abstract InputStreamSource getLogcat()

擷取 logcat 資料的快照串流。

abstract InputStreamSource getLogcat(int maxBytes)

擷取最近 maxBytes 擷取的 logcat 資料快照串流。

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)

輔助方法會執行「pidof」和「stat」指令,並傳回 ProcessInfo 物件,其中包含指定程序的 PID 和程序啟動時間。

abstract String getProcessPid(String process)

如果發生錯誤,則傳回服務的 PID 或 null。

abstract String getProductType()

Convenience method to get the product type of this device.

abstract String getProductVariant()

取得這部裝置產品子類的便利方法。

abstract String getProperty(String name)

從裝置擷取指定屬性值。

abstract ITestDevice.RecoveryMode getRecoveryMode()

取得裝置目前使用的復原模式。

abstract String getSerialNumber()

取得這部裝置序號的便利方法。

abstract getTombstones()

從裝置擷取並傳回墓碑清單。

abstract long getTotalMemory()

以位元組為單位傳回實體記憶體總大小,或在發生內部錯誤時傳回 -1

default String getTrackingSerial()

為方便管理裝置,請取得用於追蹤裝置的序號。

abstract boolean getUseFastbootErase()

取得是否使用 fastboot erase 或 fastboot format 抹除裝置上的分區。

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

檢查裝置上的平台是否支援應用程式列舉

abstract boolean isBypassLowTargetSdkBlockSupported()

檢查裝置上的平台是否支援略過應用程式安裝時的低目標 SDK 封鎖

abstract boolean isDebugfsMounted()

檢查 debugfs 是否已掛接。

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

掛接 debugfs。

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 boolean pullDir(String deviceFilePath, File localDir, int userId)

從裝置以遞迴方式提取目錄內容。

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

將目錄內容遞迴推送至裝置。

abstract boolean 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 pushFile(File localFile, String deviceFilePath, int userId)

將檔案推送至裝置。

abstract boolean pushString(String contents, String deviceFilePath)

將從字串建立的檔案推送至裝置

abstract void reboot()

將裝置重新啟動為 adb 模式。

abstract void reboot(String reason)

以指定的 reason 重新啟動裝置,進入 adb 模式,並在重新啟動後保留該模式。

abstract void rebootIntoBootloader()

將裝置重新啟動為系統啟動載入程式模式。

abstract void rebootIntoFastbootd()

將裝置重新啟動為 fastbootd 模式。

abstract void rebootIntoRecovery()

將裝置重新啟動為 adb 復原模式。

abstract void rebootIntoSideload(boolean autoReboot)

將裝置重新啟動為 adb 側載模式 (請注意,這是復原模式下的特殊模式)

Blocks until device enters sideload mode

abstract void rebootIntoSideload()

將裝置重新啟動為 adb 側載模式 (請注意,這是復原模式下的特殊模式)

Blocks until device enters sideload mode

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)

執行檢測設備測試,並提供裝置復原功能。

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

在裝置上設定日期

注意:在裝置上設定日期需要根存取權

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 setTrackingSerial(String trackingSerial)

為方便管理裝置,請追蹤我們用來參照裝置的序號。

abstract void setUseFastbootErase(boolean useFastbootErase)

設定是否要使用 fastboot erase 或 fastboot format 抹除裝置上的分割區。

abstract void startLogcat()

在背景中開始擷取裝置的 logcat 輸出內容。

abstract boolean startTradeInModeTesting(int timeoutMs)

啟用測試換購模式。

abstract void stopEmulatorOutput()

關閉並刪除模擬器輸出內容。

abstract void stopLogcat()

停止從裝置擷取 logcat 輸出內容,並捨棄目前儲存的 logcat 資料。

abstract void stopTradeInModeTesting()

停止測試換購模式。

abstract String switchToAdbTcp()

將裝置切換為 adb-over-tcp 模式。

abstract boolean switchToAdbUsb()

將裝置切換為透過 USB 進行 adb 的模式。

abstract boolean syncFiles(File localFileDir, String deviceFilePath)

將本機檔案目錄的內容逐步同步至裝置。

abstract boolean unlockDevice()

如果裝置處於加密狀態,則解鎖裝置。

abstract void unmountDebugfs()

卸載 debugfs。

abstract boolean waitForBootComplete(long timeOut)

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

abstract boolean waitForDeviceAvailable()

等待裝置回應並可供測試。

abstract boolean waitForDeviceAvailable(long waitTime)

等待裝置回應並可供測試。

abstract boolean waitForDeviceAvailableInRecoverPath(long waitTime)

等待裝置回應並可供使用,不考慮復原路徑。

abstract void waitForDeviceBootloader()

Blocks until device is visible via 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()

Blocks until device is visible via adb.

abstract void waitForDeviceOnline(long waitTime)

Blocks until device is visible via adb.

abstract boolean waitForDeviceShell(long waitTime)

等待裝置回應基本 adb 殼層指令。

常數

UNKNOWN_API_LEVEL

public static final int UNKNOWN_API_LEVEL

無法偵測 API 級別時的預設值

常數值: -1 (0xffffffff)

公用方法

checkApiLevelAgainstNextRelease

public abstract boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

請確認目前是否支援某項功能,因為支援的最低層級可能有所不同。在 API 級別提高之前,這個方法會將尚未發布的功能納入考量。

參數
strictMinLevel int:支援這項功能的最低可能等級。

傳回
boolean 如果支援該層級,則為 True。否則傳回「false」。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

clearLogcat

public abstract void clearLogcat ()

刪除所有累積的 logcat 資料。

如果您想確保 ITestDevice.getLogcat()只會傳回特定時間點之後產生的記錄資料 (例如在刷入新的裝置版本後),這個方法就非常實用。

deleteFile

public abstract void deleteFile (String deviceFilePath)

在裝置上刪除檔案或目錄的輔助方法。

參數
deviceFilePath String:裝置上檔案的絕對路徑。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

deleteFile

public abstract void deleteFile (String deviceFilePath, 
                int userId)

在裝置上刪除檔案或目錄的輔助方法。

參數
deviceFilePath String:裝置上檔案的絕對路徑。

userId int:要從中刪除的使用者 ID

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

deviceSoftRestarted

public abstract boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)

Helper method to check if device soft-restarted by comparing current system_server with previous system_server ProcessInfo. 使用 getProcessByName(String) 可在首次付款獲得 ProcessInfo

參數
prevSystemServerProcess ProcessInfo:先前的 system_server 程序 ProcessInfo

傳回
boolean true 如果裝置已軟重新啟動

擲回
RuntimeException 裝置啟動原因異常
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

deviceSoftRestartedSince

public abstract boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

輔助方法:檢查裝置是否自 Epoch 紀元時間起算 (採用世界標準時間) 軟重啟,以及裝置的 ERROR(/TimeUnit)。軟重新啟動是指在裝置強制重新啟動以外的情況下重新啟動 system_server (例如:要求重新啟動)。您可以使用 getDeviceDate() 方法,取得目前裝置的 utcEpochTime (以毫秒為單位)。

參數
utcEpochTime long:裝置時間,以紀元後秒數為單位。

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

傳回
boolean true 如果裝置已軟重新啟動

擲回
RuntimeException 裝置啟動原因異常
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

disableAdbRoot

public abstract boolean disableAdbRoot ()

關閉 adb root。

停用 adb 根層級存取權可能會導致裝置與 adb 中斷連線。這個方法會封鎖,直到裝置可用為止。

傳回
boolean true (如果成功)。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

doesFileExist

public abstract boolean doesFileExist (String deviceFilePath)

輔助方法,用於判斷裝置上是否有檔案。

參數
deviceFilePath String:裝置上要檢查的檔案絕對路徑

傳回
boolean 如果檔案存在,則為 true,否則為 false

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

enableAdbRoot

public abstract boolean enableAdbRoot ()

開啟 adb root。如果「enable-root」設定為「false」,系統會記錄訊息並傳回,但不啟用根目錄。

啟用 adb 根層級存取權可能會導致裝置與 adb 中斷連線。這個方法會封鎖,直到裝置可用為止。

傳回
boolean true (如果成功)。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbCommand

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

Helper method which executes a adb command as a system command with a specified timeout.

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
timeout long:裝置被視為沒有回應前的時間 (以毫秒為單位),如設為 0L,則不會逾時

commandArgs String:要執行的 adb 指令和引數

傳回
String 指令的 stdout。如果指令執行失敗,請使用 null

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbCommand

public abstract String executeAdbCommand (String... commandArgs)

輔助方法,可將 adb 指令做為系統指令執行。

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
commandArgs String:要執行的 adb 指令和引數

傳回
String 指令的 stdout。如果指令執行失敗,請使用 null

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbCommand

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

Helper method which executes a adb command as a system command with a specified timeout.

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
timeout long:裝置被視為沒有回應前的時間 (以毫秒為單位),如設為 0L,則表示沒有逾時

envMap :要為指令設定的環境

commandArgs String:要執行的 adb 指令和引數

傳回
String 指令的 stdout。如果指令執行失敗,請使用 null

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbV2Command

public abstract CommandResult executeAdbV2Command (long timeout, 
                 envMap, 
                String... commandArgs)

Helper method which executes a adb command as a system command with a specified timeout.

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
timeout long:裝置被視為沒有回應前的時間 (以毫秒為單位),如設為 0L,則表示沒有逾時

envMap :要為指令設定的環境

commandArgs String:要執行的 adb 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbV2Command

public abstract CommandResult executeAdbV2Command (String... commandArgs)

輔助方法,可將 adb 指令做為系統指令執行。

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
commandArgs String:要執行的 adb 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeAdbV2Command

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

Helper method which executes a adb command as a system command with a specified timeout.

請盡可能改用 executeShellCommand(String),因為這個方法能更有效地偵測失敗並提升效能。

參數
timeout long:裝置被視為沒有回應前的時間 (以毫秒為單位),如設為 0L,則不會逾時

commandArgs String:要執行的 adb 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeFastbootCommand

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

輔助方法,可將 fastboot 指令做為系統指令執行。

裝置處於快速啟動模式時,應會使用這項功能。

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

commandArgs String:要執行的 Fastboot 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeFastbootCommand

public abstract CommandResult executeFastbootCommand (String... commandArgs)

輔助方法,會以系統指令的形式執行 Fastboot 指令,預設逾時時間為 2 分鐘。

裝置處於快速啟動模式時,應會使用這項功能。

參數
commandArgs String:要執行的 Fastboot 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeLongFastbootCommand

public abstract CommandResult executeLongFastbootCommand (String... commandArgs)

輔助方法,可將長時間執行的 Fastboot 指令做為系統指令執行。

executeFastbootCommand(String) 相同,但逾時時間較長。

參數
commandArgs String:要執行的 Fastboot 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeLongFastbootCommand

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

Helper method which executes a long running fastboot command as a system command with system environment variables.

executeFastbootCommand(String) 相同,但逾時時間較長。

參數
envVarMap :fastboot 指令執行的系統環境變數

commandArgs String:要執行的 Fastboot 指令和引數

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellCommand

public abstract String executeShellCommand (String command)

這個輔助方法會執行 adb shell 指令,並以 String 形式傳回輸出內容。

參數
command String:要執行的 adb shell 指令

傳回
String 殼層輸出內容

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellCommand

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

執行 adb shell 指令,並提供更多參數來控管指令行為。

參數
command String:要執行的 adb shell 指令

receiver IShellOutputReceiver:要將直接殼層輸出內容導向的 IShellOutputReceiver

maxTimeToOutputShellResponse long:指令不得輸出任何回應的時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

retryAttempts int:如果命令因例外狀況而失敗,重試次數上限。如果 retryAttempts 執行失敗,系統會擲回 DeviceNotResponsiveException。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellCommand

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

執行 adb shell 指令,並提供更多參數來控管指令行為。

參數
command String:要執行的 adb shell 指令

receiver IShellOutputReceiver:要將直接殼層輸出內容導向的 IShellOutputReceiver

maxTimeoutForCommand long:指令完成的逾時時間上限;單位如 timeUnit 中所指定

maxTimeToOutputShellResponse long:指令不得輸出任何回應的時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

retryAttempts int:如果命令因例外狀況而失敗,重試命令的次數上限。如果 retryAttempts 未順利執行,系統會擲回 DeviceNotResponsiveException。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellCommand

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:要將直接殼層輸出內容導向的 IShellOutputReceiver

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command)

輔助方法,可執行 adb shell 指令,並以指令狀態輸出、stdout 和 stderr 正確填入的 CommandResult 形式傳回結果。

參數
command String:要執行的指令。

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                OutputStream pipeToOutput)

這個輔助方法會執行 adb shell 指令,並以指令狀態輸出和 stderr 正確填入 CommandResult,然後傳回結果。stdout 會導向至指定的串流。

參數
command String:要執行的指令。

pipeToOutput OutputStreamERROR(/OutputStream)標準輸出內容的重新導向位置,或為空值。

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

public abstract CommandResult executeShellV2Command (String command, 
                File pipeAsInput)

輔助方法,可執行 adb shell 指令,並以指令狀態輸出、stdout 和 stderr 正確填入結果,然後以 CommandResult 形式傳回。

參數
command String:要執行的指令。

pipeAsInput File:將做為指令輸入內容的 ERROR(/File),或空值。

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

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

執行 adb shell 指令,並提供更多參數來控管指令行為。

參數
command String:要執行的 adb shell 指令

maxTimeoutForCommand long:指令完成的逾時時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

retryAttempts int:如果命令因例外狀況而失敗,重試命令的次數上限。如果 retryAttempts 未順利執行,系統會擲回 DeviceNotResponsiveException。

傳回
CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

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

執行 adb shell 指令,並提供更多參數來控管指令行為。

參數
command String:要執行的 adb shell 指令

maxTimeoutForCommand long:指令完成的逾時時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

傳回
CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

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 OutputStreamERROR(/OutputStream)標準輸出內容的重新導向位置,或為空值。

maxTimeoutForCommand long:指令完成的逾時時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

retryAttempts int:如果命令因例外狀況而失敗,重試命令的次數上限。如果 retryAttempts 未順利執行,系統會擲回 DeviceNotResponsiveException。

傳回
CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

executeShellV2Command

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 OutputStreamERROR(/OutputStream)標準輸出內容的重新導向位置,或為空值。

pipeToError OutputStream:要重新導向標準錯誤的 ERROR(/OutputStream),或為空值。

maxTimeoutForCommand long:指令完成的逾時時間上限;單位如 timeUnit 中所指定

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

retryAttempts int:如果命令因例外狀況而失敗,重試命令的次數上限。如果 retryAttempts 未順利執行,系統會擲回 DeviceNotResponsiveException。

傳回
CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

fastbootWipePartition

public abstract CommandResult fastbootWipePartition (String partition)

清除裝置分區的輔助方法。

如果 getUseFastbootErase()true,系統會使用 fastboot erase 清除分區。裝置下次啟動時,必須建立檔案系統。否則會使用 fastboot 格式,在裝置上建立新的檔案系統。

裝置處於快速啟動模式時,應會使用這項功能。

參數
partition String:要清除的分區

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getApiLevel

public abstract int getApiLevel ()

取得裝置 API 級別。預設值為 UNKNOWN_API_LEVEL

傳回
int 表示裝置 API 級別的整數

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBasebandVersion

public abstract String getBasebandVersion ()

取得這部裝置基頻 (無線電) 版本的便利方法。取得無線電版本資訊是裝置專屬功能,因此可能無法為所有裝置傳回正確資訊。這個方法會依據 gsm.version.baseband 屬性傳回正確的版本資訊。對於部分 CDMA 裝置而言,這項資訊並不準確,且這裡傳回的版本可能與從 Fastboot 回報的版本不符,也可能不會傳回 CDMA 無線電的版本。簡而言之,只有在 gsm.version.baseband 屬性與 fastboot getvar version-baseband 傳回的版本相同時,這個方法才會回報準確的版本。

傳回
String String 基頻版本,或 null (如果無法判斷,例如裝置沒有無線電或無法讀取版本字串)

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getBattery

public abstract Integer getBattery ()

傳回裝置目前的電池電量,如果無法取得電池電量,則傳回 Null。

傳回
Integer

getBooleanProperty

public abstract boolean getBooleanProperty (String name, 
                boolean defaultValue)

傳回指定屬性的布林值。

參數
name String:屬性名稱

defaultValue boolean:如果屬性為空白或不存在,則傳回預設值。

傳回
boolean 如果屬性的值為 "1""y""yes""on""true",則為 true;如果屬性的值為 "0""n""no""off""false"defaultValue,則為 false;否則為其他值。

擲回
DeviceNotAvailableException

getBootHistory

public abstract  getBootHistory ()

輔助方法會收集啟動時間和啟動原因的啟動記錄地圖。

傳回
啟動時間 (自 Epoch 紀元時間起算,以秒為單位的世界標準時間) 和啟動原因的對應

擲回
DeviceNotAvailableException

getBootHistorySince

public abstract  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

輔助方法會從裝置收集自指定時間 (以紀元時間為準) 起的啟動時間和啟動原因,並以指定的時間單位儲存啟動記錄對應。您可以使用 getDeviceDate() 方法,取得目前裝置的 utcEpochTime (以毫秒為單位)。

參數
utcEpochTime long:裝置時間 (自 Epoch 起算)。

timeUnit TimeUnit:時間單位 TimeUnit

傳回
啟動時間 (自 Epoch 紀元時間起算,以秒為單位的世界標準時間) 和啟動原因的對應

擲回
DeviceNotAvailableException

getBootloaderVersion

public abstract String getBootloaderVersion ()

Convenience method to get the bootloader version of this device.

系統會嘗試從裝置的目前狀態擷取系統啟動載入程式版本。(例如,如果裝置處於快速啟動模式,系統會嘗試從快速啟動模式擷取版本)

傳回
String String系統啟動載入程式版本,或 null (如果找不到)

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getBuildAlias

public abstract String getBuildAlias ()

擷取裝置目前執行的建構版本別名。

建構別名通常是比建構 ID 更容易閱讀的字串 (Nexus 建構版本通常是數字)。舉例來說,Android 4.2 的最終版本別名為 JDQ39,建構 ID 為 573038

傳回
String 建構別名,或無法擷取時改用建構 ID

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildFlavor

public abstract String getBuildFlavor ()

擷取裝置的建構版本。

傳回
String 建構版本,如果無法擷取,則為空值

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildId

public abstract String getBuildId ()

擷取裝置目前執行的建構版本。

傳回
String 建構作業 ID,或無法擷取時為 IBuildInfo.UNKNOWN_BUILD_ID

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getBuildSigningKeys

public abstract String getBuildSigningKeys ()

傳回用於簽署裝置映像檔的金鑰類型

Android 裝置通常會以測試金鑰 (如 AOSP) 或發布金鑰 (由個別裝置製造商控管) 簽署

傳回
String 如果找到簽署金鑰,則傳回該金鑰;否則傳回空值。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getCachedDeviceDescriptor

public abstract DeviceDescriptor getCachedDeviceDescriptor ()

如果裝置已分配,則傳回快取 DeviceDescriptor,否則傳回目前的 DeviceDescriptor

傳回
DeviceDescriptor

getCachedDeviceDescriptor

public abstract DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

如果裝置已分配,則傳回快取 DeviceDescriptor,否則傳回目前的 DeviceDescriptor

參數
shortDescriptor boolean:是否將描述元限制為最少資訊

傳回
DeviceDescriptor

getChildren

public abstract String[] getChildren (String deviceFilePath)

如果權限問題導致 IFileEntry 無法運作,可以改用其他方式。

參數
deviceFilePath String:要在裝置上執行搜尋的路徑

傳回
String[] 字串陣列,內含裝置路徑中的所有檔案。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getConnection

public abstract AbstractConnection getConnection ()

傳回與裝置相關聯的連線。

傳回
AbstractConnection

getDeviceClass

public abstract String getDeviceClass ()

取得裝置類別。

傳回
String String 裝置類別。

getDeviceDate

public abstract long getDeviceDate ()

以 Epoch 紀元時間起算的毫秒數傳回裝置日期。

傳回
long 裝置日期,格式為 Epoch。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getDeviceDescriptor

public abstract DeviceDescriptor getDeviceDescriptor ()

從裝置資訊傳回 DeviceDescriptor,即可取得相關資訊,不必傳遞實際的裝置物件。

傳回
DeviceDescriptor

getDeviceDescriptor

public abstract DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

從裝置資訊傳回 DeviceDescriptor,即可取得相關資訊,不必傳遞實際的裝置物件。

參數
shortDescriptor boolean:是否將描述元限制為最少資訊

傳回
DeviceDescriptor

getDeviceState

public abstract TestDeviceState getDeviceState ()

取得裝置狀態。

傳回
TestDeviceState

getDeviceTimeOffset

public abstract long getDeviceTimeOffset (Date date)

輔助函式,可取得裝置與指定 ERROR(/Date) 之間的時間差。在內部使用 Epoch 時間。

參數
date Date

傳回
long 以毫秒為單位的時間差

擲回
DeviceNotAvailableException

getEmulatorOutput

public abstract InputStreamSource getEmulatorOutput ()

取得模擬器 stdout 和 stderr 的串流

傳回
InputStreamSource 模擬器輸出內容

getExternalStoreFreeSpace

public abstract long getExternalStoreFreeSpace ()

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

傳回
long 可用空間大小 (以 KB 為單位)

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getFastbootProductType

public abstract String getFastbootProductType ()

在快速啟動模式下取得裝置產品類型的便利方法。

只有在裝置應處於快速啟動模式時,才使用這個方法。在本例中,這是比一般 getProductType() 方法稍微安全一點的變體,因為如果裝置處於錯誤狀態或沒有回應,ITestDevice 會知道如何將裝置復原為快速啟動模式。

傳回
String String 產品類型名稱,或 null (如果無法判斷)

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getFastbootProductVariant

public abstract String getFastbootProductVariant ()

在快速啟動模式下取得裝置產品類型的便利方法。

只有在裝置應處於快速啟動模式時,才使用這個方法。在本例中,這是比一般 getProductType() 方法稍微安全一點的變體,因為如果裝置處於錯誤狀態或沒有回應,ITestDevice 會知道如何將裝置復原為快速啟動模式。

傳回
String String 產品類型名稱,或 null (如果無法判斷)

擲回
DeviceNotAvailableException 如果裝置連線中斷且無法復原。

getFastbootSerialNumber

public abstract String getFastbootSerialNumber ()

傳回快速啟動模式序號。

傳回
String

getFastbootVariable

public abstract String getFastbootVariable (String variableName)

從裝置擷取指定的快速啟動變數值。

參數
variableName String:變數名稱

傳回
String 屬性值,或是不存在時的 null

擲回
UnsupportedOperationException
DeviceNotAvailableException

getFileEntry

public abstract IFileEntry getFileEntry (String path)

在裝置上擷取遠端檔案的參照。

參數
path String:要擷取的檔案路徑。可以是絕對路徑或相對於「/」的路徑 (即支援「/system」和「system」語法)。

傳回
IFileEntry 如果找不到指定 path 的檔案,則為 IFileEntrynull

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getIDevice

public abstract IDevice getIDevice ()

傳回相關聯 ddmlib 的參照。IDevice

每次裝置與 ADB 中斷連線並重新連線時,DDMS 都可能會分配新的 IDevice。因此呼叫端不應保留對 IDevice 的參照,因為該參照可能會過時。

傳回
IDevice IDevice

getIntProperty

public abstract long getIntProperty (String name, 
                long defaultValue)

從裝置傳回指定屬性的整數值。

參數
name String:屬性名稱

defaultValue long:如果屬性為空白或不存在,則傳回預設值。

傳回
long 屬性值或 defaultValue (如果屬性為空、不存在或沒有整數值)。

擲回
DeviceNotAvailableException

getLastExpectedRebootTimeMillis

public abstract long getLastExpectedRebootTimeMillis ()

傳回 Tradefed API 上次觸發重新啟動的時間,以自 EPOCH 起算的毫秒數表示,如 System.currentTimeMillis() 所傳回。

傳回
long

getLaunchApiLevel

public abstract int getLaunchApiLevel ()

取得裝置首次啟動時的 API 級別。預設值為 UNKNOWN_API_LEVEL

傳回
int 整數,表示裝置首次啟動時的 API 級別

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

getLogcat

public abstract InputStreamSource getLogcat ()

擷取 logcat 資料的快照串流。

支援兩種模式:

  • 如果目前正在背景擷取 logcat,則會傳回最多 TestDeviceOptions.getMaxLogcatDataSize() 位元組的背景 logcat 擷取內容
  • 否則,如果裝置目前正在回應,系統會傳回 logcat 資料的靜態傾印

    傳回
    InputStreamSource

  • getLogcat

    public abstract InputStreamSource getLogcat (int maxBytes)

    擷取最近 maxBytes 份所擷取 logcat 資料的快照串流。

    如果您想頻繁擷取擷取的 logcat 資料快照,但又不想因取得整個 getLogcat() 快照而付出可能很高的磁碟空間代價,這項功能就非常實用。

    參數
    maxBytes int:要傳回的資料量上限。應為可輕鬆放入記憶體的量

    傳回
    InputStreamSource

    getLogcatDump

    public abstract InputStreamSource getLogcatDump ()

    取得裝置目前 Logcat 的傾印檔。與 getLogcat() 不同,這個方法一律會傳回 logcat 的靜態傾印。

    缺點是如果裝置無法連線,就不會傳回任何內容。

    傳回
    InputStreamSource 記錄資料的 InputStreamSource。如果無法擷取 logcat 資料,系統會傳回空白串流。

    getLogcatSince

    public abstract InputStreamSource getLogcatSince (long date)

    從提供的日期開始,擷取所擷取 logcat 資料的快照串流。請使用裝置上的時間 getDeviceDate()

    參數
    date long:以紀元後毫秒為單位,表示從何時開始擷取快照,直到目前為止。 (可使用「date +%s」取得)

    傳回
    InputStreamSource

    getMountPoint

    public abstract String getMountPoint (String mountName)

    傳回掛接點。

    如果 IDevice 中沒有快取資訊,則直接查詢裝置。

    待辦事項:將這項行為移至 IDevice.getMountPoint(String)

    參數
    mountName String:掛接點名稱

    傳回
    String 掛接點或 null

    getMountPointInfo

    public abstract ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    傳回與指定掛接點路徑對應的 MountPointInfo;如果該路徑沒有掛接任何項目,或未以掛接點的形式出現在 /proc/mounts 中,則傳回 null

    參數
    mountpoint String

    傳回
    ITestDevice.MountPointInfo 包含「/proc/mounts」中資訊的 ERROR(/List) MountPointInfo

    擲回
    DeviceNotAvailableException

    另請參閱:

    getMountPointInfo

    public abstract  getMountPointInfo ()

    傳回裝置上 /proc/mounts 中資訊的剖析版本

    傳回
    包含「/proc/mounts」中資訊的 ERROR(/List) MountPointInfo

    擲回
    DeviceNotAvailableException

    getPartitionFreeSpace

    public abstract long getPartitionFreeSpace (String partition)

    輔助方法,用於判斷裝置分割區的可用空間大小。

    參數
    partition String

    傳回
    long 可用空間大小 (以 KB 為單位)

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    getProcessByName

    public abstract ProcessInfo getProcessByName (String processName)

    輔助方法會執行「pidof」和「stat」指令,並傳回 ProcessInfo 物件,其中包含指定程序的 PID 和程序啟動時間。

    參數
    processName String:程序名稱字串。

    傳回
    ProcessInfo 指定 processName 的 ProcessInfo

    擲回
    DeviceNotAvailableException

    getProcessPid

    public abstract String getProcessPid (String process)

    傳回服務的 PID,如果發生錯誤則傳回 null。

    參數
    process String:程序名稱字串。

    傳回
    String

    擲回
    DeviceNotAvailableException

    getProductType

    public abstract String getProductType ()

    Convenience method to get the product type of this device.

    無論裝置處於 adb 或快速啟動模式,這個方法都適用。

    傳回
    String String 產品類型名稱。不得為空值

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原,或無法判斷產品類型

    getProductVariant

    public abstract String getProductVariant ()

    Convenience method to get the product variant of this device.

    無論裝置處於 adb 或快速啟動模式,這個方法都適用。

    傳回
    String String 產品子類名稱,或 null (如果無法判斷)

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    getProperty

    public abstract String getProperty (String name)

    從裝置擷取指定屬性值。

    參數
    name String:屬性名稱

    傳回
    String 屬性值,或是不存在時的 null

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    getRecoveryMode

    public abstract ITestDevice.RecoveryMode getRecoveryMode ()

    取得裝置目前使用的復原模式。

    傳回
    ITestDevice.RecoveryMode 裝置目前使用的復原模式。

    getSerialNumber

    public abstract String getSerialNumber ()

    取得這部裝置序號的便利方法。

    傳回
    String String序號

    getTombstones

    public abstract  getTombstones ()

    從裝置擷取並傳回墓碑清單。需要根層級權限。

    方法是盡量嘗試,因此如果因任何原因無法提取墓碑,該墓碑就不會出現在清單中。只有 DeviceNotAvailableException 會提早終止方法。

    傳回
    墓碑檔案清單,如果沒有墓碑,則為空白。

    擲回
    DeviceNotAvailableException

    另請參閱:

    getTotalMemory

    public abstract long getTotalMemory ()

    以位元組為單位傳回實體記憶體總大小,或在發生內部錯誤時傳回 -1

    傳回
    long

    getTrackingSerial

    public String getTrackingSerial ()

    為方便管理裝置,請取得用於追蹤裝置的序號。

    傳回
    String

    getUseFastbootErase

    public abstract boolean getUseFastbootErase ()

    取得是否使用 fastboot erase 或 fastboot format 抹除裝置上的分區。

    傳回
    boolean true (如果使用 fastboot erase) 或 false (如果使用 fastboot format)。

    isAdbRoot

    public abstract boolean isAdbRoot ()

    傳回
    boolean 如果裝置目前有 adb root,則為 true,否則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    isAdbTcp

    public abstract boolean isAdbTcp ()

    傳回
    boolean true (如果裝置已連線至透過 TCP 進行的 adb),否則為 false

    isAppEnumerationSupported

    public abstract boolean isAppEnumerationSupported ()

    檢查裝置上的平台是否支援應用程式列舉

    傳回
    boolean 如果支援應用程式列舉,則為 True,否則為 False

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isBypassLowTargetSdkBlockSupported

    public abstract boolean isBypassLowTargetSdkBlockSupported ()

    檢查裝置上的平台是否支援略過應用程式安裝的低目標 SDK 封鎖

    傳回
    boolean 如果支援略過低目標 SDK 封鎖,則為 true,否則為 false

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isDebugfsMounted

    public abstract boolean isDebugfsMounted ()

    檢查 debugfs 是否已掛接。

    傳回
    boolean true (如果已掛載 debugfs)

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isDeviceEncrypted

    public abstract boolean isDeviceEncrypted ()

    傳回裝置是否已加密。

    傳回
    boolean true 裝置是否已加密。

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    isDirectory

    public abstract boolean isDirectory (String deviceFilePath)

    如果裝置上的路徑是目錄,則傳回 True,否則傳回 False。

    參數
    deviceFilePath String

    傳回
    boolean

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isEncryptionSupported

    public abstract boolean isEncryptionSupported ()

    傳回裝置是否支援加密功能。

    傳回
    boolean true 裝置是否支援加密。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isExecutable

    public abstract boolean isExecutable (String fullPath)

    如果裝置上的檔案路徑是可執行檔,則傳回 True,否則傳回 False。

    參數
    fullPath String

    傳回
    boolean

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isHeadless

    public abstract boolean isHeadless ()

    如果裝置沒有螢幕 (無螢幕),則傳回 true,否則傳回 false。

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public abstract boolean isRuntimePermissionSupported ()

    檢查裝置上的平台是否支援授予執行階段權限

    傳回
    boolean 如果支援執行階段權限,則為 True,否則為 False。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public abstract boolean isStateBootloaderOrFastbootd ()

    如果裝置處於 TestDeviceState.FASTBOOTTestDeviceState.FASTBOOTD 狀態,則傳回 true。

    傳回
    boolean

    logAnrs

    public abstract boolean logAnrs (ITestLogger logger)

    收集並記錄裝置的 ANR。

    參數
    logger ITestLogger:用於記錄 ANR 的 ITestLogger

    傳回
    boolean 如果記錄成功,則為 True,否則為 False。

    擲回
    DeviceNotAvailableException

    logOnDevice

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

    在裝置的 logcat 中記錄訊息。這是安全呼叫,即使記錄失敗也不會擲回例外狀況。

    參數
    tag String:我們在 logcat 中記錄訊息時使用的標記。

    level Log.LogLevel:logcat 中訊息的偵錯層級。

    format String:訊息格式。

    args Object:要透過 String.format() 替換的 args。

    mountDebugfs

    public abstract void mountDebugfs ()

    掛接 debugfs。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    nonBlockingReboot

    public abstract void nonBlockingReboot ()

    發出指令來重新啟動裝置,並在指令完成且裝置不再顯示於 ADB 時傳回。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    postBootSetup

    public abstract void postBootSetup ()

    請按照操作說明設定裝置,以便在每次啟動後進行測試。

    裝置完全啟動/可用後,應呼叫此方法

    在正常情況下,不需要明確呼叫這個方法,因為實作項目應會在執行重新啟動時自動執行這些步驟。

    如果裝置因其他事件而重新啟動 (例如快速啟動更新指令已完成),可能就需要呼叫這個函式

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    postInvocationTearDown

    public void postInvocationTearDown ()

    這個方法已淘汰。
    請改用 postInvocationTearDown(Throwable)

    裝置專屬的額外必要清除步驟,會在叫用完成後執行。

    postInvocationTearDown

    public abstract void postInvocationTearDown (Throwable invocationException)

    裝置專屬的額外必要清除步驟,會在叫用完成後執行。

    參數
    invocationException Throwable:如果有的話,這是因叫用失敗而引發的最終例外狀況。

    preInvocationSetup

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

    裝置專屬的必要設定額外步驟,會在叫用流程之前於裝置上執行。

    參數
    info IBuildInfo:裝置的 IBuildInfo

    attributes MultiMap:儲存在叫用環境中的屬性

    擲回
    com.android.tradefed.targetprep.TargetSetupError
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException
    TargetSetupError

    pullDir

    public abstract boolean pullDir (String deviceFilePath, 
                    File localDir)

    從裝置以遞迴方式提取目錄內容。

    參數
    deviceFilePath String:遠端來源的絕對檔案路徑

    localDir File:要將檔案拉入的本機目錄

    傳回
    boolean true 檔案是否順利擷取。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullDir

    public abstract boolean pullDir (String deviceFilePath, 
                    File localDir, 
                    int userId)

    從裝置以遞迴方式提取目錄內容。

    參數
    deviceFilePath String:遠端來源的絕對檔案路徑

    localDir File:要將檔案拉入的本機目錄

    userId int:要從中提取的使用者 ID

    傳回
    boolean true 檔案是否順利擷取。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullFile

    public abstract File pullFile (String remoteFilePath, 
                    int userId)

    從裝置擷取檔案、儲存在本機暫時性 ERROR(/File),並傳回該 File

    參數
    remoteFilePath String:裝置上檔案的絕對路徑。

    userId int:要從中提取的使用者 ID

    傳回
    File ERROR(/File),內含裝置檔案的內容;如果因任何原因 (包括主機檔案系統發生問題) 導致複製失敗,則為 null

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullFile

    public abstract File pullFile (String remoteFilePath)

    從裝置擷取檔案、儲存在本機暫時性 ERROR(/File),並傳回該 File

    參數
    remoteFilePath String:裝置上檔案的絕對路徑。

    傳回
    File ERROR(/File),內含裝置檔案的內容;或 null,如果因任何原因 (包括主機檔案系統發生問題) 導致複製失敗

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullFile

    public abstract boolean pullFile (String remoteFilePath, 
                    File localFile)

    從裝置擷取檔案。

    參數
    remoteFilePath String:裝置上檔案的絕對路徑。

    localFile File:用於儲存內容的本機檔案。如果不是空白,系統會替換內容。

    傳回
    boolean true 檔案是否已順利擷取。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullFile

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

    從裝置擷取檔案。

    參數
    remoteFilePath String:裝置上檔案的絕對路徑。

    localFile File:用於儲存內容的本機檔案。如果不是空白,系統會替換內容。

    userId int:要從中提取的使用者 ID

    傳回
    boolean true 檔案是否已順利擷取。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pullFileContents

    public abstract String pullFileContents (String remoteFilePath)

    從裝置擷取檔案,並傳回內容。

    參數
    remoteFilePath String:裝置上檔案的絕對路徑。

    傳回
    String String,內含裝置檔案的內容;如果因任何原因 (包括主機檔案系統發生問題) 導致複製失敗,則為 null

    擲回
    DeviceNotAvailableException

    pullFileFromExternal

    public abstract File pullFileFromExternal (String remoteFilePath)

    這個便利方法可從裝置的外部儲存空間擷取檔案,並將檔案儲存在本機暫時 ERROR(/File) 中,然後傳回該 File 的參照。

    參數
    remoteFilePath String:裝置上檔案的路徑,相對於裝置的外部儲存空間裝載點

    傳回
    File ERROR(/File),內含裝置檔案的內容;或 null,如果因任何原因 (包括主機檔案系統發生問題) 導致複製失敗

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushDir

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath, 
                    int userId)

    將目錄內容遞迴推送至裝置。

    參數
    localDir File:要推送的本機目錄

    deviceFilePath String:遠端目的地的絕對檔案路徑

    userId int:要推送的使用者 ID

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushDir

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

    將目錄內容遞迴推送至裝置,同時排除經過篩選的某些目錄。

    參數
    localDir File:要推送的本機目錄

    deviceFilePath String:遠端目的地的絕對檔案路徑

    excludedDirectories :不應推送的排除目錄名稱集。

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushDir

    public abstract boolean pushDir (File localDir, 
                    String deviceFilePath)

    將目錄內容遞迴推送至裝置。

    參數
    localDir File:要推送的本機目錄

    deviceFilePath String:遠端目的地的絕對檔案路徑

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushFile

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

    pushFile(File, String) 的變體,可選擇性地評估內容供應商的需求。

    參數
    localFile File:要推送的本機檔案

    deviceFilePath String:遠端目的地的絕對檔案路徑

    evaluateContentProviderNeeded boolean:是否需要檢查內容供應商

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath)

    將檔案推送至裝置。預設使用內容供應器。

    參數
    localFile File:要推送的本機檔案

    deviceFilePath String:遠端目的地的絕對檔案路徑

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushFile

    public abstract boolean pushFile (File localFile, 
                    String deviceFilePath, 
                    int userId)

    將檔案推送至裝置。預設使用內容供應器。

    參數
    localFile File:要推送的本機檔案

    deviceFilePath String:遠端目的地的絕對檔案路徑

    userId int:要推送的 userId

    傳回
    boolean true (如果檔案推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    pushString

    public abstract boolean pushString (String contents, 
                    String deviceFilePath)

    將字串建立的檔案推送至裝置

    參數
    contents String:要推送的檔案內容

    deviceFilePath String:遠端目的地的絕對檔案路徑

    傳回
    boolean true (如果字串推送成功)。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    重開。

    public abstract void reboot ()

    將裝置重新啟動為 adb 模式。

    封鎖作業會執行至裝置可用為止。

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    重開。

    public abstract void reboot (String reason)

    以指定的 reason 將裝置重新啟動為 adb 模式,並在重新啟動後保留設定。

    封鎖作業會執行至裝置可用為止。

    您可以查詢 sys.boot.reason 屬性,取得上次重新啟動的原因。

    參數
    reason String:重新啟動的原因;如未指定原因,則為 null

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    rebootIntoBootloader

    public abstract void rebootIntoBootloader ()

    將裝置重新啟動為系統啟動載入程式模式。

    Blocks until device is in bootloader mode.

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    rebootIntoFastbootd

    public abstract void rebootIntoFastbootd ()

    將裝置重新啟動為 fastbootd 模式。

    在裝置進入 fastbootd 模式之前,會一直保持封鎖。

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    rebootIntoRecovery

    public abstract void rebootIntoRecovery ()

    將裝置重新啟動為 adb 復原模式。

    封鎖,直到裝置進入復原模式

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    rebootIntoSideload

    public abstract void rebootIntoSideload (boolean autoReboot)

    將裝置重新啟動為 adb 側載模式 (請注意,這是復原模式下的特殊模式)

    封鎖,直到裝置進入側載模式

    參數
    autoReboot boolean:側載後是否自動重新啟動裝置

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後未進入側載模式

    rebootIntoSideload

    public abstract void rebootIntoSideload ()

    將裝置重新啟動為 adb 側載模式 (請注意,這是復原模式下的特殊模式)

    封鎖,直到裝置進入側載模式

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後未進入側載模式

    rebootUntilOnline

    public abstract void rebootUntilOnline ()

    reboot() 的替代方案,只會封鎖到裝置上線 (即 adb 可見) 為止。

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    rebootUntilOnline

    public abstract void rebootUntilOnline (String reason)

    reboot() 的替代方案,只會封鎖到裝置上線 (即 adb 可見) 為止。

    參數
    reason String:重新啟動的原因;如未指定原因,則為 null

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    另請參閱:

    rebootUserspace

    public abstract void rebootUserspace ()

    僅重新啟動裝置的使用者空間部分。

    封鎖作業會執行至裝置可用為止。

    警告。使用者空間重新啟動功能目前仍在積極開發中,使用時請自行承擔風險。

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    rebootUserspaceUntilOnline

    public abstract void rebootUserspaceUntilOnline ()

    rebootUserspace() ()} 的替代方案,只會封鎖到裝置上線為止,也就是 adb 可見的狀態。

    擲回
    DeviceNotAvailableException 如果裝置在重新啟動後無法使用

    remountSystemReadOnly

    public abstract void remountSystemReadOnly ()

    將裝置上的系統分區設為唯讀。可能需要重新啟動裝置。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountSystemWritable

    public abstract void remountSystemWritable ()

    將裝置上的系統磁碟分割設為可寫入。可能需要重新啟動裝置。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountVendorReadOnly

    public abstract void remountVendorReadOnly ()

    將裝置上的供應商分區設為唯讀。可能需要重新啟動裝置。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    remountVendorWritable

    public abstract void remountVendorWritable ()

    將裝置上的供應商磁碟分割區設為可寫入。可能需要重新啟動裝置。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    runInstrumentationTests

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

    便利方法,可使用做為參數傳遞的一或多個接聽程式執行 ERROR(/#runInstrumentationTests(com.android.ddmlib.testrunner.IRemoteAndroidTestRunner,Collection))

    參數
    runner IRemoteAndroidTestRunnerIRemoteAndroidTestRunner,用於執行測試

    listeners ITestLifeCycleReceiver:測試結果監聽器

    傳回
    boolean true if test command completed. false 如果作業無法完成,但復原成功

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原,也就是測試指令無法完成且復原失敗。

    runInstrumentationTests

    public abstract boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

    執行檢測設備測試,並提供裝置復原功能。

    如果在測試執行完成前與裝置失去連線,且復原成功,系統會通知所有接聽程式 testRunFailed,並傳回「false」。測試指令不會重新執行。如有必要,呼叫端會重試。

    如果在測試執行完成前失去與裝置的連線,且復原失敗,系統會通知所有接聽程式 testRunFailed,並擲回 DeviceNotAvailableException。

    參數
    runner IRemoteAndroidTestRunnerIRemoteAndroidTestRunner,用於執行測試

    listeners :測試結果監聽器

    傳回
    boolean true if test command completed. false (如果因裝置通訊例外狀況而無法完成,但復原成功)

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原,也就是測試指令無法完成且復原失敗。

    runInstrumentationTestsAsUser

    public abstract boolean 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)) 相同,但會為指定使用者執行測試。

    參數
    runner IRemoteAndroidTestRunner

    userId int

    listeners

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

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

    ITestDevice.runInstrumentationTests(IRemoteAndroidTestRunner, ITestLifeCycleReceiver...) 相同,但會為指定使用者執行測試。

    參數
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    setDate

    public abstract void setDate (Date date)

    在裝置上設定日期

    注意:如要在裝置上設定日期,必須取得根存取權

    參數
    date Date:指定特定日期;如果 null,則會使用主機日期

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setOptions

    public abstract void setOptions (TestDeviceOptions options)

    設定裝置的 TestDeviceOptions

    參數
    options TestDeviceOptions

    setProperty

    public abstract boolean setProperty (String propKey, 
                    String propValue)

    在裝置上設定指定屬性值。需要 adb root 為 true。

    參數
    propKey String:要設定的目標鍵。

    propValue String:要設定的屬性值。

    傳回
    boolean 如果 setprop 指令成功,則傳回 True,否則傳回 False。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    setRecovery

    public abstract void setRecovery (IDeviceRecovery recovery)

    設定這部裝置要使用的 IDeviceRecovery。應在首次分配裝置時設定。

    參數
    recovery IDeviceRecoveryIDeviceRecovery

    setRecoveryMode

    public abstract void setRecoveryMode (ITestDevice.RecoveryMode mode)

    設定裝置目前要使用的復原模式。

    用於控制發生裝置通訊問題時要使用的復原方法。建議您僅在必要時 (例如架構故障等) 少量使用此方法。

    參數
    mode ITestDevice.RecoveryMode:是否應開啟「僅在連線時復原」模式。

    setTrackingSerial

    public abstract void setTrackingSerial (String trackingSerial)

    為方便管理裝置,請追蹤我們用來參照裝置的序號。

    參數
    trackingSerial String

    setUseFastbootErase

    public abstract void setUseFastbootErase (boolean useFastbootErase)

    設定是否要使用 fastboot erase 或 fastboot format 抹除裝置上的分割區。

    參數
    useFastbootErase boolean:如果應使用 fastboot erase,請輸入 true;如果應使用 fastboot format,請輸入 false

    startLogcat

    public abstract void startLogcat ()

    在背景中開始擷取裝置的 logcat 輸出內容。

    如果系統已擷取 logcat 輸出內容,這個指令就不會產生任何作用。 之後可透過 getLogcat 擷取資料。

    裝置不再使用時,必須呼叫 stopLogcat()

    在 TF 叫用環境中,通常不需要呼叫 startLogcat()stopLogcat(),因為 TF 架構會啟動及停止 logcat。

    startTradeInModeTesting

    public abstract boolean startTradeInModeTesting (int timeoutMs)

    啟用測試換購模式。裝置會清除資料並重新啟動。

    參數
    timeoutMs int

    傳回
    boolean 成功時傳回 True,否則傳回 False

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    stopEmulatorOutput

    public abstract void stopEmulatorOutput ()

    關閉並刪除模擬器輸出內容。

    stopLogcat

    public abstract void stopLogcat ()

    停止從裝置擷取 logcat 輸出內容,並捨棄目前儲存的 logcat 資料。

    如果沒有擷取 logcat 輸出內容,這個指令就不會產生任何作用。

    stopTradeInModeTesting

    public abstract void stopTradeInModeTesting ()

    停止測試換購模式。裝置會重新啟動。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    switchToAdbTcp

    public abstract String switchToAdbTcp ()

    將裝置切換為 adb-over-tcp 模式。

    傳回
    String tcp 序號或 null (如果裝置無法切換)

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    switchToAdbUsb

    public abstract boolean switchToAdbUsb ()

    將裝置切換為透過 USB 進行 adb 的模式。

    傳回
    boolean 如果切換成功,則為 true,否則為 false

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    syncFiles

    public abstract boolean syncFiles (File localFileDir, 
                    String deviceFilePath)

    將本機檔案目錄的內容逐步同步到裝置。

    比較本機檔案和遠端對應檔案的時間戳記,決定要推送哪些檔案。系統只會將「較新」或不存在的檔案推送到裝置。因此,如果裝置上的檔案集已是最新版本,額外負荷應該相對較小。

    系統會忽略隱藏檔案 (名稱開頭為「.」)。

    使用範例:syncFiles("/tmp/files", "/sdcard") 會建立 /sdcard/files 目錄 (如果該目錄尚不存在),並以遞迴方式將 /tmp/files 內容推送至 /sdcard/files。

    參數
    localFileDir File:包含要以遞迴方式推送檔案的本機檔案目錄。

    deviceFilePath String:遠端目的地絕對檔案路徑根目錄。該檔案路徑中的所有目錄都必須可讀取。也就是說,如果 adb 不是根目錄,推送至 /data/local/tmp 就會失敗

    傳回
    boolean true 檔案是否已成功同步。其他情況則為 false

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    unlockDevice

    public abstract boolean unlockDevice ()

    如果裝置處於加密狀態,則解鎖裝置。

    這個方法可能會重新啟動架構,但不會呼叫 postBootSetup()。因此,這個方法傳回時,裝置可能尚未完全準備好接受測試。

    傳回
    boolean 如果成功或裝置未加密,則為 true

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。
    UnsupportedOperationException 如果裝置不支援加密功能。

    unmountDebugfs

    public abstract void unmountDebugfs ()

    卸載 debugfs。

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    waitForBootComplete

    public abstract boolean waitForBootComplete (long timeOut)

    封鎖,直到設定裝置的開機完成旗標為止。

    參數
    timeOut long:等待設定旗標的時間 (以毫秒為單位)

    傳回
    boolean 如果裝置的啟動完成標記在逾時時間內設定,則為 true

    擲回
    com.android.tradefed.device.DeviceNotAvailableException
    DeviceNotAvailableException

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable ()

    等待裝置回應並可供測試。使用預設逾時。

    傳回
    boolean 如果裝置可用,則為 True;如果復原功能已停用且無法使用,則為 False。

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    waitForDeviceAvailable

    public abstract boolean waitForDeviceAvailable (long waitTime)

    等待裝置回應並可供測試。

    參數
    waitTime long:等待時間 (毫秒)

    傳回
    boolean 如果裝置可用,則為 True;如果復原功能已停用且無法使用,則為 False。

    擲回
    DeviceNotAvailableException 如果裝置在 waitTime 到期後仍未回應。

    waitForDeviceAvailableInRecoverPath

    public abstract boolean waitForDeviceAvailableInRecoverPath (long waitTime)

    等待裝置回應並可供使用,不考慮復原路徑。

    參數
    waitTime long

    傳回
    boolean 如果裝置可用,則為 True;如果裝置無法使用,則為 False。

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    waitForDeviceBootloader

    public abstract void waitForDeviceBootloader ()

    封鎖,直到裝置可透過 Fastboot 顯示為止。使用預設逾時。

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    waitForDeviceInRecovery

    public abstract boolean waitForDeviceInRecovery (long waitTime)

    裝置處於「adb recovery」狀態時的區塊 (請注意,這與 IDeviceRecovery 不同)。

    參數
    waitTime long:等待時間 (毫秒)

    傳回
    boolean true如果裝置在時間到期前啟動進入復原模式。 其他情況則為 false

    waitForDeviceInSideload

    public abstract boolean waitForDeviceInSideload (long waitTime)

    禁止裝置處於「adb sideload」狀態

    參數
    waitTime long:等待時間 (毫秒)

    傳回
    boolean true如果裝置在時間到期前啟動側載模式,其他情況則為 false

    waitForDeviceNotAvailable

    public abstract boolean waitForDeviceNotAvailable (long waitTime)

    裝置的區塊無法使用,也就是說,裝置在 Android 偵錯橋接器 (adb) 中遺失

    參數
    waitTime long:等待時間 (毫秒)

    傳回
    boolean true如果裝置在時間到期前無法使用。 其他情況則為 false

    waitForDeviceOnline

    public abstract void waitForDeviceOnline ()

    封鎖,直到裝置透過 adb 可見為止。 使用預設逾時時間

    請注意,裝置完成後可能不會回應指令。請改用 waitForDeviceAvailable()

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    waitForDeviceOnline

    public abstract void waitForDeviceOnline (long waitTime)

    Blocks until device is visible via adb.

    請注意,裝置完成後可能不會回應指令。請改用 waitForDeviceAvailable()

    參數
    waitTime long:等待時間 (毫秒)

    擲回
    DeviceNotAvailableException 如果裝置連線中斷且無法復原。

    waitForDeviceShell

    public abstract boolean waitForDeviceShell (long waitTime)

    等待裝置回應基本 adb 殼層指令。

    參數
    waitTime long:等待時間 (毫秒)

    傳回
    boolean true 經過 waitTime 前裝置恢復回應。