NativeDevice

public class NativeDevice
extends Object implements IConfigurationReceiver, IManagedTestDevice, ITestLoggerReceiver

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


ITestDevice 非完整堆疊 Android 裝置的預設實作。

摘要

巢狀類別

class NativeDevice.AdbAction

用於執行 OS「adb ....」指令的 ERROR(DeviceAction/com.android.tradefed.device.NativeDevice.DeviceAction DeviceAction)。 

class NativeDevice.AdbShellAction

 

class NativeDevice.RebootDeviceAction

ERROR(DeviceAction/com.android.tradefed.device.NativeDevice.DeviceAction DeviceAction) 重新啟動裝置。 

常數

String DEBUGFS_PATH

int INVALID_USER_ID

針對任何無效/找不到的使用者 ID 傳回的值:UserHandle 定義了 -10000 值

long MAX_HOST_DEVICE_TIME_OFFSET

int MAX_RETRY_ATTEMPTS

要執行的預設指令重試次數

String SD_CARD

String STORAGE_EMULATED

欄位

protected TestDeviceOptions mOptions

protected final IDeviceStateMonitor mStateMonitor

公用建構函式

NativeDevice(IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)

建立 TestDevice

公用方法

void batchPrefetchStartupBuildProps()

微幅最佳化 (約 400 毫秒):預先擷取所有需要的屬性,而非針對每個屬性呼叫「adb getprop」。

boolean canSwitchToHeadlessSystemUser()

傳回是否允許切換至無使用者介面系統使用者。

boolean checkApiLevelAgainstNextRelease(int strictMinLevel)

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

boolean checkConnectivity()

確認裝置已連上網路。

boolean clearErrorDialogs()

嘗試關閉裝置 UI 目前顯示的任何錯誤對話方塊。

void clearLastConnectedWifiNetwork()

清除上次連線的 Wi-Fi 網路。

void clearLogcat()

刪除所有累積的 logcat 資料。

boolean connectToWifiNetwork( wifiSsidToPsk, boolean scanSsid)

連線至 Wi-Fi 網路。

boolean connectToWifiNetwork(String wifiSsid, String wifiPsk)

連線至 Wi-Fi 網路。

boolean connectToWifiNetwork( wifiSsidToPsk)

連線至 Wi-Fi 網路。f

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

連線至 Wi-Fi 網路。

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

connectToWifiNetwork(String, String) 的變體,只會在裝置目前沒有網路連線時連線。

boolean connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk)

connectToWifiNetwork(String, String) 的變體,只會在裝置目前沒有網路連線時連線。

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

使用指定名稱和提供的旗標建立使用者

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

使用指定名稱和提供的旗標建立使用者

int createUser(String name)

建立具有指定名稱和預設旗標 0 的使用者。

int createUserNoThrow(String name)

建立具有指定名稱和預設旗標 0 的使用者。

DeviceInspectionResult debugDeviceNotAvailable()

檢查裝置,並在裝置無法使用時傳回詳細資訊。

void deleteFile(String deviceFilePath, int userId)

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

void deleteFile(String deviceFilePath)

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

void deregisterDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)

移除已註冊的 IDeviceActionReceiver

boolean deviceSoftRestarted(ProcessInfo prevSystemServerProcess)

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

boolean deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)

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

boolean disableAdbRoot()

關閉 adb 根層級存取權。

void disableKeyguard()

Attempts to disable the keyguard.

boolean disableNetworkMonitor()

停用裝置上的網路監控功能。

boolean disconnectFromWifi()

中斷 Wi-Fi 網路連線。

boolean doesFileExist(String deviceFilePath, int userId)

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

boolean doesFileExist(String deviceFilePath)

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

File dumpHeap(String process, String devicePath)

嘗試從 system_server 傾印堆積。

boolean enableAdbRoot()

開啟 adb 根層級存取權。

boolean enableNetworkMonitor()

在裝置上啟用網路監控功能。

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

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

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

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

String executeAdbCommand(String... cmdArgs)

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

CommandResult executeAdbV2Command(String... cmdArgs)

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

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

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

CommandResult executeAdbV2Command(long timeout, envMap, String... cmdArgs)

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

CommandResult executeFastbootCommand(String... cmdArgs)

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

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

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

CommandResult executeLongFastbootCommand(String... cmdArgs)

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

CommandResult executeLongFastbootCommand( envVarMap, String... cmdArgs)

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

String executeShellCommand(String command)

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

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

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

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

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

void executeShellCommand(String command, IShellOutputReceiver receiver)

執行指定的 adb shell 指令,如果指令失敗,會多次重試。

CommandResult executeShellV2Command(String cmd)

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

CommandResult executeShellV2Command(String cmd, OutputStream pipeToOutput)

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

CommandResult executeShellV2Command(String cmd, File pipeAsInput)

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

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

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

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

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

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

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

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

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

CommandResult fastbootWipePartition(String partition)

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

getActiveApexes()

擷取裝置上啟用的 APEX 相關資訊。

String getAdbPath()

傳回所用 adb 二進位檔的路徑。

getAllSettings(String namespace)

傳回所要求命名空間的鍵/值組合。

DeviceAllocationState getAllocationState()

傳回裝置的目前分配狀態

String getAndroidId(int userId)

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

getAndroidIds()

建立與相符使用者 ID 相關聯的 Android ID 對應。

int getApiLevel()

取得裝置 API 級別。

PackageInfo getAppPackageInfo(String packageName)

擷取裝置上安裝的套件相關資訊。

getAppPackageInfos()

擷取裝置上安裝的套件資訊。

String getBasebandVersion()

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

Integer getBattery()

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

boolean getBooleanProperty(String name, boolean defaultValue)

傳回指定屬性的布林值。

getBootHistory()

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

getBootHistorySince(long utcEpochTime, TimeUnit timeUnit)

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

String getBootloaderVersion()

取得這部裝置系統啟動載入程式版本的便利方法。

InputStreamSource getBugreport()

從裝置擷取錯誤報告。

InputStreamSource getBugreportz()

從裝置擷取錯誤報告。

String getBuildAlias()

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

String getBuildFlavor()

擷取裝置的建構版本。

String getBuildId()

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

String getBuildSigningKeys()

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

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

DeviceDescriptor getCachedDeviceDescriptor()

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

DeviceDescriptor getCachedDeviceDescriptor(boolean shortDescriptor)

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

String[] getChildren(String path)

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

AbstractConnection getConnection()

與裝置相關聯的目前連線。

ContentProviderHandler getContentProvider(int userId)

傳回 ContentProviderHandler,如果無法使用則傳回空值。

DeviceFoldableState getCurrentFoldableState()

傳回裝置目前的折疊狀態,如果發生問題則傳回 null。

int getCurrentUser()

傳回目前執行使用者的 ID。

String getDeviceClass()

取得裝置類別。

long getDeviceDate()

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

DeviceDescriptor getDeviceDescriptor()

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

DeviceDescriptor getDeviceDescriptor(boolean shortDescriptor)

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

TestDeviceState getDeviceState()

取得裝置狀態。

long getDeviceTimeOffset(Date date)

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

InputStreamSource getEmulatorOutput()

取得模擬器 stdout 和 stderr 的串流

Process getEmulatorProcess()

傳回與這個模擬器對應的 Process

final File getExecuteShellCommandLog()

包含所有 executeShellCommand(String) 記錄的記錄檔。

long getExternalStoreFreeSpace()

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

String getFastbootPath()

傳回所用快速啟動二進位檔的路徑。

String getFastbootProductType()

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

String getFastbootProductVariant()

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

String getFastbootSerialNumber()

傳回快速啟動模式序號。

String getFastbootVariable(String variableName)

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

String getFastbootVersion()

傳回所用 Fastboot 二進位檔的版本字串。

IFileEntry getFileEntry(String path)

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

IFileEntry getFileEntry(FileListingService.FileEntry entry)

非官方輔助程式,可從非根路徑取得 FileEntry

getFoldableStates()

傳回裝置上的摺疊狀態清單。

IDevice getIDevice()

傳回相關聯 ddmlib 的參照。IDevice

getInstalledPackageNames()

擷取裝置上的應用程式套件名稱。

long getIntProperty(String name, long defaultValue)

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

String getIpAddress()

取得裝置的 IP 位址。

KeyguardControllerState getKeyguardState()

傳回物件以取得螢幕鎖定目前的狀態,如果系統不支援,則傳回空值。

long getLastExpectedRebootTimeMillis()

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

int getLaunchApiLevel()

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

InputStreamSource getLogcat()

擷取 logcat 資料的快照串流。

InputStreamSource getLogcat(int maxBytes)

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

InputStreamSource getLogcatDump()

取得裝置目前 Logcat 的傾印。

InputStreamSource getLogcatSince(long date)

擷取從指定日期開始的已擷取 logcat 資料快照串流。

String getMacAddress()

傳回裝置的 MAC 位址,如果無法從裝置查詢,則傳回空值。

Integer getMainUserId()

傳回主要使用者 ID。

getMainlineModuleInfo()

取得裝置上安裝的主線模組相關資訊。

int getMaxNumberOfRunningUsersSupported()

取得支援同時執行的使用者人數上限。

int getMaxNumberOfUsersSupported()

取得支援的使用者人數上限。

Process getMicrodroidProcess()
IDeviceStateMonitor getMonitor()

傳回與裝置相關聯的 IDeviceStateMonitor

String getMountPoint(String mountName)

傳回掛接點。

ITestDevice.MountPointInfo getMountPointInfo(String mountpoint)

傳回與指定掛接點路徑對應的 MountPointInfo,如果該路徑沒有掛接任何項目,或以其他方式未在 /proc/mounts 中顯示為掛接點,則傳回 null

getMountPointInfo()

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

TestDeviceOptions getOptions()

擷取裝置的測試選項。

long getPartitionFreeSpace(String partition)

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

Integer getPrimaryUserId()

傳回主要使用者 ID。

ProcessInfo getProcessByName(String processName)

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

String getProcessPid(String process)

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

String getProductType()

Convenience method to get the product type of this device.

String getProductVariant()

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

String getProperty(String name)

從裝置擷取指定屬性值。

ITestDevice.RecoveryMode getRecoveryMode()

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

InputStreamSource getScreenshot(long displayId)

從指定顯示器 ID 的裝置擷取螢幕截圖。

InputStreamSource getScreenshot(String format)

擷取裝置的螢幕截圖。

InputStreamSource getScreenshot(String format, boolean rescale)

擷取裝置的螢幕截圖。

InputStreamSource getScreenshot()

擷取裝置的螢幕截圖。

String getSerialNumber()

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

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

傳回所要求設定的值。

String getSetting(String namespace, String key)

請參閱 getSetting(int, String, String),並在系統使用者上執行。

String getSimOperator()

如果無法使用或裝置無法使用,則傳回 SIM 卡業者或空值。

String getSimState()

傳回 SIM 卡狀態,如果無法使用或裝置無法使用,則傳回空值。

getTombstones()

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

long getTotalMemory()

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

String getTrackingSerial()

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

getUninstallablePackageNames()

擷取可解除安裝的應用程式套件名稱。

boolean getUseFastbootErase()

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

int getUserFlags(int userId)

找出並傳回指定使用者的檢舉。

getUserInfos()

取得裝置上 useId 對應 UserInfo 的對應項。

int getUserSerialNumber(int userId)

如果找到與 userId 相關聯的序號,則傳回該序號;否則傳回 -10000。

IManagedTestDevice.DeviceEventResponse handleAllocationEvent(DeviceEvent event)

處理指定的 DeviceEvent。

處理 DeviceEvent,這可能會將裝置轉換為新的分配狀態,也可能不會。

boolean hasFeature(String feature)

檢查裝置是否支援特定功能。

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

初始化與裝置的連線。

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

在裝置上安裝 Android 套件。

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

在裝置上安裝 Android 套件。

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

為特定使用者在裝置上安裝 Android 套件。

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

為特定使用者在裝置上安裝 Android 套件。

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

以遞增模式安裝 APK。

void invalidatePropertyCache()
boolean isAdbRoot()

boolean isAdbTcp()
boolean isAppEnumerationSupported()

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

boolean isBypassLowTargetSdkBlockSupported()

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

boolean isDebugfsMounted()

檢查 debugfs 是否已掛接。

boolean isDeviceEncrypted()

傳回裝置是否已加密。

boolean isDirectory(String path)

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

boolean isEnableAdbRoot()
boolean isEncryptionSupported()

傳回裝置是否支援加密。

boolean isExecutable(String fullPath)

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

boolean isFastbootEnabled()

傳回裝置是否支援 Fastboot。

boolean isHeadless()

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

boolean isHeadlessSystemUserMode()

傳回裝置是否使用無頭系統使用者模式。

boolean isMainUserPermanentAdmin()

傳回主要使用者是否為永久管理員,且無法刪除或降級為非管理員狀態。

boolean isMultiUserSupported()

判斷是否支援多位使用者。

boolean isPackageInstalled(String packageName, String userId)

查詢裝置的指定套件名稱和使用者 ID,檢查該使用者目前是否已安裝應用程式。

boolean isPackageInstalled(String packageName)

查詢裝置的指定套件名稱,檢查目前是否已安裝該套件。

boolean isRuntimePermissionSupported()

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

boolean isStateBootloaderOrFastbootd()

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

boolean isUserRunning(int userId)

檢查特定使用者是否正在執行。

boolean isUserSecondary(int userId)

根據指定使用者的旗標,傳回該使用者是否為次要使用者。

boolean isUserVisible(int userId)

檢查指定使用者是否可見。

boolean isUserVisibleOnDisplay(int userId, int displayId)

檢查指定使用者是否在指定螢幕上可見。

boolean isVisibleBackgroundUsersOnDefaultDisplaySupported()

傳回裝置是否允許使用者在 ERROR(/java.android.view.Display#DEFAULT_DISPLAY) 中啟動可見的背景。

boolean isVisibleBackgroundUsersSupported()

Returns whether the device allow users to be started visible in the background.

boolean isWifiEnabled()

測試 Wi-Fi 是否已啟用。

listDisplayIds()

收集裝置上「dumpsys SurfaceFlinger」回報的可用螢幕 ID 清單。

listDisplayIdsForStartingVisibleBackgroundUsers()

取得可用於 start a user visible in the background 的螢幕清單。

listUsers()

取得裝置上的使用者清單。

boolean logAnrs(ITestLogger logger)

收集並記錄裝置的 ANR。

boolean logBugreport(String dataName, ITestLogger listener)

輔助方法,可擷取錯誤報告並記錄到回報者。

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

在裝置的 logcat 中記錄訊息。

void mountDebugfs()

掛接 debugfs。

void nonBlockingReboot()

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

void postAdbRootAction()

如果裝置在 adb root 後和重新上線前需要執行特定動作,請覆寫此方法。

void postAdbUnrootAction()

如果裝置需要在 adb 解除 Root 權限後,以及裝置重新上線前執行特定動作,請覆寫此方法。

void postBootSetup()

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

void postInvocationTearDown(Throwable exception)

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

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

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

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

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

boolean pullDir(String deviceFilePath, File localDir)

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

boolean pullFile(String remoteFilePath, File localFile)

從裝置擷取檔案。

File pullFile(String remoteFilePath, int userId)

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

File pullFile(String remoteFilePath)

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

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

從裝置擷取檔案。

String pullFileContents(String remoteFilePath)

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

File pullFileFromExternal(String remoteFilePath)

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

boolean pushDir(File localFileDir, String deviceFilePath, excludedDirectories)

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

boolean pushDir(File localFileDir, String deviceFilePath)

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

boolean pushDir(File localFileDir, String deviceFilePath, int userId)

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

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

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

boolean pushFile(File localFile, String remoteFilePath)

將檔案推送至裝置。

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

將檔案推送至裝置。

boolean pushString(String contents, String remoteFilePath)

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

void reboot(String reason)

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

void reboot()

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

void rebootIntoBootloader()

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

void rebootIntoFastbootd()

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

void rebootIntoRecovery()

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

void rebootIntoSideload()

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

Blocks until device enters sideload mode

void rebootIntoSideload(boolean autoReboot)

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

Blocks until device enters sideload mode

void rebootUntilOnline()

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

void rebootUntilOnline(String reason)

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

void rebootUserspace()

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

void rebootUserspaceUntilOnline()

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

boolean recoverDevice()

嘗試恢復裝置通訊。

void registerDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)

為這部裝置註冊 IDeviceActionReceiver

void remountSystemReadOnly()

將裝置上的系統分區設為唯讀。

void remountSystemWritable()

將裝置上的系統磁碟分割設為可寫入。

void remountVendorReadOnly()

將裝置上的供應商分區設為唯讀。

void remountVendorWritable()

將裝置上的供應商磁碟分割區設為可寫入。

boolean removeAdmin(String componentName, int userId)

移除指定使用者中指定的裝置管理員,如果成功則傳回 true,否則傳回 false

void removeOwners()

盡可能移除所有現有的裝置設定檔擁有者。

boolean removeUser(int userId)

從裝置中移除指定使用者。

void resetContentProviderSetup()

重設內容供應商設定的旗標,再次觸發設定。

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

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

boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, listeners)

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

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

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

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

void setAdbPath(String adbPath)

設定要使用的 adb 二進位檔路徑。

void setConfiguration(IConfiguration configuration)

注入使用的 IConfiguration

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

在裝置上設定日期

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

boolean setDeviceOwner(String componentName, int userId)

在指定使用者中,將裝置管理員元件設為裝置擁有者。

void setDeviceState(TestDeviceState deviceState)

更新裝置的狀態。

void setEmulatorOutputStream(SizeLimitedOutputStream output)

針對模擬器設定 SizeLimitedOutputStream,記錄輸出內容

void setEmulatorProcess(Process p)

設定 Process,前提是這部裝置為模擬器。

void setFastbootEnabled(boolean fastbootEnabled)

設定裝置的 Fastboot 選項。

void setFastbootPath(String fastbootPath)

設定要使用的 fastboot 二進位檔路徑。

void setIDevice(IDevice newDevice)

更新與這個 ITestDevice 相關聯的 IDevice。

void setLogStartDelay(int delay)

設定開始擷取線上裝置的 logcat 前,要等待的時間 (毫秒)。

void setOptions(TestDeviceOptions options)

為裝置設定 TestDeviceOptions

boolean setProperty(String propKey, String propValue)

在裝置上設定指定屬性值。

void setRecovery(IDeviceRecovery recovery)

設定這部裝置要使用的 IDeviceRecovery

void setRecoveryMode(ITestDevice.RecoveryMode mode)

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

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

請參閱 setSetting(int, String, String, String),並在系統使用者上執行。

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

將設定值新增至特定使用者的命名空間。

void setTestLogger(ITestLogger testLogger)

注入 ITestLogger 例項

void setTrackingSerial(String trackingSerial)

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

void setUseFastbootErase(boolean useFastbootErase)

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

void startLogcat()

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

boolean startTradeInModeTesting(int timeoutMs)

啟用測試換購模式。

boolean startUser(int userId)

如果指定使用者目前已停止,則會在背景啟動。

boolean startUser(int userId, boolean waitFlag)

如果指定使用者目前已停止,則會在背景啟動。

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

在指定螢幕上啟動指定使用者 (即允許使用者在該螢幕上啟動活動)。

void stopEmulatorOutput()

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

void stopLogcat()

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

void stopTradeInModeTesting()

停止測試換購模式。

boolean stopUser(int userId)

停止指定使用者。

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

停止特定使用者。

String switchToAdbTcp()

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

boolean switchToAdbUsb()

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

boolean switchUser(int userId)

切換至其他使用者 ID,並使用預設逾時。

boolean switchUser(int userId, long timeout)

在提供的逾時期限內切換至其他 userId。

boolean syncFiles(File localFileDir, String deviceFilePath)

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

Bugreport takeBugreport()

擷取錯誤報告,並在 Bugreport 物件中傳回,以進行處理。

String uninstallPackage(String packageName)

從裝置解除安裝 Android 套件。

String uninstallPackageForUser(String packageName, int userId)

為特定使用者從裝置解除安裝 Android 套件。

boolean unlockDevice()

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

void unmountDebugfs()

卸載 debugfs。

boolean waitForBootComplete(long timeOut)

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

boolean waitForDeviceAvailable()

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

boolean waitForDeviceAvailable(long waitTime)

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

boolean waitForDeviceAvailableInRecoverPath(long waitTime)

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

void waitForDeviceBootloader()

Blocks until device is visible via fastboot.

void waitForDeviceFastbootD()
boolean waitForDeviceInRecovery(long waitTime)

裝置處於「adb recovery」狀態時會遭到封鎖 (請注意,這與 IDeviceRecovery 不同)。

boolean waitForDeviceInSideload(long waitTime)

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

boolean waitForDeviceNotAvailable(long waitTime)

封鎖裝置,使其無法使用 (即從 adb 中遺失)

void waitForDeviceOnline()

Blocks until device is visible via adb.

void waitForDeviceOnline(long waitTime)

Blocks until device is visible via adb.

boolean waitForDeviceShell(long waitTime)

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

受保護的方法

void addExtraConnectionBuilderArgs(DefaultConnection.ConnectionBuilder builder)
String[] buildAdbShellCommand(String command, boolean forceExitStatusDetection)

為指定的 adb shell 指令工作階段和引數建構 OS 指令

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

建立 RebootDeviceAction,以便在執行重新啟動動作時使用。

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

執行 adb reboot。

void ensureRuntimePermissionSupported()

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

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

取得要使用的 RunUtil 執行個體。

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

從 ddmlib 快取擷取裝置屬性 (預設),並視裝置是否處於 Fastboot 狀態,還原為 `adb shell getprop` 或 `fastboot getvar`。

boolean isInRebootCallback()

傳回目前是否正在執行重新啟動回呼。

boolean isNewer(File localFile, IFileEntry entry)

如果本機檔案比遠端檔案新,則傳回 true

void notifyRebootEnded()

通知所有 IDeviceActionReceiver有關重新啟動結束事件。

void notifyRebootStarted()

通知所有 IDeviceActionReceiver 重新啟動事件。

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

對這部裝置執行動作。

void postAdbReboot(NativeDevice.RebootMode rebootMode)

重新啟動後可能可以執行的額外動作。

void prePostBootSetup()

允許每種裝置類型 (AndroidNativeDevice、TestDevice) 覆寫此方法,以進行特定的開機後設定。

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

設定要使用的 Clock 執行個體。

void setMicrodroidProcess(Process process)

將 TestDevice 標示為 microdroid,並設定其 CID。

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

使用環境變數執行簡單的 Fastboot 指令,並回報指令狀態。

CommandResult simpleFastbootCommand(long timeout, String[] fullCmd)

執行簡單的 Fastboot 指令,並回報指令狀態。

boolean waitForDeviceNotAvailable(String operationDesc, long time)

等待裝置無法使用 (停止向 adb 回報)。

常數

DEBUGFS_PATH

public static final String DEBUGFS_PATH

常數值: "/sys/kernel/debug"

INVALID_USER_ID

public static final int INVALID_USER_ID

針對任何無效/找不到的使用者 ID 傳回的值:UserHandle 定義了 -10000 值

常數值: -10000 (0xffffd8f0)

MAX_HOST_DEVICE_TIME_OFFSET

protected static final long MAX_HOST_DEVICE_TIME_OFFSET

常數值: 5000 (0x0000000000001388)

MAX_RETRY_ATTEMPTS

protected static final int MAX_RETRY_ATTEMPTS

要執行的預設指令重試次數

常數值: 2 (0x00000002)

SD_CARD

protected static final String SD_CARD

常數值: "/sdcard/"

STORAGE_EMULATED

protected static final String STORAGE_EMULATED

常數值: "/storage/emulated/"

欄位

mOptions

protected TestDeviceOptions mOptions

mStateMonitor

protected final IDeviceStateMonitor mStateMonitor

公用建構函式

NativeDevice

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

建立 TestDevice

參數
device IDevice:相關聯的 IDevice

stateMonitor IDeviceStateMonitor:要使用的 IDeviceStateMonitor 機制

allocationMonitor IDeviceMonitorIDeviceMonitor,用於通知分配狀態變更。 可為空值

公用方法

batchPrefetchStartupBuildProps

public void batchPrefetchStartupBuildProps ()

微幅最佳化 (約 400 毫秒):預先擷取所有需要的屬性,而非針對每個屬性呼叫「adb getprop」。也就是說,擷取所有屬性的速度與擷取單一屬性一樣快。例如,device.getApiLevel()、checkApiLevelAgainstNextRelease 和 getBuildAlias 都會在幕後呼叫 `adb getprop`。我們會在一次呼叫中擷取這些屬性,並呼叫 NativeDevice.setProperty。 即使我們不這麼做,NativeDevice 本身也會呼叫 setProperty,並將結果快取以供日後呼叫。我們只是稍微提早進行。如果裝置處於復原模式,或是擷取屬性時發生其他錯誤,我們只會忽略這些錯誤。

canSwitchToHeadlessSystemUser

public boolean canSwitchToHeadlessSystemUser ()

傳回是否允許切換至無使用者介面系統使用者。

傳回
boolean

擲回
DeviceNotAvailableException

checkApiLevelAgainstNextRelease

public boolean checkApiLevelAgainstNextRelease (int strictMinLevel)

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

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

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

擲回
DeviceNotAvailableException

checkConnectivity

public boolean checkConnectivity ()

確認裝置已連上網路。

傳回
boolean true 如果裝置的網路連線正常, false 否則。

擲回
DeviceNotAvailableException

clearErrorDialogs

public boolean clearErrorDialogs ()

嘗試關閉裝置 UI 目前顯示的任何錯誤對話方塊。

傳回
boolean true 如果沒有對話方塊,或對話方塊已成功清除。 其他情況則為 false

擲回
DeviceNotAvailableException

clearLastConnectedWifiNetwork

public void clearLastConnectedWifiNetwork ()

清除上次連線的 Wi-Fi 網路。啟動新的叫用時,應呼叫此函式,避免裝置重新啟動後連線至先前測試使用的 Wi-Fi 網路。

clearLogcat

public void clearLogcat ()

刪除所有累積的 logcat 資料。

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

connectToWifiNetwork

public boolean connectToWifiNetwork ( wifiSsidToPsk, 
                boolean scanSsid)

連線至 Wi-Fi 網路。

開啟 Wi-Fi 並封鎖,直到與 wifiSsidToPsk 對應項中提供的其中一個 Wi-Fi 網路成功連線為止。連線建立後,執行個體會在每次重新啟動後嘗試還原連線,直到呼叫 ITestDevice.disconnectFromWifi()ITestDevice.clearLastConnectedWifiNetwork() 為止。

參數
wifiSsidToPsk :Wi-Fi SSID 對應密碼的地圖。

scanSsid boolean:是否掃描這個網路的隱藏 SSID。

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

connectToWifiNetwork

public boolean connectToWifiNetwork (String wifiSsid, 
                String wifiPsk)

連線至 Wi-Fi 網路。

開啟 Wi-Fi 並封鎖,直到成功連線至指定的 Wi-Fi 網路。 連線建立後,執行個體會在每次重新啟動後嘗試還原連線,直到呼叫 ITestDevice.disconnectFromWifi()ITestDevice.clearLastConnectedWifiNetwork() 為止。

參數
wifiSsid String:要連線的 Wi-Fi SSID

wifiPsk String:PSK 密碼片語,或未加密時為空值

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

connectToWifiNetwork

public boolean connectToWifiNetwork ( wifiSsidToPsk)

連線至 Wi-Fi 網路。

開啟 Wi-Fi 並封鎖,直到與 wifiSsidToPsk 對應項中提供的其中一個 Wi-Fi 網路成功連線為止。連線建立後,執行個體會在每次重新啟動後嘗試還原連線,直到呼叫 ITestDevice.disconnectFromWifi()ITestDevice.clearLastConnectedWifiNetwork() 為止。

參數
wifiSsidToPsk :Wi-Fi SSID 對應密碼的地圖。

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

connectToWifiNetwork

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

連線至 Wi-Fi 網路。

開啟 Wi-Fi 並封鎖,直到成功連線至指定的 Wi-Fi 網路。 連線建立後,執行個體會在每次重新啟動後嘗試還原連線,直到呼叫 ITestDevice.disconnectFromWifi()ITestDevice.clearLastConnectedWifiNetwork() 為止。

參數
wifiSsid String:要連線的 Wi-Fi SSID

wifiPsk String:PSK 密碼片語,或未加密時為空值

scanSsid boolean:是否掃描這個網路的隱藏 SSID。

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

connectToWifiNetworkIfNeeded

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

這個變體只會在裝置目前沒有網路連線時連線。connectToWifiNetwork(String, String)

參數
scanSsid boolean:是否掃描這個網路的隱藏 SSID

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

connectToWifiNetworkIfNeeded

public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk)

這個變體只會在裝置目前沒有網路連線時連線。connectToWifiNetwork(String, String)

傳回
boolean true (如果已成功連上 Wi-Fi 網路)。false 否則

擲回
DeviceNotAvailableException

createUser

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

使用指定名稱和提供的旗標建立使用者

參數
name String:要在裝置上建立的使用者

guest boolean:在建立期間啟用使用者旗標 --guest

ephemeral boolean:在建立期間啟用使用者旗標 --ephemeral

傳回
int 所建立使用者的 ID

擲回
DeviceNotAvailableException

createUser

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

使用指定名稱和提供的旗標建立使用者

參數
name String:要在裝置上建立的使用者

guest boolean:在建立期間啟用使用者旗標 --guest

ephemeral boolean:在建立期間啟用使用者旗標 --ephemeral

forTesting boolean:在建立期間啟用測試專用的旗標 --for-testing

傳回
int 所建立使用者的 ID

擲回
DeviceNotAvailableException

createUser

public int createUser (String name)

建立具有指定名稱和預設旗標 0 的使用者。

參數
name String:要在裝置上建立的使用者

傳回
int 建立的使用者 ID 整數

擲回
DeviceNotAvailableException

createUserNoThrow

public int createUserNoThrow (String name)

建立具有指定名稱和預設旗標 0 的使用者。

參數
name String:要在裝置上建立的使用者

傳回
int 建立的使用者 ID 整數,或錯誤時為 -1。

擲回
DeviceNotAvailableException

debugDeviceNotAvailable

public DeviceInspectionResult debugDeviceNotAvailable ()

檢查裝置,並在裝置無法使用時傳回詳細資訊。

傳回
DeviceInspectionResult

deleteFile

public void deleteFile (String deviceFilePath, 
                int userId)

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

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

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

擲回
DeviceNotAvailableException

deleteFile

public void deleteFile (String deviceFilePath)

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

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

擲回
DeviceNotAvailableException

deregisterDeviceActionReceiver

public void deregisterDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

移除已註冊的 IDeviceActionReceiver

參數
deviceActionReceiver IDeviceActionReceiver:要移除的 IDeviceActionReceiver

deviceSoftRestarted

public 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 如果裝置已軟重新啟動

擲回
DeviceNotAvailableException

deviceSoftRestartedSince

public boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

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

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

擲回
DeviceNotAvailableException

disableAdbRoot

public boolean disableAdbRoot ()

關閉 adb root。

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

傳回
boolean true (如果成功)。

擲回
DeviceNotAvailableException

disableKeyguard

public void disableKeyguard ()

嘗試停用 Keyguard。

首先,請等待輸入調度作業準備就緒,這大約會在裝置回報 BOOT_COMPLETE 時發生 (顯然是非同步作業),因為目前的架構實作偶爾會出現競爭情況。然後傳送指令來關閉 Keyguard (僅適用於非安全裝置)

擲回
DeviceNotAvailableException

disableNetworkMonitor

public boolean disableNetworkMonitor ()

停用裝置上的網路監控功能。

傳回
boolean true (如果成功停用監控功能)。false (如果失敗)。

擲回
DeviceNotAvailableException

disconnectFromWifi

public boolean disconnectFromWifi ()

中斷 Wi-Fi 網路連線。

從已知網路清單中移除所有網路,並停用 Wi-Fi。

傳回
boolean true (如果已成功中斷 Wi-Fi 網路連線)。false if disconnect failed.

擲回
DeviceNotAvailableException

doesFileExist

public boolean doesFileExist (String deviceFilePath, 
                int userId)

輔助方法,用於判斷特定使用者的裝置上是否有檔案。

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

userId int:要檢查檔案是否存在的使用者 ID

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

擲回
DeviceNotAvailableException

doesFileExist

public boolean doesFileExist (String deviceFilePath)

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

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

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

擲回
DeviceNotAvailableException

dumpHeap

public File dumpHeap (String process, 
                String devicePath)

嘗試從 system_server 傾印堆積。呼叫端有責任清除傾印的檔案。

參數
process String:要傾印堆積的裝置程序名稱。

devicePath String:裝置上要放置傾印內容的路徑。這個位置必須是權限允許的位置。

傳回
File 包含報表的 ERROR(/File)。如果發生錯誤,則為空值。

擲回
DeviceNotAvailableException

enableAdbRoot

public boolean enableAdbRoot ()

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

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

傳回
boolean true (如果成功)。

擲回
DeviceNotAvailableException

enableNetworkMonitor

public boolean enableNetworkMonitor ()

在裝置上啟用網路監控功能。

傳回
boolean true 如果成功啟用監控,false (如果失敗)。

擲回
DeviceNotAvailableException

executeAdbCommand

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

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

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

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

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

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

擲回
DeviceNotAvailableException

executeAdbCommand

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

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

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

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

envMap :要為指令設定的環境

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

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

擲回
DeviceNotAvailableException

executeAdbCommand

public String executeAdbCommand (String... cmdArgs)

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

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

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

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

擲回
DeviceNotAvailableException

executeAdbV2Command

public CommandResult executeAdbV2Command (String... cmdArgs)

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

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

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

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

擲回
DeviceNotAvailableException

executeAdbV2Command

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

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

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

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

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

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

擲回
DeviceNotAvailableException

executeAdbV2Command

public CommandResult executeAdbV2Command (long timeout, 
                 envMap, 
                String... cmdArgs)

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

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

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

envMap :要為指令設定的環境

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

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

擲回
DeviceNotAvailableException

executeFastbootCommand

public CommandResult executeFastbootCommand (String... cmdArgs)

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

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

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

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException

executeFastbootCommand

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

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

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

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

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

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException

executeLongFastbootCommand

public CommandResult executeLongFastbootCommand (String... cmdArgs)

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

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

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

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException

executeLongFastbootCommand

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

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

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

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

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

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException

executeShellCommand

public String executeShellCommand (String command)

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

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

傳回
String 殼層輸出內容

擲回
DeviceNotAvailableException

executeShellCommand

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

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

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

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException

executeShellV2Command

public CommandResult executeShellV2Command (String cmd, 
                OutputStream pipeToOutput)

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

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

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

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException

executeShellV2Command

public CommandResult executeShellV2Command (String cmd, 
                File pipeAsInput)

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

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

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

傳回
CommandResult CommandResult的結果。

擲回
DeviceNotAvailableException

executeShellV2Command

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

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

傳回
CommandResult

擲回
DeviceNotAvailableException

executeShellV2Command

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

傳回
CommandResult

擲回
DeviceNotAvailableException

executeShellV2Command

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

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

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

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

傳回
CommandResult

擲回
DeviceNotAvailableException

executeShellV2Command

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

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

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

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

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

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

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

timeUnit TimeUnitmaxTimeToOutputShellResponse 的單位

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

傳回
CommandResult

擲回
DeviceNotAvailableException

fastbootWipePartition

public CommandResult fastbootWipePartition (String partition)

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

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

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

參數
partition String:要清除的分區

傳回
CommandResult 包含指令輸出的 CommandResult

擲回
DeviceNotAvailableException

getActiveApexes

public  getActiveApexes ()

擷取裝置上啟用的 APEX 相關資訊。

傳回
裝置目前已啟用 ERROR(/Set) 組 (共 ApexInfo 組)

擲回
DeviceNotAvailableException

getAdbPath

public String getAdbPath ()

傳回所用 adb 二進位檔的路徑。

傳回
String

getAllSettings

public  getAllSettings (String namespace)

傳回所要求命名空間的鍵/值組合。

參數
namespace String:必須是 {"system"、"secure"、"global"} 其中之一

傳回
鍵/值組合對應。如果系統不支援命名空間,則為空值。

擲回
DeviceNotAvailableException

getAllocationState

public DeviceAllocationState getAllocationState ()

傳回裝置的目前分配狀態

傳回
DeviceAllocationState

getAndroidId

public String getAndroidId (int userId)

尋找並傳回與 userId 相關聯的 android-id,如果找不到則傳回 null。

參數
userId int

傳回
String

擲回
DeviceNotAvailableException

getAndroidIds

public  getAndroidIds ()

建立與相符使用者 ID 對應的 Android ID 對應。無法保證每個使用者 ID 都能在這個函式中找到相關聯的 Android ID,因此部分使用者 ID 可能會比對到空值。

傳回
找到與使用者 ID 相符的 Android ID 對應表。

擲回
DeviceNotAvailableException

getApiLevel

public int getApiLevel ()

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

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

擲回
DeviceNotAvailableException

getAppPackageInfo

public PackageInfo getAppPackageInfo (String packageName)

擷取裝置上安裝的套件資訊。

參數
packageName String

傳回
PackageInfo 如果無法擷取資訊,則為 PackageInfonull

擲回
DeviceNotAvailableException

getAppPackageInfos

public  getAppPackageInfos ()

擷取裝置上安裝的套件資訊。

傳回
裝置上安裝的 ERROR(/List) 版本。PackageInfo

擲回
DeviceNotAvailableException

getBasebandVersion

public String getBasebandVersion ()

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

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

擲回
DeviceNotAvailableException

getBattery

public Integer getBattery ()

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

傳回
Integer

getBooleanProperty

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

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

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

擲回
DeviceNotAvailableException

getBootHistorySince

public  getBootHistorySince (long utcEpochTime, 
                TimeUnit timeUnit)

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

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

timeUnit TimeUnit:時間單位 TimeUnit

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

擲回
DeviceNotAvailableException

getBootloaderVersion

public String getBootloaderVersion ()

Convenience method to get the bootloader version of this device.

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

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

擲回
DeviceNotAvailableException

getBugreport

public InputStreamSource getBugreport ()

從裝置擷取錯誤報告。

保證這項實作項目在沒有 SD 卡的裝置上 (或 SD 卡尚未掛接時) 仍可繼續運作。

傳回
InputStreamSource InputStreamSource,可視需要產生錯誤報告內容。如果失敗,InputStreamSource 會產生空白 ERROR(/InputStream)

getBugreportz

public InputStreamSource getBugreportz ()

從裝置擷取錯誤報告。ZIP 格式的錯誤報告包含主要錯誤報告,以及有助於偵錯的其他記錄檔。

僅支援「adb version」> 1.0.36

傳回
InputStreamSource 包含 bugreportz 的 zip 檔案的 InputStreamSource,如果失敗則傳回空值。

getBuildAlias

public String getBuildAlias ()

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

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

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

擲回
DeviceNotAvailableException

getBuildFlavor

public String getBuildFlavor ()

擷取裝置的建構版本。

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

擲回
DeviceNotAvailableException

getBuildId

public String getBuildId ()

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

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

擲回
DeviceNotAvailableException

getBuildSigningKeys

public String getBuildSigningKeys ()

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

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

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

擲回
DeviceNotAvailableException

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor ()

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

傳回
DeviceDescriptor

getCachedDeviceDescriptor

public DeviceDescriptor getCachedDeviceDescriptor (boolean shortDescriptor)

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

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

傳回
DeviceDescriptor

getChildren

public String[] getChildren (String path)

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

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

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

擲回
DeviceNotAvailableException

getConnection

public AbstractConnection getConnection ()

與裝置相關聯的目前連線。

傳回
AbstractConnection

getContentProvider

public ContentProviderHandler getContentProvider (int userId)

傳回 ContentProviderHandler,如果無法使用則傳回空值。

如果先前使用相同的 userId 建構內容提供者,即可重複使用。

參數
userId int:用於初始化內容供應器的使用者 ID。

傳回
ContentProviderHandler

擲回
DeviceNotAvailableException

getCurrentFoldableState

public DeviceFoldableState getCurrentFoldableState ()

傳回裝置目前的折疊狀態,或在發生問題時傳回空值。

傳回
DeviceFoldableState

擲回
DeviceNotAvailableException

getCurrentUser

public int getCurrentUser ()

傳回目前執行使用者的 ID。如有錯誤,請傳回 -10000。

傳回
int

擲回
DeviceNotAvailableException

getDeviceClass

public String getDeviceClass ()

取得裝置類別。

傳回
String String 裝置類別。

getDeviceDate

public long getDeviceDate ()

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

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

擲回
DeviceNotAvailableException

getDeviceDescriptor

public DeviceDescriptor getDeviceDescriptor ()

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

傳回
DeviceDescriptor

getDeviceDescriptor

public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)

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

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

傳回
DeviceDescriptor

getDeviceState

public TestDeviceState getDeviceState ()

取得裝置狀態。

傳回
TestDeviceState

getDeviceTimeOffset

public long getDeviceTimeOffset (Date date)

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

參數
date Date

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

擲回
DeviceNotAvailableException

getEmulatorOutput

public InputStreamSource getEmulatorOutput ()

取得模擬器 stdout 和 stderr 的串流

傳回
InputStreamSource 模擬器輸出內容

getEmulatorProcess

public Process getEmulatorProcess ()

傳回與這個模擬器對應的 Process

傳回
Process Processnull

getExecuteShellCommandLog

public final File getExecuteShellCommandLog ()

包含所有 executeShellCommand(String) 記錄的記錄檔。

傳回
File

getExternalStoreFreeSpace

public long getExternalStoreFreeSpace ()

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

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

擲回
DeviceNotAvailableException

getFastbootPath

public String getFastbootPath ()

傳回所用快速啟動二進位檔的路徑。 仍須將 isFastbootEnabled() 設為 True,才能啟用 Fastboot 函式。

傳回
String

getFastbootProductType

public String getFastbootProductType ()

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

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

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

擲回
DeviceNotAvailableException

getFastbootProductVariant

public String getFastbootProductVariant ()

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

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

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

擲回
DeviceNotAvailableException

getFastbootSerialNumber

public String getFastbootSerialNumber ()

傳回快速啟動模式序號。

傳回
String

getFastbootVariable

public String getFastbootVariable (String variableName)

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

參數
variableName String:變數名稱

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

擲回
DeviceNotAvailableException

getFastbootVersion

public String getFastbootVersion ()

傳回所用 Fastboot 二進位檔的版本字串。如果發生錯誤,則為空值。

傳回
String

getFileEntry

public IFileEntry getFileEntry (String path)

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

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

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

擲回
DeviceNotAvailableException

getFileEntry

public IFileEntry getFileEntry (FileListingService.FileEntry entry)

非官方輔助程式,可從非根路徑取得 FileEntry。FIXME: Refactor the FileEntry system to have it available from any path. (即使未取得 Root 權限也一樣)。

參數
entry FileListingService.FileEntry:不一定是根層級,因為 Ddmlib 需要。FileEntry

傳回
IFileEntry 代表 FileEntry 的 FileEntryWrapper。

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

getFoldableStates

public  getFoldableStates ()

傳回裝置上的摺疊狀態清單。可使用「cmd device_state print-states」取得。

傳回

擲回
DeviceNotAvailableException

getIDevice

public IDevice getIDevice ()

傳回相關聯 ddmlib 的參照。IDevice

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

傳回
IDevice IDevice

getInstalledPackageNames

public  getInstalledPackageNames ()

擷取裝置上的應用程式套件名稱。

傳回
裝置上目前安裝的 ERROR(/Set) 個套件名稱。String

擲回
DeviceNotAvailableException

getIntProperty

public long getIntProperty (String name, 
                long defaultValue)

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

參數
name String:屬性名稱

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

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

擲回
DeviceNotAvailableException

getIpAddress

public String getIpAddress ()

取得裝置的 IP 位址。

傳回
String 裝置的 IP 位址,或 null (如果裝置沒有 IP 位址)

擲回
DeviceNotAvailableException

getKeyguardState

public KeyguardControllerState getKeyguardState ()

傳回物件即可取得 Keyguard 的目前狀態,如果系統不支援,則傳回空值。

傳回
KeyguardControllerState 包含 Keyguard 狀態快照的 KeyguardControllerState,如果系統不支援 Keyguard 查詢,則傳回 Null。

擲回
DeviceNotAvailableException

getLastExpectedRebootTimeMillis

public long getLastExpectedRebootTimeMillis ()

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

傳回
long

getLaunchApiLevel

public int getLaunchApiLevel ()

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

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

擲回
DeviceNotAvailableException

getLogcat

public InputStreamSource getLogcat ()

擷取 logcat 資料的快照串流。

支援兩種模式:

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

    傳回
    InputStreamSource

  • getLogcat

    public InputStreamSource getLogcat (int maxBytes)

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

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

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

    傳回
    InputStreamSource

    getLogcatDump

    public InputStreamSource getLogcatDump ()

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

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

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

    getLogcatSince

    public InputStreamSource getLogcatSince (long date)

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

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

    傳回
    InputStreamSource

    getMacAddress

    public String getMacAddress ()

    傳回裝置的 MAC 位址,如果無法從裝置查詢,則傳回空值。

    傳回
    String

    getMainUserId

    public Integer getMainUserId ()

    傳回主要使用者 ID。

    傳回
    Integer 主要使用者的 userId (如有),如果沒有主要使用者,則為空值。

    擲回
    DeviceNotAvailableException

    getMainlineModuleInfo

    public  getMainlineModuleInfo ()

    取得裝置上安裝的 Mainline 模組相關資訊。

    傳回
    裝置目前安裝的 ERROR(/Set)String主線模組。

    擲回
    DeviceNotAvailableException

    getMaxNumberOfRunningUsersSupported

    public int getMaxNumberOfRunningUsersSupported ()

    取得支援同時執行的使用者人數上限。預設為 0。

    傳回
    int 表示同時執行的使用者人數的整數

    擲回
    DeviceNotAvailableException

    getMaxNumberOfUsersSupported

    public int getMaxNumberOfUsersSupported ()

    取得支援的使用者人數上限。預設為 0。

    傳回
    int 整數,表示支援的使用者人數

    擲回
    DeviceNotAvailableException

    getMicrodroidProcess

    public Process getMicrodroidProcess ()

    傳回
    Process 傳回 Microdroid VM 的程序。如果 TestDevice 不是 Microdroid,則傳回空值。

    getMonitor

    public IDeviceStateMonitor getMonitor ()

    傳回與裝置相關聯的 IDeviceStateMonitor

    傳回
    IDeviceStateMonitor

    getMountPoint

    public String getMountPoint (String mountName)

    傳回掛接點。

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

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

    參數
    mountName String:掛接點名稱

    傳回
    String 掛接點或 null

    getMountPointInfo

    public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

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

    參數
    mountpoint String

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

    擲回
    DeviceNotAvailableException

    getMountPointInfo

    public  getMountPointInfo ()

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

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

    擲回
    DeviceNotAvailableException

    getOptions

    public TestDeviceOptions getOptions ()

    擷取裝置的測試選項。

    傳回
    TestDeviceOptions TestDeviceOptions 相關的裝置。

    getPartitionFreeSpace

    public long getPartitionFreeSpace (String partition)

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

    參數
    partition String

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

    擲回
    DeviceNotAvailableException

    getPrimaryUserId

    public Integer getPrimaryUserId ()

    傳回主要使用者 ID。

    傳回
    Integer 主要使用者的 userId (如有),如果沒有主要使用者,則為空值。

    擲回
    DeviceNotAvailableException

    getProcessByName

    public ProcessInfo getProcessByName (String processName)

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

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

    傳回
    ProcessInfo 指定 processName 的 ProcessInfo

    擲回
    DeviceNotAvailableException

    getProcessPid

    public String getProcessPid (String process)

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

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

    傳回
    String

    擲回
    DeviceNotAvailableException

    getProductType

    public String getProductType ()

    Convenience method to get the product type of this device.

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

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

    擲回
    DeviceNotAvailableException

    getProductVariant

    public String getProductVariant ()

    Convenience method to get the product variant of this device.

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

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

    擲回
    DeviceNotAvailableException

    getProperty

    public String getProperty (String name)

    從裝置擷取指定屬性值。

    參數
    name String:屬性名稱

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

    擲回
    DeviceNotAvailableException

    getRecoveryMode

    public ITestDevice.RecoveryMode getRecoveryMode ()

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

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

    getScreenshot

    public InputStreamSource getScreenshot (long displayId)

    從指定顯示器 ID 的裝置擷取螢幕截圖。格式為 PNG。

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

    參數
    displayId long:要擷取螢幕截圖的螢幕顯示 ID。

    傳回
    InputStreamSource 螢幕截圖的格式,或 null (如果螢幕截圖未成功)。InputStreamSource

    擲回
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot (String format)

    擷取裝置的螢幕截圖。 建議改用 getScreenshot(format),並採用 JPEG 編碼,以縮減大小

    參數
    format String:支援 PNG、JPEG

    傳回
    InputStreamSource 螢幕截圖的格式,或 null (如果螢幕截圖未成功)。InputStreamSource

    擲回
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot (String format, 
                    boolean rescale)

    擷取裝置的螢幕截圖。建議改用 getScreenshot(String),並採用 JPEG 編碼,以縮小大小。

    參數
    format String:支援 PNG、JPEG

    rescale boolean:是否應重新調整螢幕截圖大小,以縮減產生的圖片大小

    傳回
    InputStreamSource 螢幕截圖的格式,或 null (如果螢幕截圖未成功)。InputStreamSource

    擲回
    DeviceNotAvailableException

    getScreenshot

    public InputStreamSource getScreenshot ()

    擷取裝置的螢幕截圖。

    傳回
    InputStreamSource png 格式的螢幕截圖 InputStreamSource,或 null (如果螢幕截圖失敗)。

    擲回
    DeviceNotAvailableException

    getSerialNumber

    public String getSerialNumber ()

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

    傳回
    String String序號

    getSetting

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

    傳回所要求設定的值。 命名空間必須是「system」、「secure」或「global」其中之一

    參數
    userId int

    namespace String

    key String

    傳回
    String 與使用者命名空間:索引鍵相關聯的值。如果找不到,則為空值。

    擲回
    DeviceNotAvailableException

    getSetting

    public String getSetting (String namespace, 
                    String key)

    請參閱 getSetting(int, String, String),並在系統使用者上執行。

    參數
    namespace String

    key String

    傳回
    String

    擲回
    DeviceNotAvailableException

    getSimOperator

    public String getSimOperator ()

    如果無法使用或裝置無法使用,則傳回 SIM 卡業者或空值。

    傳回
    String

    getSimState

    public String getSimState ()

    傳回 SIM 卡狀態,如果無法使用或裝置無法使用,則傳回空值。

    傳回
    String

    getTombstones

    public  getTombstones ()

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

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

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

    擲回
    DeviceNotAvailableException

    getTotalMemory

    public long getTotalMemory ()

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

    傳回
    long

    getTrackingSerial

    public String getTrackingSerial ()

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

    傳回
    String

    getUninstallablePackageNames

    public  getUninstallablePackageNames ()

    擷取可解除安裝的應用程式套件名稱。目前定義為非系統套件和更新的系統套件。

    傳回
    裝置上目前安裝的ERROR(/Set)無法解除安裝String套件名稱。

    擲回
    DeviceNotAvailableException

    getUseFastbootErase

    public boolean getUseFastbootErase ()

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

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

    getUserFlags

    public int getUserFlags (int userId)

    尋找並傳回指定使用者的標記。 旗標定義於 Android 開放原始碼計畫的「android.content.pm.UserInfo」類別中。

    參數
    userId int

    傳回
    int 如果找到與所提供 userId 相關聯的旗標,則傳回這些旗標;否則傳回 -10000。

    擲回
    DeviceNotAvailableException

    getUserInfos

    public  getUserInfos ()

    取得裝置上 useId 對應 UserInfo 的對應項。如果裝置的輸出內容與預期不符,就會擲回 DeviceRuntimeException

    傳回
    UserInfo 物件清單。

    擲回
    DeviceNotAvailableException

    getUserSerialNumber

    public int getUserSerialNumber (int userId)

    如果找到與 userId 相關聯的序號,則傳回該序號;否則傳回 -10000。

    參數
    userId int

    傳回
    int

    擲回
    DeviceNotAvailableException

    handleAllocationEvent

    public IManagedTestDevice.DeviceEventResponse handleAllocationEvent (DeviceEvent event)

    處理指定的 DeviceEvent。可能將裝置轉換為新狀態。通知 IDeviceMonitor 所有狀態轉換。

    處理 DeviceEvent,這可能會將裝置轉換為新的分配狀態,也可能不會。

    參數
    event DeviceEvent

    傳回
    IManagedTestDevice.DeviceEventResponse

    hasFeature

    public boolean hasFeature (String feature)

    確認裝置是否支援某項功能。

    參數
    feature String:格式應為「feature:」或直接為「」。

    傳回
    boolean 如果找到特徵,則為 True,否則為 False。

    擲回
    DeviceNotAvailableException

    initializeConnection

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

    初始化與裝置的連線。這是由 preInvocationSetup 呼叫,但在極少數情況下,於裝置設定期間建立連線時,可能需要單獨呼叫。

    參數
    info IBuildInfo

    attributes MultiMap

    擲回
    DeviceNotAvailableException
    TargetSetupError

    installPackage

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

    在裝置上安裝 Android 套件。

    參數
    packageFile File:要安裝的 APK 檔案

    reinstall boolean:是否應執行重新安裝,true 表示是

    extraArgs String:要傳遞的選用額外引數。如要查看可用選項,請參閱「adb shell pm -h」。

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    installPackage

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

    在裝置上安裝 Android 套件。

    注意:只有在安裝時需要明確控管執行階段權限授予作業的用途,才應呼叫這個函式。

    參數
    packageFile File:要安裝的 APK 檔案

    reinstall boolean:是否應執行重新安裝,true 表示是

    grantPermissions boolean:是否應在安裝時授予所有執行階段權限

    extraArgs String:要傳遞的選用額外引數。如要查看可用選項,請參閱「adb shell pm -h」。

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    installPackageForUser

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

    在裝置上為特定使用者安裝 Android 套件。

    參數
    packageFile File:要安裝的 APK 檔案

    reinstall boolean:是否應執行重新安裝,true 表示是

    userId int:要安裝的整數使用者 ID。

    extraArgs String:要傳遞的選用額外引數。如要查看可用選項,請參閱「adb shell pm -h」。

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    installPackageForUser

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

    在裝置上為特定使用者安裝 Android 套件。

    注意:只有在安裝時需要明確控管執行階段權限授予作業的用途,才應呼叫這個函式。

    參數
    packageFile File:要安裝的 APK 檔案

    reinstall boolean:是否應執行重新安裝,true 表示是

    grantPermissions boolean:是否應在安裝時授予所有執行階段權限

    userId int:要安裝的整數使用者 ID。

    extraArgs String:要傳遞的選用額外引數。如要查看可用選項,請參閱「adb shell pm -h」。

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    installPackageWithIncrementalMode

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

    以漸進模式安裝 APK。

    參數
    apkFiles File:要安裝的 APK 檔案。

    extraArgs String

    userId String

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    invalidatePropertyCache

    public void invalidatePropertyCache ()

    isAdbRoot

    public boolean isAdbRoot ()

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isAdbTcp

    public boolean isAdbTcp ()

    傳回
    boolean

    isAppEnumerationSupported

    public boolean isAppEnumerationSupported ()

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

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

    擲回
    DeviceNotAvailableException

    isBypassLowTargetSdkBlockSupported

    public boolean isBypassLowTargetSdkBlockSupported ()

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

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

    擲回
    DeviceNotAvailableException

    isDebugfsMounted

    public boolean isDebugfsMounted ()

    檢查 debugfs 是否已掛接。

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

    擲回
    DeviceNotAvailableException

    isDeviceEncrypted

    public boolean isDeviceEncrypted ()

    傳回裝置是否已加密。

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

    擲回
    DeviceNotAvailableException

    isDirectory

    public boolean isDirectory (String path)

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

    參數
    path String

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isEnableAdbRoot

    public boolean isEnableAdbRoot ()

    傳回
    boolean true 是否要在裝置上啟用 adb root

    isEncryptionSupported

    public boolean isEncryptionSupported ()

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

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

    擲回
    DeviceNotAvailableException

    isExecutable

    public boolean isExecutable (String fullPath)

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

    參數
    fullPath String

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isFastbootEnabled

    public boolean isFastbootEnabled ()

    傳回裝置是否支援 Fastboot。

    傳回
    boolean

    isHeadless

    public boolean isHeadless ()

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

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isHeadlessSystemUserMode

    public boolean isHeadlessSystemUserMode ()

    傳回裝置是否使用無頭系統使用者模式。

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isMainUserPermanentAdmin

    public boolean isMainUserPermanentAdmin ()

    傳回主要使用者是否為永久管理員,且無法刪除或降級為非管理員狀態。

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isMultiUserSupported

    public boolean isMultiUserSupported ()

    判斷是否支援多位使用者。

    傳回
    boolean 如果支援多使用者,則為 true,否則為 false

    擲回
    DeviceNotAvailableException

    isPackageInstalled

    public boolean isPackageInstalled (String packageName, 
                    String userId)

    針對特定套件名稱和使用者 ID 查詢裝置,檢查該使用者目前是否已安裝應用程式。

    參數
    packageName String:我們要檢查是否已安裝的套件。

    userId String:我們要檢查套件是否已為該使用者安裝。如果為空值,系統會使用主要使用者零。

    傳回
    boolean 如果套件回報為已安裝,則為 True。否則傳回「false」。

    擲回
    DeviceNotAvailableException

    isPackageInstalled

    public boolean isPackageInstalled (String packageName)

    查詢裝置的指定套件名稱,檢查目前是否已安裝。

    參數
    packageName String

    傳回
    boolean 如果套件回報為已安裝,則為 True。否則傳回「false」。

    擲回
    DeviceNotAvailableException

    isRuntimePermissionSupported

    public boolean isRuntimePermissionSupported ()

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

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

    擲回
    DeviceNotAvailableException

    isStateBootloaderOrFastbootd

    public boolean isStateBootloaderOrFastbootd ()

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

    傳回
    boolean

    isUserRunning

    public boolean isUserRunning (int userId)

    檢查特定使用者是否正在執行。

    參數
    userId int

    傳回
    boolean 如果使用者正在跑步,則為 True;否則為 False。

    擲回
    DeviceNotAvailableException

    isUserSecondary

    public boolean isUserSecondary (int userId)

    根據指定使用者的旗標,傳回該使用者是否為次要使用者。

    參數
    userId int

    傳回
    boolean 如果使用者是次要使用者,則為 true,否則為 false。

    擲回
    DeviceNotAvailableException

    isUserVisible

    public boolean isUserVisible (int userId)

    檢查指定使用者是否可見。

    「可見」使用者是指與「真人」使用者互動的使用者,因此能夠啟動啟動活動 (通常是在預設螢幕上)。

    參數
    userId int

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isUserVisibleOnDisplay

    public boolean isUserVisibleOnDisplay (int userId, 
                    int displayId)

    檢查指定使用者是否在指定螢幕上可見。

    「可見」使用者是指與「真人」使用者互動的使用者,因此能夠在該螢幕中啟動活動。

    參數
    userId int

    displayId int

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isVisibleBackgroundUsersOnDefaultDisplaySupported

    public boolean isVisibleBackgroundUsersOnDefaultDisplaySupported ()

    傳回裝置是否允許使用者在 ERROR(/java.android.view.Display#DEFAULT_DISPLAY) 中啟動可見的背景服務。

    如果是,您可以呼叫 startVisibleBackgroundUser(int, int, boolean),並傳遞 listDisplayIdsForStartingVisibleBackgroundUsers() 傳回的顯示畫面 (應包含 ERROR(/java.android.view.Display#DEFAULT_DISPLAY))。

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isVisibleBackgroundUsersSupported

    public boolean isVisibleBackgroundUsersSupported ()

    傳回裝置是否允許使用者在背景啟動可見的應用程式。

    如果是,您可以呼叫 startVisibleBackgroundUser(int, int, boolean),並傳遞 listDisplayIdsForStartingVisibleBackgroundUsers() 傳回的顯示器。

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    isWifiEnabled

    public boolean isWifiEnabled ()

    測試 Wi-Fi 是否已啟用。

    檢查裝置是否已啟用 Wi-Fi。在不應使用 Wi-Fi 執行的測試 (例如行動數據測試) 之前,這項功能可用於判斷 Wi-Fi 狀態。

    傳回
    boolean true (如果已啟用 Wi-Fi)。false (如果已停用)

    擲回
    DeviceNotAvailableException

    listDisplayIds

    public  listDisplayIds ()

    收集裝置上「dumpsys SurfaceFlinger」回報的可用螢幕 ID 清單。

    傳回
    螢幕清單。Default 一律會傳回預設螢幕 0。

    擲回
    DeviceNotAvailableException

    listDisplayIdsForStartingVisibleBackgroundUsers

    public  listDisplayIdsForStartingVisibleBackgroundUsers ()

    取得可用於 start a user visible in the background 的螢幕清單。

    傳回

    擲回
    DeviceNotAvailableException

    listUsers

    public  listUsers ()

    取得裝置上的使用者清單。如果裝置的輸出內容與預期不符,系統會擲回 DeviceRuntimeException

    傳回
    使用者 ID 清單。

    擲回
    DeviceNotAvailableException

    logAnrs

    public boolean logAnrs (ITestLogger logger)

    收集並記錄裝置的 ANR。

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

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

    擲回
    DeviceNotAvailableException

    logBugreport

    public boolean logBugreport (String dataName, 
                    ITestLogger listener)

    輔助方法:擷取錯誤報告並記錄給回報者。

    參數
    dataName String:要回報錯誤報告的名稱。

    listener ITestLogger:用於記錄錯誤報告的 ITestLogger

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

    logOnDevice

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

    掛接 debugfs。

    擲回
    DeviceNotAvailableException

    nonBlockingReboot

    public void nonBlockingReboot ()

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

    擲回
    DeviceNotAvailableException

    postAdbRootAction

    public void postAdbRootAction ()

    如果裝置在 adb root 後和重新上線前需要執行特定動作,請覆寫此方法。預設實作方式不包含任何額外動作。這個階段不保證啟用 adb root。

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

    postAdbUnrootAction

    public void postAdbUnrootAction ()

    如果裝置需要在 adb 解除 Root 權限後,以及裝置重新上線前執行特定動作,請覆寫此方法。預設實作方式不包含任何額外動作。此階段無法保證停用 adb root。

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

    postBootSetup

    public void postBootSetup ()

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

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

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

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

    擲回
    DeviceNotAvailableException

    postInvocationTearDown

    public void postInvocationTearDown (Throwable exception)

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

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

    preInvocationSetup

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

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

    參數
    info IBuildInfo:裝置的 IBuildInfo

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

    擲回
    DeviceNotAvailableException
    TargetSetupError

    pullDir

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

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

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

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

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

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

    擲回
    DeviceNotAvailableException

    pullDir

    public boolean pullDir (String deviceFilePath, 
                    File localDir)

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

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

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

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

    擲回
    DeviceNotAvailableException

    pullFile

    public boolean pullFile (String remoteFilePath, 
                    File localFile)

    從裝置擷取檔案。

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

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

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

    擲回
    DeviceNotAvailableException

    pullFile

    public File pullFile (String remoteFilePath, 
                    int userId)

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

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

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

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

    擲回
    DeviceNotAvailableException

    pullFile

    public File pullFile (String remoteFilePath)

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

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

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

    擲回
    DeviceNotAvailableException

    pullFile

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

    從裝置擷取檔案。

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

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

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

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

    擲回
    DeviceNotAvailableException

    pullFileContents

    public String pullFileContents (String remoteFilePath)

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

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

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

    擲回
    DeviceNotAvailableException

    pullFileFromExternal

    public File pullFileFromExternal (String remoteFilePath)

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

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

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

    擲回
    DeviceNotAvailableException

    pushDir

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

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

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

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

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

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

    擲回
    DeviceNotAvailableException

    pushDir

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath)

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

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

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

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

    擲回
    DeviceNotAvailableException

    pushDir

    public boolean pushDir (File localFileDir, 
                    String deviceFilePath, 
                    int userId)

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

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

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

    userId int:要推送的使用者 ID

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

    擲回
    DeviceNotAvailableException

    pushFile

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

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

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

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

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

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

    擲回
    DeviceNotAvailableException

    pushFile

    public boolean pushFile (File localFile, 
                    String remoteFilePath)

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

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

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

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

    擲回
    DeviceNotAvailableException

    pushFile

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

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

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

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

    userId int:要推送的 userId

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

    擲回
    DeviceNotAvailableException

    pushString

    public boolean pushString (String contents, 
                    String remoteFilePath)

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

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

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

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

    擲回
    DeviceNotAvailableException

    重開。

    public void reboot (String reason)

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

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

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

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

    擲回
    DeviceNotAvailableException

    重開。

    public void reboot ()

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

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

    擲回
    DeviceNotAvailableException

    rebootIntoBootloader

    public void rebootIntoBootloader ()

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

    Blocks until device is in bootloader mode.

    擲回
    DeviceNotAvailableException

    rebootIntoFastbootd

    public void rebootIntoFastbootd ()

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

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

    擲回
    DeviceNotAvailableException

    rebootIntoRecovery

    public void rebootIntoRecovery ()

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

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

    擲回
    DeviceNotAvailableException

    rebootIntoSideload

    public void rebootIntoSideload ()

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

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

    擲回
    DeviceNotAvailableException

    rebootIntoSideload

    public void rebootIntoSideload (boolean autoReboot)

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

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

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

    擲回
    DeviceNotAvailableException

    rebootUntilOnline

    public void rebootUntilOnline ()

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

    擲回
    DeviceNotAvailableException

    rebootUntilOnline

    public void rebootUntilOnline (String reason)

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

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

    擲回
    DeviceNotAvailableException

    rebootUserspace

    public void rebootUserspace ()

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

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

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

    擲回
    DeviceNotAvailableException

    rebootUserspaceUntilOnline

    public void rebootUserspaceUntilOnline ()

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

    擲回
    DeviceNotAvailableException

    recoverDevice

    public boolean recoverDevice ()

    嘗試恢復裝置通訊。

    傳回
    boolean 如果嘗試復原且成功,則傳回 True;如果略過復原,則傳回 False

    擲回
    DeviceNotAvailableException 如果裝置已無法使用

    registerDeviceActionReceiver

    public void registerDeviceActionReceiver (IDeviceActionReceiver deviceActionReceiver)

    為這部裝置註冊 IDeviceActionReceiver

    裝置動作開始前和結束後,系統都會通知所有已註冊的 IDeviceActionReceiver

    參數
    deviceActionReceiver IDeviceActionReceiver:要註冊的 IDeviceActionReceiver

    remountSystemReadOnly

    public void remountSystemReadOnly ()

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

    擲回
    DeviceNotAvailableException

    remountSystemWritable

    public void remountSystemWritable ()

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

    擲回
    DeviceNotAvailableException

    remountVendorReadOnly

    public void remountVendorReadOnly ()

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

    擲回
    DeviceNotAvailableException

    remountVendorWritable

    public void remountVendorWritable ()

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

    擲回
    DeviceNotAvailableException

    removeAdmin

    public boolean removeAdmin (String componentName, 
                    int userId)

    移除指定使用者中指定的裝置管理員,如果成功則傳回 true,否則傳回 false

    參數
    componentName String:要移除的裝置管理員。

    userId int:裝置管理員所在的使用者。

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

    擲回
    DeviceNotAvailableException

    removeOwners

    public void removeOwners ()

    盡可能移除所有現有的裝置設定檔擁有者。

    擲回
    DeviceNotAvailableException

    removeUser

    public boolean removeUser (int userId)

    從裝置中移除指定使用者。

    參數
    userId int:要移除的使用者

    傳回
    boolean 如果成功移除使用者,則為 true,否則為 false。

    擲回
    DeviceNotAvailableException

    resetContentProviderSetup

    public void resetContentProviderSetup ()

    重設內容供應商設定的旗標,再次觸發設定。

    runInstrumentationTests

    public 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 boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                     listeners)

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

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

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

    參數
    runner IRemoteAndroidTestRunnerIRemoteAndroidTestRunner,用於執行測試

    listeners :測試結果監聽器

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

    擲回
    DeviceNotAvailableException

    runInstrumentationTestsAsUser

    public 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 boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, 
                    int userId, 
                    ITestLifeCycleReceiver... listeners)

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

    參數
    runner IRemoteAndroidTestRunner

    userId int

    listeners ITestLifeCycleReceiver

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    setAdbPath

    public void setAdbPath (String adbPath)

    設定要使用的 adb 二進位檔路徑。

    參數
    adbPath String

    setConfiguration

    public void setConfiguration (IConfiguration configuration)

    插入使用的 IConfiguration

    參數
    configuration IConfiguration

    setConnectionAvdInfo

    public final void setConnectionAvdInfo (GceAvdInfo avdInfo)

    參數
    avdInfo GceAvdInfo

    setDate

    public void setDate (Date date)

    在裝置上設定日期

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

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

    擲回
    DeviceNotAvailableException

    setDeviceOwner

    public boolean setDeviceOwner (String componentName, 
                    int userId)

    將裝置管理員元件設為指定使用者的裝置擁有者。

    參數
    componentName String:裝置管理員成為裝置擁有者。

    userId int:裝置擁有者居住的國家/地區。

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

    擲回
    DeviceNotAvailableException

    setDeviceState

    public void setDeviceState (TestDeviceState deviceState)

    更新裝置狀態。

    參數
    deviceState TestDeviceStateTestDeviceState

    setEmulatorOutputStream

    public void setEmulatorOutputStream (SizeLimitedOutputStream output)

    針對模擬器設定 SizeLimitedOutputStream,記錄輸出內容

    參數
    output SizeLimitedOutputStream:記錄輸出內容

    setEmulatorProcess

    public void setEmulatorProcess (Process p)

    如果這部裝置是模擬器,則設定 Process

    參數
    p Process

    setFastbootEnabled

    public void setFastbootEnabled (boolean fastbootEnabled)

    設定裝置的 Fastboot 選項。應在首次分配裝置時設定。

    參數
    fastbootEnabled boolean:裝置是否支援 Fastboot

    setFastbootPath

    public void setFastbootPath (String fastbootPath)

    設定要使用的 fastboot 二進位檔路徑。仍須將 isFastbootEnabled() 設為 True,才能啟用 Fastboot 函式。

    參數
    fastbootPath String

    setIDevice

    public void setIDevice (IDevice newDevice)

    更新與這個 ITestDevice 相關聯的 IDevice。

    新的 IDevice 必須參照與目前參照相同的實體裝置。如果 DDMS 已分配新的 IDevice,系統就會呼叫這個方法

    參數
    newDevice IDeviceIDevice

    setLogStartDelay

    public void setLogStartDelay (int delay)

    設定開始擷取線上裝置的 logcat 前,要等待的時間 (毫秒)。

    參數
    delay int:延遲時間 (毫秒)

    setOptions

    public void setOptions (TestDeviceOptions options)

    設定裝置的 TestDeviceOptions

    參數
    options TestDeviceOptions

    setProperty

    public boolean setProperty (String propKey, 
                    String propValue)

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

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

    propValue String:要設定的屬性值。

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

    擲回
    DeviceNotAvailableException

    setRecovery

    public void setRecovery (IDeviceRecovery recovery)

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

    參數
    recovery IDeviceRecoveryIDeviceRecovery

    setRecoveryMode

    public void setRecoveryMode (ITestDevice.RecoveryMode mode)

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

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

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

    setSetting

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

    請參閱 setSetting(int, String, String, String),並在系統使用者上執行。

    參數
    namespace String

    key String

    value String

    擲回
    DeviceNotAvailableException

    setSetting

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

    為特定使用者的命名空間新增設定值。部分設定必須重新啟動裝置後才能使用。命名空間必須是「system」、「secure」或「global」其中之一

    參數
    userId int

    namespace String

    key String

    value String

    擲回
    DeviceNotAvailableException

    setTestLogger

    public void setTestLogger (ITestLogger testLogger)

    插入 ITestLogger 例項

    參數
    testLogger ITestLogger

    setTrackingSerial

    public void setTrackingSerial (String trackingSerial)

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

    參數
    trackingSerial String

    setUseFastbootErase

    public void setUseFastbootErase (boolean useFastbootErase)

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

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

    startLogcat

    public void startLogcat ()

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

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

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

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

    startTradeInModeTesting

    public boolean startTradeInModeTesting (int timeoutMs)

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

    參數
    timeoutMs int

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

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

    startUser

    public boolean startUser (int userId)

    如果指定使用者目前已停止,則會在背景啟動。如果使用者已在背景執行,這個方法會是 NOOP。

    參數
    userId int:要在背景啟動的使用者

    傳回
    boolean 如果使用者已成功在背景啟動,則為 true。

    擲回
    DeviceNotAvailableException

    startUser

    public boolean startUser (int userId, 
                    boolean waitFlag)

    如果指定使用者目前已停止,則會在背景啟動。如果使用者已在背景執行,這個方法會是 NOOP。可提供額外旗標,等待作業生效。

    參數
    userId int:要在背景啟動的使用者

    waitFlag boolean:會讓指令等待使用者啟動並解鎖。

    傳回
    boolean 如果使用者已成功在背景啟動,則為 true。

    擲回
    DeviceNotAvailableException

    startVisibleBackgroundUser

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

    在指定螢幕中啟動指定使用者 (即允許使用者在該螢幕中啟動活動)。

    注意: 這項指令不會檢查使用者是否存在、顯示器是否可用、device supports such feature 等。

    參數
    userId int:要在背景啟動的使用者

    displayId int:要開始顯示的使用者可見內容

    waitFlag boolean:會讓指令等待使用者啟動並解鎖。

    傳回
    boolean true (如果使用者已成功在背景啟動可見的活動)。

    擲回
    DeviceNotAvailableException

    stopEmulatorOutput

    public void stopEmulatorOutput ()

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

    stopLogcat

    public void stopLogcat ()

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

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

    stopTradeInModeTesting

    public void stopTradeInModeTesting ()

    停止測試換購模式。

    擲回
    DeviceNotAvailableException

    stopUser

    public boolean stopUser (int userId)

    停止指定使用者。如果使用者已停止,這個方法會是 NOOP。 無法停止目前使用者和系統使用者。

    參數
    userId int:要停止的使用者。

    傳回
    boolean 如果使用者已成功停止,則為 true。

    擲回
    DeviceNotAvailableException

    stopUser

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

    停止特定使用者。可以提供額外旗標,等待作業生效,並強制終止使用者。無法停止目前使用者和系統使用者。

    參數
    userId int:要停止的使用者。

    waitFlag boolean:指令會等待使用者停止。

    forceFlag boolean:會強制停止使用者。

    傳回
    boolean 如果使用者已成功停止,則為 true。

    擲回
    DeviceNotAvailableException

    switchToAdbTcp

    public String switchToAdbTcp ()

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

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

    擲回
    DeviceNotAvailableException

    switchToAdbUsb

    public boolean switchToAdbUsb ()

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

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

    擲回
    DeviceNotAvailableException

    switchUser

    public boolean switchUser (int userId)

    切換至其他使用者 ID,並使用預設逾時。switchUser(int, long)

    參數
    userId int

    傳回
    boolean 如果新使用者 ID 與使用者 ID 供應商相符,則為 True。否則傳回「false」。

    擲回
    DeviceNotAvailableException

    switchUser

    public boolean switchUser (int userId, 
                    long timeout)

    在提供的逾時期限內切換至其他使用者 ID。 使用者變更成功後,嘗試停用 Keyguard。

    參數
    userId int

    timeout long:等待時間,之後會傳回 false,表示切換使用者失敗。

    傳回
    boolean 如果新使用者 ID 與使用者 ID 供應商相符,則為 True。否則傳回「false」。

    擲回
    DeviceNotAvailableException

    syncFiles

    public 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

    takeBugreport

    public Bugreport takeBugreport ()

    擷取錯誤報告,並在 Bugreport 物件中傳回,以進行處理。如有問題,則傳回空值。Bugreport 物件參照的檔案必須透過 Bugreport.close() 清理。

    傳回
    Bugreport

    uninstallPackage

    public String uninstallPackage (String packageName)

    從裝置解除安裝 Android 套件。

    參數
    packageName String:要解除安裝的 Android 套件

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    uninstallPackageForUser

    public String uninstallPackageForUser (String packageName, 
                    int userId)

    為特定使用者從裝置解除安裝 Android 套件。

    參數
    packageName String:要解除安裝的 Android 套件

    userId int:要解除安裝的整數使用者 ID。

    傳回
    String 如果成功,則為 null;如果失敗,則為含有錯誤代碼的 String

    擲回
    DeviceNotAvailableException

    unlockDevice

    public boolean unlockDevice ()

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

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

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

    擲回
    DeviceNotAvailableException

    unmountDebugfs

    public void unmountDebugfs ()

    卸載 debugfs。

    擲回
    DeviceNotAvailableException

    waitForBootComplete

    public boolean waitForBootComplete (long timeOut)

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

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

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

    擲回
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable ()

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

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

    擲回
    DeviceNotAvailableException

    waitForDeviceAvailable

    public boolean waitForDeviceAvailable (long waitTime)

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

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

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

    擲回
    DeviceNotAvailableException

    waitForDeviceAvailableInRecoverPath

    public boolean waitForDeviceAvailableInRecoverPath (long waitTime)

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

    參數
    waitTime long

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

    擲回
    DeviceNotAvailableException

    waitForDeviceBootloader

    public void waitForDeviceBootloader ()

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

    擲回
    DeviceNotAvailableException

    waitForDeviceFastbootD

    public void waitForDeviceFastbootD ()

    擲回
    DeviceNotAvailableException

    waitForDeviceInRecovery

    public boolean waitForDeviceInRecovery (long waitTime)

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

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

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

    waitForDeviceInSideload

    public boolean waitForDeviceInSideload (long waitTime)

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

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

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

    waitForDeviceNotAvailable

    public boolean waitForDeviceNotAvailable (long waitTime)

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

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

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

    waitForDeviceOnline

    public void waitForDeviceOnline ()

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

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

    擲回
    DeviceNotAvailableException

    waitForDeviceOnline

    public void waitForDeviceOnline (long waitTime)

    Blocks until device is visible via adb.

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

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

    擲回
    DeviceNotAvailableException

    waitForDeviceShell

    public boolean waitForDeviceShell (long waitTime)

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

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

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

    受保護的方法

    addExtraConnectionBuilderArgs

    protected void addExtraConnectionBuilderArgs (DefaultConnection.ConnectionBuilder builder)

    參數
    builder DefaultConnection.ConnectionBuilder

    buildAdbShellCommand

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

    為指定的 adb shell 指令工作階段和引數建構 OS 指令

    參數
    command String

    forceExitStatusDetection boolean

    傳回
    String[]

    checkApiLevelAgainst

    protected void checkApiLevelAgainst (String feature, 
                    int strictMinLevel)

    參數
    feature String

    strictMinLevel int

    createRebootDeviceAction

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

    建立 RebootDeviceAction,以便執行重新啟動動作。

    參數
    rebootMode NativeDevice.RebootMode:這次重新啟動的模式。

    reason String:這次重新啟動的原因。

    傳回
    NativeDevice.RebootDeviceAction 建立的 RebootDeviceAction

    createRunUtil

    protected IRunUtil createRunUtil ()

    傳回
    IRunUtil

    doAdbReboot

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

    執行 adb 重新啟動。

    參數
    rebootMode NativeDevice.RebootMode:這次重新啟動的模式。

    reason String:這次重新啟動的原因。

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

    ensureRuntimePermissionSupported

    protected void ensureRuntimePermissionSupported ()

    如果系統不支援執行階段權限,輔助方法會擲回例外狀況

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

    getApiLevelSafe

    protected int getApiLevelSafe ()

    傳回
    int

    getLogger

    protected ITestLogger getLogger ()

    傳回
    ITestLogger

    getRunUtil

    protected IRunUtil getRunUtil ()

    取得要使用的 RunUtil 執行個體。

    傳回
    IRunUtil

    internalGetProperty

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

    從 ddmlib 快取擷取裝置屬性,並視裝置是否處於 Fastboot 模式,還原為 `adb shell getprop` 或 `fastboot getvar`。

    參數
    propName String:裝置屬性的名稱,由 `adb shell getprop` 傳回

    fastbootVar String:要查詢的對等 Fastboot 變數名稱。如果為 null,系統不會嘗試 Fastboot 查詢

    description String:變數的簡單說明。第一個字母應為大寫。

    傳回
    String 字串 (可能為 null 或空白),內含指定屬性的值

    擲回
    DeviceNotAvailableException

    isInRebootCallback

    protected boolean isInRebootCallback ()

    傳回目前是否正在執行重新啟動回呼。如果為 true,則應停用所有重新啟動的公開 API。

    傳回
    boolean

    isNewer

    protected boolean isNewer (File localFile, 
                    IFileEntry entry)

    如果本機檔案比遠端檔案新,則傳回 trueIFileEntry,如果時間相同,系統會將檔案視為較新。

    參數
    localFile File

    entry IFileEntry

    傳回
    boolean

    notifyRebootEnded

    protected void notifyRebootEnded ()

    通知所有 IDeviceActionReceiver 重新啟動結束事件。

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

    notifyRebootStarted

    protected void notifyRebootStarted ()

    通知所有 IDeviceActionReceiver 重新啟動事件。

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

    performDeviceAction

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

    對這部裝置執行動作。嘗試復原裝置,並在動作失敗時選擇性地重試指令。

    參數
    actionDescription String:要執行的動作簡短說明。僅用於記錄。

    action NativeDevice.DeviceAction:要執行的動作

    retryAttempts int:如果動作失敗但復原成功,重試次數

    傳回
    boolean 如果動作順利完成,則為 true

    擲回
    DeviceNotAvailableException 如果復原嘗試失敗,或已達嘗試次數上限但仍未成功

    postAdbReboot

    protected void postAdbReboot (NativeDevice.RebootMode rebootMode)

    重新啟動後可能可以執行的額外動作。

    參數
    rebootMode NativeDevice.RebootMode

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

    prePostBootSetup

    protected void prePostBootSetup ()

    允許每個裝置類型 (AndroidNativeDevice、TestDevice) 覆寫這個方法,以進行特定開機後設定。

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

    pullFileInternal

    protected boolean pullFileInternal (String remoteFilePath, 
                    File localFile)

    參數
    remoteFilePath String

    localFile File

    傳回
    boolean

    擲回
    DeviceNotAvailableException

    setClock

    protected void setClock (Clock clock)

    設定要使用的 Clock 執行個體。

    參數
    clock Clock

    setMicrodroidProcess

    protected void setMicrodroidProcess (Process process)

    將 TestDevice 標示為 microdroid,並設定其 CID。

    參數
    process Process:Microdroid VM 的程序。

    setTestDeviceOptions

    protected void setTestDeviceOptions ( deviceOptions)

    參數
    deviceOptions

    simpleFastbootCommand

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

    使用環境變數執行簡單的 fastboot 指令,並回報指令狀態。

    參數
    timeout long

    envVarMap

    fullCmd String

    傳回
    CommandResult

    simpleFastbootCommand

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

    執行簡單的 Fastboot 指令,並回報指令狀態。

    參數
    timeout long

    fullCmd String

    傳回
    CommandResult

    waitForDeviceNotAvailable

    protected boolean waitForDeviceNotAvailable (String operationDesc, 
                    long time)

    等待裝置無法使用 (停止向 adb 回報)。

    參數
    operationDesc String:等待無法使用的作業名稱。

    time long:等待發生 unavailable 的時間。

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