NativeDevice
  public
  
  
  
  class
  NativeDevice
  
    extends Object
  
  
  
  
  
      implements
      
        IConfigurationReceiver, 
      
        IManagedTestDevice, 
      
        ITestLoggerReceiver
      
  
  
| java.lang.Object | |
| ↳ | com.android.tradefed.device.NativeDevice | 
ITestDevice 非完整堆疊 Android 裝置的預設實作方式。
摘要
| 常數 | |
|---|---|
| int | INVALID_USER_ID針對任何無效/找不到的使用者 ID 傳回的值:UserHandle 定義了 -10000 值 | 
| long | MAX_HOST_DEVICE_TIME_OFFSET
 | 
| int | MAX_RETRY_ATTEMPTS要執行的預設指令重試次數 | 
| 欄位 | |
|---|---|
| 
    public
    static
    final
    String | DEBUGFS_PATH
 | 
| 
    protected
    static
    final
    String | SD_CARD
 | 
| 
    protected
    static
    final
    String | STORAGE_EMULATED
 | 
| 
    protected
    
    
    TestDeviceOptions | mOptions
 | 
| 
    protected
    
    final
    IDeviceStateMonitor | mStateMonitor
 | 
| 公用建構函式 | |
|---|---|
| 
      NativeDevice(IDevice device, IDeviceStateMonitor stateMonitor, IDeviceMonitor allocationMonitor)
      建立  | |
| 公用方法 | |
|---|---|
| 
        
        
        
        
        
        void | 
      batchPrefetchStartupBuildProps()
      微最佳化 (約 400 毫秒),方法是預先擷取所需的所有 props,而非為每個 props 呼叫 'adb getprop'。 | 
| 
        
        
        
        
        
        boolean | 
      canSwitchToHeadlessSystemUser()
      傳回是否允許切換至無介面系統使用者。 | 
| 
        
        
        
        
        
        boolean | 
      checkApiLevelAgainstNextRelease(int strictMinLevel)
      檢查是否有任何功能目前支援最小支援級別。 | 
| 
        
        
        
        
        
        boolean | 
      checkConnectivity()
      確認裝置已連上網路。 | 
| 
        
        
        
        
        
        boolean | 
      clearErrorDialogs()
      嘗試關閉目前在裝置 UI 上顯示的任何錯誤對話方塊。 | 
| 
        
        
        
        
        
        void | 
      clearLastConnectedWifiNetwork()
      清除上次連線的 Wi-Fi 網路。 | 
| 
        
        
        
        
        
        void | 
      clearLogcat()
      刪除任何累積的 logcat 資料。 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetwork(連線至 Wi-Fi 網路。 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetwork(String wifiSsid, String wifiPsk)
      連線至 Wi-Fi 網路。 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetwork(連線至 Wi-Fi 網路。 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetwork(String wifiSsid, String wifiPsk, boolean scanSsid)
      連線至 Wi-Fi 網路。 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk, boolean scanSsid)
      
 | 
| 
        
        
        
        
        
        boolean | 
      connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk)
      
 | 
| 
        
        
        
        
        
        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)
      移除已註冊的  | 
| 
        
        
        
        
        
        boolean | 
      deviceSoftRestarted(ProcessInfo prevSystemServerProcess)
      輔助方法,可比較目前的 system_server 與先前的 system_server  | 
| 
        
        
        
        
        
        boolean | 
      deviceSoftRestartedSince(long utcEpochTime, TimeUnit timeUnit)
      輔助方法,用於檢查裝置是否在裝置和其  | 
| 
        
        
        
        
        
        boolean | 
      disableAdbRoot()
      關閉 ADB 根目錄。 | 
| 
        
        
        
        
        
        void | 
      disableKeyguard()
      嘗試停用鎖定畫面。 | 
| 
        
        
        
        
        
        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)
      輔助方法,可將 ADB 指令做為系統指令執行,並設有指定的逾時期限。 | 
| 
        
        
        
        
        
        String | 
      executeAdbCommand(long timeout, 輔助方法,可將 ADB 指令做為系統指令執行,並設有指定的逾時期限。 | 
| 
        
        
        
        
        
        String | 
      executeAdbCommand(String... cmdArgs)
      輔助方法,可將 ADB 指令視為系統指令執行。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeFastbootCommand(String... cmdArgs)
      輔助方法,可將 fastboot 指令做為系統指令執行,預設逾時時間為 2 分鐘。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeFastbootCommand(long timeout, String... cmdArgs)
      輔助方法,可將 fastboot 指令做為系統指令執行。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeLongFastbootCommand(String... cmdArgs)
      輔助方法,可將長時間執行的 fastboot 指令做為系統指令執行。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeLongFastbootCommand(輔助方法,可將長時間執行的 fastboot 指令做為系統指令,並搭配系統環境變數執行。 | 
| 
        
        
        
        
        
        String | 
      executeShellCommand(String command)
      執行 ADB 殼層指令並將輸出內容傳回為  | 
| 
        
        
        
        
        
        void | 
      executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        void | 
      executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeoutForCommand, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        void | 
      executeShellCommand(String command, IShellOutputReceiver receiver)
      執行指定的 ADB 殼層指令,如果指令失敗,則重試多次。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd)
      輔助方法,可執行 ADB 殼層指令,並將結果傳回為  | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, OutputStream pipeToOutput)
      輔助方法,可執行 ADB 殼層指令,並將結果傳回為  | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, File pipeAsInput)
      輔助方法,可執行 ADB 殼層指令,並將結果傳回為  | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, long maxTimeoutForCommand, TimeUnit timeUnit)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, File pipeAsInput, OutputStream pipeToOutput, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        CommandResult | 
      executeShellV2Command(String cmd, File pipeAsInput, OutputStream pipeToOutput, OutputStream pipeToError, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
      執行 ADB 殼層指令,並提供更多參數來控制指令行為。 | 
| 
        
        
        
        
        
        CommandResult | 
      fastbootWipePartition(String partition)
      裝置分區的輔助方法。 | 
| 
        
        
        
        
        
         | 
      getActiveApexes()
      擷取裝置上已啟用的 APEX 相關資訊。 | 
| 
        
        
        
        
        
         | 
      getAllSettings(String namespace)
      傳回要求命名空間的鍵/值組合。 | 
| 
        
        
        
        
        
        DeviceAllocationState | 
      getAllocationState()
      傳回裝置目前的分配狀態 | 
| 
        
        
        
        
        
        String | 
      getAndroidId(int userId)
      尋找並傳回與 userId 相關聯的 android-id,如果找不到,則傳回 null。 | 
| 
        
        
        
        
        
         | 
      getAndroidIds()
      建立地圖,找出與使用者 ID 相符的 Android ID。 | 
| 
        
        
        
        
        
        int | 
      getApiLevel()
      取得裝置 API 級別。 | 
| 
        
        
        
        
        
        PackageInfo | 
      getAppPackageInfo(String packageName)
      擷取裝置上已安裝套件的相關資訊。 | 
| 
        
        
        
        
        
         | 
      getAppPackageInfos()
      擷取裝置上已安裝套件的相關資訊。 | 
| 
        
        
        
        
        
        String | 
      getBasebandVersion()
      取得此裝置基頻 (無線電) 版本的簡便方法。 | 
| 
        
        
        
        
        
        Integer | 
      getBattery()
      傳回裝置目前的電池電量,如果無法取得電池電量,則傳回 Null。 | 
| 
        
        
        
        
        
        boolean | 
      getBooleanProperty(String name, boolean defaultValue)
      傳回指定屬性的布林值。 | 
| 
        
        
        
        
        
         | 
      getBootHistory()
      輔助方法會收集啟動時間和啟動原因的啟動記錄地圖。 | 
| 
        
        
        
        
        
         | 
      getBootHistorySince(long utcEpochTime, TimeUnit timeUnit)
      輔助方法會收集啟動歷史地圖,其中包含從裝置的紀元起算的指定時間,以及指定的時間單位和啟動時間和啟動原因。 | 
| 
        
        
        
        
        
        String | 
      getBootloaderVersion()
      取得此裝置的系統啟動載入程式版本的便利方法。 | 
| 
        
        
        
        
        
        InputStreamSource | 
      getBugreport()
      從裝置擷取錯誤報告。 | 
| 
        
        
        
        
        
        InputStreamSource | 
      getBugreportz()
      從裝置擷取 bugreportz。 | 
| 
        
        
        
        
        
        String | 
      getBuildAlias()
      擷取裝置目前執行的版本別名。 | 
| 
        
        
        
        
        
        String | 
      getBuildFlavor()
      擷取裝置的版本風味。 | 
| 
        
        
        
        
        
        String | 
      getBuildId()
      擷取裝置目前執行的版本。 | 
| 
        
        
        
        
        
        String | 
      getBuildSigningKeys()
      傳回用於簽署裝置映像檔的金鑰類型 通常 Android 裝置會使用測試金鑰 (例如 AOSP) 或發布金鑰 (由個別裝置製造商控制) 進行簽署 | 
| 
        
        
        
        
        
        DeviceDescriptor | 
      getCachedDeviceDescriptor()
      如果已分配裝置,則會傳回快取的  | 
| 
        
        
        
        
        
        DeviceDescriptor | 
      getCachedDeviceDescriptor(boolean shortDescriptor)
      如果已分配裝置,則會傳回快取的  | 
| 
        
        
        
        
        
        String[] | 
      getChildren(String path)
      使用  | 
| 
        
        
        
        
        
        AbstractConnection | 
      getConnection()
      與裝置相關聯的目前連線。 | 
| 
        
        
        
        
        
        ContentProviderHandler | 
      getContentProvider(int userId)
      傳回  | 
| 
        
        
        
        
        
        DeviceFoldableState | 
      getCurrentFoldableState()
      傳回裝置目前的折疊狀態,如果發生某些問題,則傳回 null。 | 
| 
        
        
        
        
        
        int | 
      getCurrentUser()
      傳回目前執行使用者的 ID。 | 
| 
        
        
        
        
        
        String | 
      getDeviceClass()
      取得裝置類別。 | 
| 
        
        
        
        
        
        long | 
      getDeviceDate()
      以 Epoch 紀元時間為起點,以毫秒為單位傳回裝置的日期。 | 
| 
        
        
        
        
        
        DeviceDescriptor | 
      getDeviceDescriptor()
      從裝置資訊傳回  | 
| 
        
        
        
        
        
        DeviceDescriptor | 
      getDeviceDescriptor(boolean shortDescriptor)
      從裝置資訊傳回  | 
| 
        
        
        
        
        
        TestDeviceState | 
      getDeviceState()
      取得裝置狀態。 | 
| 
        
        
        
        
        
        long | 
      getDeviceTimeOffset(Date date)
      輔助函式,用於取得裝置與指定  | 
| 
        
        
        
        
        
        InputStreamSource | 
      getEmulatorOutput()
      取得模擬器 stdout 和 stderr 的串流 | 
| 
        
        
        
        
        
        Process | 
      getEmulatorProcess()
      傳回與此模擬器對應的  | 
| 
        
        
        
        final
        
        File | 
      getExecuteShellCommandLog()
      包含所有  | 
| 
        
        
        
        
        
        long | 
      getExternalStoreFreeSpace()
      輔助方法,用於判斷裝置外部儲存空間的可用空間大小。 | 
| 
        
        
        
        
        
        String | 
      getFastbootPath()
      傳回所用快速系統啟動二進位檔的路徑。 | 
| 
        
        
        
        
        
        String | 
      getFastbootProductType()
      在快速系統啟動模式下,取得裝置產品類型的便利方法。 | 
| 
        
        
        
        
        
        String | 
      getFastbootProductVariant()
      在快速系統啟動模式下,取得裝置產品類型的便利方法。 | 
| 
        
        
        
        
        
        String | 
      getFastbootSerialNumber()
      傳回快速啟動模式序號。 | 
| 
        
        
        
        
        
        String | 
      getFastbootVariable(String variableName)
      從裝置擷取指定的 fastboot 變數值。 | 
| 
        
        
        
        
        
        String | 
      getFastbootVersion()
      傳回所用 fastboot 二進位檔的版本字串。 | 
| 
        
        
        
        
        
        IFileEntry | 
      getFileEntry(String path)
      擷取裝置上遠端檔案的參照。 | 
| 
        
        
        
        
        
        IFileEntry | 
      getFileEntry(FileListingService.FileEntry entry)
      非官方輔助程式,可從非根目錄路徑取得  | 
| 
        
        
        
        
        
         | 
      getFoldableStates()
      傳回裝置上的可折疊狀態清單。 | 
| 
        
        
        
        
        
        IDevice | 
      getIDevice()
      傳回相關 ddmlib  | 
| 
        
        
        
        
        
         | 
      getInstalledPackageNames()
      擷取裝置上的應用程式套件名稱。 | 
| 
        
        
        
        
        
        long | 
      getIntProperty(String name, long defaultValue)
      傳回裝置中指定屬性的整數值。 | 
| 
        
        
        
        
        
        String | 
      getIpAddress()
      取得裝置的 IP 位址。 | 
| 
        
        
        
        
        
        KeyguardControllerState | 
      getKeyguardState()
      傳回物件,以取得 Keyguard 的目前狀態;如果不支援,則傳回空值。 | 
| 
        
        
        
        
        
        long | 
      getLastExpectedRebootTimeMillis()
      傳回 Tradefed API 上次觸發重新啟動作業的時間,以自  | 
| 
        
        
        
        
        
        int | 
      getLaunchApiLevel()
      取得裝置首次啟動的 API 級別。 | 
| 
        
        
        
        
        
        InputStreamSource | 
      getLogcat()
      擷取 logcat 資料的快照串流。 | 
| 
        
        
        
        
        
        InputStreamSource | 
      getLogcat(int maxBytes)
      擷取最後  | 
| 
        
        
        
        
        
        InputStreamSource | 
      getLogcatDump()
      取得裝置目前的 Logcat 傾印。 | 
| 
        
        
        
        
        
        InputStreamSource | 
      getLogcatSince(long date)
      擷取從指定日期開始的擷取 logcat 資料快照串流。 | 
| 
        
        
        
        
        
        String | 
      getMacAddress()
      傳回裝置的 MAC 位址,如果無法從裝置查詢,則傳回空值。 | 
| 
        
        
        
        
        
        Integer | 
      getMainUserId()
      傳回主要使用者 ID。 | 
| 
        
        
        
        
        
         | 
      getMainlineModuleInfo()
      取得裝置上已安裝的主線程模組相關資訊。 | 
| 
        
        
        
        
        
        int | 
      getMaxNumberOfRunningUsersSupported()
      取得支援的同時執行使用者人數上限。 | 
| 
        
        
        
        
        
        int | 
      getMaxNumberOfUsersSupported()
      取得支援的使用者人數上限。 | 
| 
        
        
        
        
        
        Process | 
      getMicrodroidProcess()
       | 
| 
        
        
        
        
        
        IDeviceStateMonitor | 
      getMonitor()
      傳回與裝置相關聯的  | 
| 
        
        
        
        
        
        String | 
      getMountPoint(String mountName)
      傳回掛接點。 | 
| 
        
        
        
        
        
        ITestDevice.MountPointInfo | 
      getMountPointInfo(String mountpoint)
      傳回與指定掛載點路徑相對應的  | 
| 
        
        
        
        
        
         | 
      getMountPointInfo()
      傳回裝置上 /proc/mounts 中剖析版本的資訊 | 
| 
        
        
        
        
        
        TestDeviceOptions | 
      getOptions()
      擷取裝置的測試選項。 | 
| 
        
        
        
        
        
        long | 
      getPartitionFreeSpace(String partition)
      輔助方法,用於判斷裝置分區的可用空間大小。 | 
| 
        
        
        
        
        
        Integer | 
      getPrimaryUserId()
      傳回主要使用者 ID。 | 
| 
        
        
        
        
        
        ProcessInfo | 
      getProcessByName(String processName)
      輔助方法會執行「pidof」和「stat」指令,並傳回含有 PID 和指定程序的程序開始時間的  | 
| 
        
        
        
        
        
        String | 
      getProcessPid(String process)
      傳回服務的 pid,如果發生錯誤則傳回 null。 | 
| 
        
        
        
        
        
        String | 
      getProductType()
      取得此裝置產品類型的便利方法。 | 
| 
        
        
        
        
        
        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)
      請參閱  | 
| 
        
        
        
        
        
        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 到  | 
| 
        
        
        
        
        
        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 套件。 | 
| 
        
        
        
        
        
        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)
      如果裝置上的檔案路徑是可執行檔案,則傳回「是」;否則傳回「否」。 | 
| 
        
        
        
        
        
        boolean | 
      isFastbootEnabled()
      傳回裝置是否可使用 Fastboot。 | 
| 
        
        
        
        
        
        boolean | 
      isHeadless()
      如果裝置是無頭裝置 (沒有螢幕),則傳回「是」,否則傳回「否」。 | 
| 
        
        
        
        
        
        boolean | 
      isHeadlessSystemUserMode()
      傳回裝置是否使用無頭系統使用者模式。 | 
| 
        
        
        
        
        
        boolean | 
      isMainUserPermanentAdmin()
      傳回主使用者是否為永久管理員,且無法刪除或降級為非管理員狀態。 | 
| 
        
        
        
        
        
        boolean | 
      isMultiUserSupported()
      判斷是否支援多位使用者。 | 
| 
        
        
        
        
        
        boolean | 
      isPackageInstalled(String packageName, String userId)
      針對裝置查詢指定的套件名稱和使用者 ID,檢查該使用者目前是否已安裝該套件。 | 
| 
        
        
        
        
        
        boolean | 
      isPackageInstalled(String packageName)
      針對裝置中的特定套件名稱執行查詢,確認目前是否已安裝該套件。 | 
| 
        
        
        
        
        
        boolean | 
      isRuntimePermissionSupported()
      檢查裝置上的平台是否支援授予執行階段權限 | 
| 
        
        
        
        
        
        boolean | 
      isStateBootloaderOrFastbootd()
      如果裝置處於  | 
| 
        
        
        
        
        
        boolean | 
      isUserRunning(int userId)
      檢查特定使用者是否正在執行。 | 
| 
        
        
        
        
        
        boolean | 
      isUserSecondary(int userId)
      根據指定使用者的標記,傳回該使用者是否為次要使用者。 | 
| 
        
        
        
        
        
        boolean | 
      isUserVisible(int userId)
      檢查指定使用者是否可見。 | 
| 
        
        
        
        
        
        boolean | 
      isUserVisibleOnDisplay(int userId, int displayId)
      檢查指定使用者是否在指定顯示畫面中顯示。 | 
| 
        
        
        
        
        
        boolean | 
      isVisibleBackgroundUsersOnDefaultDisplaySupported()
      傳回裝置是否允許使用者在  | 
| 
        
        
        
        
        
        boolean | 
      isVisibleBackgroundUsersSupported()
      傳回裝置是否允許使用者在背景啟動。 | 
| 
        
        
        
        
        
        boolean | 
      isWifiEnabled()
      測試是否已啟用 Wi-Fi。 | 
| 
        
        
        
        
        
         | 
      listDisplayIds()
      收集裝置上可用顯示器 ID 的清單,並由「dumpsys SurfaceFlinger」回報。 | 
| 
        
        
        
        
        
         | 
      listDisplayIdsForStartingVisibleBackgroundUsers()
      取得可用於  | 
| 
        
        
        
        
        
         | 
      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 根目錄後,且在裝置重新上線前執行特定動作,請覆寫此值。 | 
| 
        
        
        
        
        
        void | 
      postAdbUnrootAction()
      如果裝置需要在 adb 解除系統核心權限後,並在裝置重新上線前採取某些特定動作,請覆寫此值。 | 
| 
        
        
        
        
        
        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)
      從裝置中擷取檔案,將檔案儲存在本機暫存的  | 
| 
        
        
        
        
        
        File | 
      pullFile(String remoteFilePath)
      從裝置中擷取檔案,將檔案儲存在本機暫存的  | 
| 
        
        
        
        
        
        boolean | 
      pullFile(String remoteFilePath, File localFile, int userId)
      從裝置中擷取檔案。 | 
| 
        
        
        
        
        
        String | 
      pullFileContents(String remoteFilePath)
      從裝置中擷取檔案,並傳回內容。 | 
| 
        
        
        
        
        
        File | 
      pullFileFromExternal(String remoteFilePath)
      方便方法,可從裝置的外部儲存空間擷取檔案,將檔案儲存在本機暫時  | 
| 
        
        
        
        
        
        boolean | 
      pushDir(File localFileDir, String deviceFilePath, 遞迴將目錄內容推送至裝置,同時排除部分已篩選的目錄。 | 
| 
        
        
        
        
        
        boolean | 
      pushDir(File localFileDir, String deviceFilePath)
      遞迴地將目錄內容推送至裝置。 | 
| 
        
        
        
        
        
        boolean | 
      pushDir(File localFileDir, String deviceFilePath, int userId)
      遞迴地將目錄內容推送至裝置。 | 
| 
        
        
        
        
        
        boolean | 
      pushFile(File localFile, String remoteFilePath, boolean evaluateContentProviderNeeded)
      
 | 
| 
        
        
        
        
        
        boolean | 
      pushFile(File localFile, String remoteFilePath)
      將檔案推送至裝置。 | 
| 
        
        
        
        
        
        boolean | 
      pushFile(File localFile, String remoteFilePath, int userId)
      將檔案推送至裝置。 | 
| 
        
        
        
        
        
        boolean | 
      pushString(String contents, String remoteFilePath)
      將從字串建立的檔案推送至裝置 | 
| 
        
        
        
        
        
        void | 
      reboot(String reason)
      將裝置重新啟動至 ADB 模式,並使用指定的  | 
| 
        
        
        
        
        
        void | 
      reboot()
      重新啟動裝置並進入 ADB 模式。 | 
| 
        
        
        
        
        
        void | 
      rebootIntoBootloader()
      重新啟動裝置並進入系統啟動載入程式模式。 | 
| 
        
        
        
        
        
        void | 
      rebootIntoFastbootd()
      將裝置重新啟動為快速系統啟動模式。 | 
| 
        
        
        
        
        
        void | 
      rebootIntoRecovery()
      重新啟動裝置,進入 ADB 復原模式。 | 
| 
        
        
        
        
        
        void | 
      rebootIntoSideload()
      將裝置重新啟動至 ADB 側載模式 (請注意,這是復原模式下的特殊模式) 直到裝置進入側載模式為止 | 
| 
        
        
        
        
        
        void | 
      rebootIntoSideload(boolean autoReboot)
      將裝置重新啟動至 ADB 側載模式 (請注意,這是復原模式下的特殊模式) 直到裝置進入側載模式為止 | 
| 
        
        
        
        
        
        void | 
      rebootUntilOnline()
      
 | 
| 
        
        
        
        
        
        void | 
      rebootUntilOnline(String reason)
      
 | 
| 
        
        
        
        
        
        void | 
      rebootUserspace()
      僅重新啟動裝置的使用者空間部分。 | 
| 
        
        
        
        
        
        void | 
      rebootUserspaceUntilOnline()
      這是  | 
| 
        
        
        
        
        
        boolean | 
      recoverDevice()
      嘗試恢復裝置通訊。 | 
| 
        
        
        
        
        
        void | 
      registerDeviceActionReceiver(IDeviceActionReceiver deviceActionReceiver)
      為這部裝置註冊  | 
| 
        
        
        
        
        
        void | 
      remountSystemReadOnly()
      將裝置上的系統分區設為唯讀。 | 
| 
        
        
        
        
        
        void | 
      remountSystemWritable()
      讓裝置上的系統分區可供寫入。 | 
| 
        
        
        
        
        
        void | 
      remountVendorReadOnly()
      將裝置上的供應商分區設為唯讀。 | 
| 
        
        
        
        
        
        void | 
      remountVendorWritable()
      讓裝置上的供應商分區可供寫入。 | 
| 
        
        
        
        
        
        boolean | 
      removeAdmin(String componentName, int userId)
      從指定使用者中移除指定裝置管理員,如果成功,則傳回  | 
| 
        
        
        
        
        
        void | 
      removeOwners()
      盡力移除所有現有的裝置設定檔擁有者。 | 
| 
        
        
        
        
        
        boolean | 
      removeUser(int userId)
      從裝置中移除特定使用者。 | 
| 
        
        
        
        
        
        void | 
      resetContentProviderSetup()
      請重設內容供應器設定的旗標,以便再次觸發。 | 
| 
        
        
        
        
        
        boolean | 
      runInstrumentationTests(IRemoteAndroidTestRunner runner, ITestLifeCycleReceiver... listeners)
      方便方法,可使用一或多個以參數傳遞的事件監聽器執行  | 
| 
        
        
        
        
        
        boolean | 
      runInstrumentationTests(IRemoteAndroidTestRunner runner, 執行檢測設備測試,並提供裝置復原功能。 | 
| 
        
        
        
        
        
        boolean | 
      runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId,  | 
| 
        
        
        
        
        
        boolean | 
      runInstrumentationTestsAsUser(IRemoteAndroidTestRunner runner, int userId, ITestLifeCycleReceiver... listeners)
      與  | 
| 
        
        
        
        
        
        void | 
      setConfiguration(IConfiguration configuration)
      插入正在使用的  | 
| 
        
        
        
        final
        
        void | 
      setConnectionAvdInfo(GceAvdInfo avdInfo)
       | 
| 
        
        
        
        
        
        void | 
      setDate(Date date)
      設定裝置上的日期 注意:在裝置上設定日期需要取得 root 權限 | 
| 
        
        
        
        
        
        boolean | 
      setDeviceOwner(String componentName, int userId)
      將裝置管理員元件設為特定使用者的裝置擁有者。 | 
| 
        
        
        
        
        
        void | 
      setDeviceState(TestDeviceState deviceState)
      更新裝置狀態。 | 
| 
        
        
        
        
        
        void | 
      setEmulatorOutputStream(SizeLimitedOutputStream output)
      如要設定模擬器,請將  | 
| 
        
        
        
        
        
        void | 
      setEmulatorProcess(Process p)
      當裝置為模擬器時,會設定  | 
| 
        
        
        
        
        
        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)
      為裝置設定  | 
| 
        
        
        
        
        
        boolean | 
      setProperty(String propKey, String propValue)
      在裝置上設定指定的屬性值。 | 
| 
        
        
        
        
        
        void | 
      setRecovery(IDeviceRecovery recovery)
      設定要用於這部裝置的  | 
| 
        
        
        
        
        
        void | 
      setRecoveryMode(ITestDevice.RecoveryMode mode)
      設定裝置目前要使用的復原模式。 | 
| 
        
        
        
        
        
        void | 
      setSetting(String namespace, String key, String value)
      請參閱  | 
| 
        
        
        
        
        
        void | 
      setSetting(int userId, String namespace, String key, String value)
      將設定值新增至特定使用者的命名空間。 | 
| 
        
        
        
        
        
        void | 
      setTestLogger(ITestLogger testLogger)
      插入  | 
| 
        
        
        
        
        
        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)
      以提供的逾時期限做為期限,切換至其他使用者 ID。 | 
| 
        
        
        
        
        
        boolean | 
      syncFiles(File localFileDir, String deviceFilePath)
      將本機檔案目錄的內容以遞增方式同步至裝置。 | 
| 
        
        
        
        
        
        Bugreport | 
      takeBugreport()
      取得 bugreport,並在  | 
| 
        
        
        
        
        
        String | 
      uninstallPackage(String packageName)
      從裝置解除安裝 Android 套件。 | 
| 
        
        
        
        
        
        String | 
      uninstallPackageForUser(String packageName, int userId)
      針對特定使用者,從裝置上解除安裝 Android 套件。 | 
| 
        
        
        
        
        
        boolean | 
      unlockDevice()
      如果裝置處於加密狀態,則解鎖裝置。 | 
| 
        
        
        
        
        
        void | 
      unmountDebugfs()
      卸載 debugfs。 | 
| 
        
        
        
        
        
        boolean | 
      waitForBootComplete(long timeOut)
      阻斷,直到裝置的啟動完成標記設定為止。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceAvailable()
      等待裝置回應並可供測試。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceAvailable(long waitTime)
      等待裝置回應並可供測試。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceAvailableInRecoverPath(long waitTime)
      等待裝置回應並可使用,但不考慮復原路徑。 | 
| 
        
        
        
        
        
        void | 
      waitForDeviceBootloader()
      直到裝置可透過 fastboot 顯示為止。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceInRecovery(long waitTime)
      裝置必須處於「adb recovery」狀態才能執行的區塊 (請注意,這與  | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceInSideload(long waitTime)
      裝置必須處於「adb sideload」狀態才能執行的區塊 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceNotAvailable(long waitTime)
      無法使用的裝置區塊,例如 adb 中缺少的區塊 | 
| 
        
        
        
        
        
        void | 
      waitForDeviceOnline()
      直到裝置可透過 ADB 查看為止。 | 
| 
        
        
        
        
        
        void | 
      waitForDeviceOnline(long waitTime)
      直到裝置可透過 ADB 查看為止。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceShell(long waitTime)
      等待裝置回應基本 ADB 殼層指令。 | 
| 受保護的方法 | |
|---|---|
| 
        
        
        
        
        
        void | 
      addExtraConnectionBuilderArgs(DefaultConnection.ConnectionBuilder builder)
       | 
| 
        
        
        
        
        
        String[] | 
      buildAdbShellCommand(String command, boolean forceExitStatusDetection)
      為指定的 ADB 殼層指令工作階段和參數建構 OS 指令 | 
| 
        
        
        
        
        
        void | 
      checkApiLevelAgainst(String feature, int strictMinLevel)
       | 
| 
        
        
        
        
        
        NativeDevice.RebootDeviceAction | 
      createRebootDeviceAction(NativeDevice.RebootMode rebootMode, String reason)
      建立  | 
| 
        
        
        
        
        
        IRunUtil | 
      createRunUtil()
       | 
| 
        
        
        
        
        
        void | 
      doAdbReboot(NativeDevice.RebootMode rebootMode, String reason)
      執行 ADB 重新啟動。 | 
| 
        
        
        
        
        
        void | 
      ensureRuntimePermissionSupported()
      輔助方法,如果不支援執行階段權限,則擲回例外 | 
| 
        
        
        
        
        
        int | 
      getApiLevelSafe()
       | 
| 
        
        
        
        
        
        ITestLogger | 
      getLogger()
       | 
| 
        
        
        
        
        
        IRunUtil | 
      getRunUtil()
      取得要使用的  | 
| 
        
        
        
        
        
        String | 
      internalGetProperty(String propName, String fastbootVar, String description)
      預設會從 ddmlib 快取擷取裝置屬性,並視裝置是否處於 Fastboot 而改用 `adb shell getprop` 或 `fastboot getvar`。 | 
| 
        
        
        
        
        
        boolean | 
      isInRebootCallback()
      傳回目前是否正在執行重新啟動回呼。 | 
| 
        
        
        
        
        
        boolean | 
      isNewer(File localFile, IFileEntry entry)
      如果本機檔案較遠端檔案新,則傳回  | 
| 
        
        
        
        
        
        void | 
      notifyRebootEnded()
      通知所有  | 
| 
        
        
        
        
        
        void | 
      notifyRebootStarted()
      通知所有  | 
| 
        
        
        
        
        
        boolean | 
      performDeviceAction(String actionDescription, NativeDevice.DeviceAction action, int retryAttempts)
      在裝置上執行動作。 | 
| 
        
        
        
        
        
        void | 
      postAdbReboot()
      重新啟動後可採取的其他可能動作。 | 
| 
        
        
        
        
        
        void | 
      prePostBootSetup()
      允許每個裝置類型 (AndroidNativeDevice、TestDevice) 針對特定的開機後設定覆寫此方法。 | 
| 
        
        
        
        
        
        boolean | 
      pullFileInternal(String remoteFilePath, File localFile)
       | 
| 
        
        
        
        
        
        void | 
      setClock(Clock clock)
      設定要使用的時鐘例項。 | 
| 
        
        
        
        
        
        void | 
      setMicrodroidProcess(Process process)
      將 TestDevice 標示為 microdroid,並設定其 CID。 | 
| 
        
        
        
        
        
        void | 
      setTestDeviceOptions( | 
| 
        
        
        
        
        
        CommandResult | 
      simpleFastbootCommand(long timeout, 執行含有環境變數的簡單 fastboot 指令,並回報指令狀態。 | 
| 
        
        
        
        
        
        CommandResult | 
      simpleFastbootCommand(long timeout, String[] fullCmd)
      執行簡單的 fastboot 指令,並回報指令狀態。 | 
| 
        
        
        
        
        
        boolean | 
      waitForDeviceNotAvailable(String operationDesc, long time)
      等待裝置變成無法使用 (停止向 ADB 回報)。 | 
常數
INVALID_USER_ID
public static final int INVALID_USER_ID
針對任何無效/找不到的使用者 ID 傳回的值:UserHandle 定義了 -10000 值
常數值: -10000 (0xffffd8f0)
MAX_HOST_DEVICE_TIME_OFFSET
protected static final long MAX_HOST_DEVICE_TIME_OFFSET
常數值: 5000 (0x0000000000001388)
MAX_RETRY_ATTEMPTS
protected static final int MAX_RETRY_ATTEMPTS
預設要執行的指令重試次數
常數值: 2 (0x00000002)
欄位
DEBUGFS_PATH
public static final String DEBUGFS_PATH
SD_CARD
protected static final String SD_CARD
STORAGE_EMULATED
protected static final String STORAGE_EMULATED
公用建構函式
NativeDevice
public NativeDevice (IDevice device, 
                IDeviceStateMonitor stateMonitor, 
                IDeviceMonitor allocationMonitor)建立 TestDevice。
| 參數 | |
|---|---|
| device | IDevice:相關聯的IDevice | 
| stateMonitor | IDeviceStateMonitor:要使用的IDeviceStateMonitor機制 | 
| allocationMonitor | IDeviceMonitor:用於通知分配狀態變更的IDeviceMonitor。可為空值 | 
公用方法
batchPrefetchStartupBuildProps
public void batchPrefetchStartupBuildProps ()
微最佳化 (約 400 毫秒),方法是預先擷取所需的所有 props,而非為每個 props 呼叫 'adb getprop'。也就是說,擷取所有屬性和擷取單一屬性一樣快速。像是 device.getApiLevel()、checkApiLevelAgainstNextRelease 和 getBuildAlias 等,都會在幕後呼叫 `adb getprop`。我們會在一個呼叫中擷取這些值,並呼叫 NativeDevice.setProperty。即使我們不這樣做,NativeDevice 本身也會呼叫 setProperty,並將結果快取供日後呼叫使用。只是稍早實施。如果裝置處於復原狀態,或擷取 props 時發生其他錯誤,我們會直接忽略這些錯誤。
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 網路。falseotherwise | 
| 擲回 | |
|---|---|
| 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 網路。falseotherwise | 
| 擲回 | |
|---|---|
| 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 網路。falseotherwise | 
| 擲回 | |
|---|---|
| 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 網路。falseotherwise | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
connectToWifiNetworkIfNeeded
public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk, 
                boolean scanSsid)connectToWifiNetwork(String, String) 的變化版本,只會在裝置目前沒有網路連線時連線。
| 參數 | |
|---|---|
| scanSsid | boolean:是否掃描此網路的隱藏 SSID | 
| 傳回 | |
|---|---|
| boolean | true已成功連上 Wi-Fi 網路。falseotherwise | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
connectToWifiNetworkIfNeeded
public boolean connectToWifiNetworkIfNeeded (String wifiSsid, 
                String wifiPsk)connectToWifiNetwork(String, String) 的變化版本,只會在裝置目前沒有網路連線時連線。
| 傳回 | |
|---|---|
| boolean | true已成功連上 Wi-Fi 網路。falseotherwise | 
| 擲回 | |
|---|---|
| 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)
輔助方法,可比較目前的 system_server 與先前的 system_server ProcessInfo,檢查裝置是否已軟重啟。使用 getProcessByName(String) 可取得 ProcessInfo。
| 參數 | |
|---|---|
| prevSystemServerProcess | ProcessInfo:先前的 system_server 程序ProcessInfo。 | 
| 傳回 | |
|---|---|
| boolean | true裝置是否已軟體重新啟動 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
deviceSoftRestartedSince
public boolean deviceSoftRestartedSince (long utcEpochTime, 
                TimeUnit timeUnit)輔助方法,用於檢查裝置和其 ERROR(/TimeUnit) 自紀元時間起算的 UTC 時間是否已軟重啟。軟重啟是指在裝置強制重啟 (例如:要求重啟) 之外重新啟動 system_server。您可以使用 getDeviceDate() 方法,取得目前裝置的 utcEpochTime 以毫秒為單位。
| 參數 | |
|---|---|
| utcEpochTime | long:裝置時間,從紀元時間起算的秒數。 | 
| timeUnit | TimeUnit:指定 utcEpochTime 的時間單位TimeUnit。 | 
| 傳回 | |
|---|---|
| boolean | true裝置是否已軟體重新啟動 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
disableAdbRoot
public boolean disableAdbRoot ()
關閉 ADB 根目錄。
停用 ADB 根目錄可能會導致裝置與 ADB 斷開連線。這個方法會在裝置可用之前阻斷。
| 傳回 | |
|---|---|
| boolean | true(如果成功)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
disableKeyguard
public void disableKeyguard ()
嘗試停用鎖定畫面。
首先等待輸入調度作業就緒,這會在裝置回報 BOOT_COMPLETE 時發生,且顯然是非同步的,因為目前的架構實作有偶發的競爭狀態。接著,系統會傳送指令來關閉 Keyguard (僅適用於非安全的 Keyguard)
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
disableNetworkMonitor
public boolean disableNetworkMonitor ()
停用裝置上的網路監控功能。
| 傳回 | |
|---|---|
| boolean | true,表示監控功能已成功停用。false(如果失敗)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
disconnectFromWifi
public boolean disconnectFromWifi ()
中斷 Wi-Fi 網路連線。
從已知網路清單中移除所有網路,並停用 Wi-Fi。
| 傳回 | |
|---|---|
| boolean | true,如果已成功中斷 Wi-Fi 網路連線。false如果取消連線失敗。 | 
| 擲回 | |
|---|---|
| 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 根目錄。如果「enable-root」設定為「false」,則會記錄訊息並傳回,但不會啟用 root。
啟用 ADB 根目錄可能會導致裝置與 ADB 中斷連線。這個方法會在裝置可用之前阻斷。
| 傳回 | |
|---|---|
| boolean | true(如果成功)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
enableNetworkMonitor
public boolean enableNetworkMonitor ()
啟用裝置上的網路監控功能。
| 傳回 | |
|---|---|
| boolean | true表示已成功啟用監控功能。false(如果失敗)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeAdbCommand
public String executeAdbCommand (long timeout, 
                String... cmdArgs)輔助方法,可將 ADB 指令做為系統指令執行,並設有指定的逾時期限。
盡可能使用 executeShellCommand(String),因為該方法可提供更佳的失敗偵測和效能。
| 參數 | |
|---|---|
| timeout | long:裝置被視為無回應之前的時間 (以毫秒為單位),如果沒有逾時時間,則為 0L | 
| cmdArgs | String:要執行的 ADB 指令和引數 | 
| 傳回 | |
|---|---|
| String | 指令的 stdout。 null,如果指令無法執行。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeAdbCommand
public String executeAdbCommand (long timeout, 
                 envMap, 
                String... cmdArgs) 輔助方法,可將 ADB 指令做為系統指令執行,並設有指定的逾時期限。
盡可能使用 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 | |
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) 
輔助方法,可將長時間執行的 fastboot 指令做為系統指令,並搭配系統環境變數執行。
與 executeFastbootCommand(String) 相同,但使用較長的逾時時間。
| 參數 | |
|---|---|
| envVarMap | :fastboot 指令執行時使用的系統環境變數 | 
| cmdArgs | String:要執行的 Fastboot 指令和引數 | 
| 傳回 | |
|---|---|
| CommandResult | 包含指令輸出的 CommandResult | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellCommand
public String executeShellCommand (String command)
執行 ADB 殼層指令並以 String 格式傳回輸出的輔助方法。
| 參數 | |
|---|---|
| command | String:要執行的 ADB 殼層指令 | 
| 傳回 | |
|---|---|
| String | 殼層輸出 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellCommand
public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputShellResponse, 
                TimeUnit timeUnit, 
                int retryAttempts)執行 ADB 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| command | String:要執行的 ADB 殼層指令 | 
| receiver | IShellOutputReceiver:要將殼層輸出內容導向至的IShellOutputReceiver。 | 
| maxTimeToOutputShellResponse | long:指令允許不輸出任何回應的時間上限;單位如timeUnit所指定 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| retryAttempts | int:如果指令因例外狀況而失敗,則重試指令的次數上限。如果執行 retryAttempts 失敗,系統會擲回 DeviceNotResponsiveException。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellCommand
public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeoutForCommand, 
                long maxTimeToOutputShellResponse, 
                TimeUnit timeUnit, 
                int retryAttempts)執行 ADB 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| command | String:要執行的 ADB 殼層指令 | 
| receiver | IShellOutputReceiver:要將殼層輸出內容導向至的IShellOutputReceiver。 | 
| maxTimeoutForCommand | long:指令完成的最大逾時時間;單位為timeUnit中指定的單位 | 
| maxTimeToOutputShellResponse | long:指令允許不輸出任何回應的時間上限;單位為timeUnit中指定的單位 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| retryAttempts | int:如果指令因例外狀況而失敗,則重試指令的次數上限。如果執行 retryAttempts 失敗,系統會擲回 DeviceNotResponsiveException。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellCommand
public void executeShellCommand (String command, 
                IShellOutputReceiver receiver)執行指定的 ADB 殼層指令,如果指令失敗,則重試多次。
 executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, long, TimeUnit, int) 的簡易形式,含有預設值。
| 參數 | |
|---|---|
| command | String:要執行的 ADB 殼層指令 | 
| receiver | IShellOutputReceiver:要將殼層輸出內容導向至的IShellOutputReceiver。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd)
輔助方法,可執行 ADB 殼層指令,並將結果傳回為 CommandResult,並以適當方式填入指令狀態輸出內容、stdout 和 stderr。
| 參數 | |
|---|---|
| cmd | String:應執行的指令。 | 
| 傳回 | |
|---|---|
| CommandResult | CommandResult中的結果。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, OutputStream pipeToOutput)
輔助方法,可執行 ADB 殼層指令,並將結果傳回為 CommandResult,並以適當方式填入指令狀態輸出內容和 stderr。stdout 會導向至指定的串流。
| 參數 | |
|---|---|
| cmd | String:應執行的指令。 | 
| pipeToOutput | OutputStream:ERROR(/OutputStream)會重新導向 std 輸出內容,或為空值。 | 
| 傳回 | |
|---|---|
| CommandResult | CommandResult中的結果。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, File pipeAsInput)
輔助方法,可執行 ADB 殼層指令,並將結果傳回為 CommandResult,並以適當方式填入指令狀態輸出內容、stdout 和 stderr。
| 參數 | |
|---|---|
| cmd | String:應執行的指令。 | 
| pipeAsInput | File:會以管道輸送至指令做為輸入內容的ERROR(/File),或空值。 | 
| 傳回 | |
|---|---|
| CommandResult | CommandResult中的結果。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
執行 ADB 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| cmd | String:要執行的 ADB 殼層指令 | 
| maxTimeoutForCommand | long:指令完成的最大逾時時間;單位為timeUnit中指定的單位 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| retryAttempts | int:如果指令因例外狀況而失敗,則重試指令的次數上限。如果執行 retryAttempts 失敗,系統會擲回 DeviceNotResponsiveException。 | 
| 傳回 | |
|---|---|
| CommandResult | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, long maxTimeoutForCommand, TimeUnit timeUnit)
執行 ADB 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| cmd | String:要執行的 ADB 殼層指令 | 
| maxTimeoutForCommand | long:指令完成的最大逾時時間;單位為timeUnit中指定的單位 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| 傳回 | |
|---|---|
| CommandResult | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
executeShellV2Command
public CommandResult executeShellV2Command (String cmd, File pipeAsInput, OutputStream pipeToOutput, long maxTimeoutForCommand, TimeUnit timeUnit, int retryAttempts)
執行 ADB 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| cmd | String:要執行的 ADB 殼層指令 | 
| pipeAsInput | File:會以管道輸送至指令做為輸入內容的ERROR(/File),或空值。 | 
| pipeToOutput | OutputStream:ERROR(/OutputStream)會重新導向 std 輸出內容,或為空值。 | 
| maxTimeoutForCommand | long:指令完成的最大逾時時間;單位為timeUnit中指定的單位 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| 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 殼層指令,並提供更多參數來控制指令行為。
| 參數 | |
|---|---|
| cmd | String:要執行的 ADB 殼層指令 | 
| pipeAsInput | File:會傳送至指令做為輸入內容的ERROR(/File),或空值。 | 
| pipeToOutput | OutputStream:ERROR(/OutputStream)會重新導向 std 輸出內容,或為空值。 | 
| pipeToError | OutputStream:ERROR(/OutputStream),其中 std 錯誤會重新導向,或為空值。 | 
| maxTimeoutForCommand | long:指令完成的最大逾時時間;單位為timeUnit中指定的單位 | 
| timeUnit | TimeUnit:maxTimeToOutputShellResponse的單位 | 
| retryAttempts | int:如果指令因例外狀況而失敗,則重試指令的次數上限。如果執行 retryAttempts 失敗,系統會擲回 DeviceNotResponsiveException。 | 
| 傳回 | |
|---|---|
| CommandResult | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
fastbootWipePartition
public CommandResult fastbootWipePartition (String partition)
裝置分區的輔助方法。
 如果 getUseFastbootErase() 是 true,則會使用 fastboot erase 來清除分區。裝置必須在下次啟動時建立檔案系統。否則,系統會使用 fastboot 格式,在裝置上建立新的檔案系統。
應在裝置已進入快速系統啟動模式時使用。
| 參數 | |
|---|---|
| partition | String:要清除的分割區 | 
| 傳回 | |
|---|---|
| CommandResult | 包含指令輸出的 CommandResult | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getActiveApexes
publicgetActiveApexes () 
擷取裝置上已啟用的 APEX 相關資訊。
| 傳回 | |
|---|---|
|  | 目前在裝置上啟用的 ApexInfo的ERROR(/Set) | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getAllSettings
publicgetAllSettings (String namespace) 
傳回要求命名空間的鍵/值組合。
| 參數 | |
|---|---|
| namespace | String:必須是 {"system", "secure", "global"} 其中之一 | 
| 傳回 | |
|---|---|
|  | 鍵/值組合的對應關係。如果不支援命名空間,則為空值。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getAllocationState
public DeviceAllocationState getAllocationState ()
傳回裝置目前的分配狀態
| 傳回 | |
|---|---|
| DeviceAllocationState | |
getAndroidId
public String getAndroidId (int userId)
找出與 userId 相關聯的 android-id,並傳回該 ID。如果找不到,則傳回 null。
| 參數 | |
|---|---|
| userId | int | 
| 傳回 | |
|---|---|
| String | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getAndroidIds
publicgetAndroidIds () 
建立與使用者 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 | PackageInfo或null(如果無法擷取資訊) | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getAppPackageInfos
publicgetAppPackageInfos () 
擷取裝置上已安裝套件的相關資訊。
| 傳回 | |
|---|---|
|  | 裝置上安裝的 PackageInfoERROR(/List)。 | 
| 擲回 | |
|---|---|
| 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
publicgetBootHistory () 
輔助方法會收集啟動時間和啟動原因的啟動記錄地圖。
| 傳回 | |
|---|---|
|  | 開機時間 (從 Epoch 紀元時間起算,以世界標準時間秒為單位) 和開機原因對照表 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getBootHistorySince
publicgetBootHistorySince (long utcEpochTime, TimeUnit timeUnit) 
輔助方法會收集啟動記錄地圖,其中包含從裝置的紀元起算的指定時間,以及指定的時間單位和啟動時間和啟動原因。您可以使用 getDeviceDate() 方法,取得目前裝置的 utcEpochTime 以毫秒為單位。
| 參數 | |
|---|---|
| utcEpochTime | long:自 Epoch 起算的裝置時間。 | 
| timeUnit | TimeUnit:時間單位TimeUnit。 | 
| 傳回 | |
|---|---|
|  | 開機時間 (從 Epoch 紀元時間起算,以世界標準時間秒為單位) 和開機原因對照表 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getBootloaderVersion
public String getBootloaderVersion ()
取得此裝置的系統啟動載入程式版本的便利方法。
會嘗試從裝置的目前狀態擷取 Bootloader 版本。(例如,如果裝置處於快速系統啟動模式,則會嘗試從快速系統啟動模式擷取版本)
| 傳回 | |
|---|---|
| String | String系統啟動載入程式版本,如果找不到,則為null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getBugreport
public InputStreamSource getBugreport ()
從裝置中擷取錯誤報告。
這項功能的實作方式保證可在沒有 SD 卡 (或尚未掛載 SD 卡) 的裝置上繼續運作。
| 傳回 | |
|---|---|
| InputStreamSource | InputStreamSource會視需求產生錯誤報告內容。如果失敗,InputStreamSource會產生空白ERROR(/InputStream)。 | 
getBugreportz
public InputStreamSource getBugreportz ()
從裝置擷取 bugreportz。ZIP 格式錯誤報告包含主要錯誤報告和其他有助於偵錯的記錄檔案。
僅支援「adb 版本」> 1.0.36
| 傳回 | |
|---|---|
| InputStreamSource | 包含 bugreportz 的 ZIP 檔案的 InputStreamSource,如果失敗,則會傳回 null。 | 
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 | |
getContentProvider
public ContentProviderHandler getContentProvider (int userId)
傳回 ContentProviderHandler,如果無法取得則傳回空值。
如果內容提供者先前是使用相同的 userId 建構,則可重複使用。
| 參數 | |
|---|---|
| userId | int:用於初始化內容提供者的使用者 ID。 | 
| 傳回 | |
|---|---|
| ContentProviderHandler | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getCurrentFoldableState
public DeviceFoldableState getCurrentFoldableState ()
傳回裝置目前的折疊狀態,如果發生問題,則傳回 null。
| 傳回 | |
|---|---|
| DeviceFoldableState | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getCurrentUser
public int getCurrentUser ()
傳回目前執行中的使用者 ID。如果發生錯誤,請傳回 -10000。
| 傳回 | |
|---|---|
| int | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getDeviceDate
public long getDeviceDate ()
以 Epoch 紀元時間為起點,以毫秒為單位傳回裝置的日期。
| 傳回 | |
|---|---|
| long | 裝置的日期,以 Epoch 格式表示。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getDeviceDescriptor
public DeviceDescriptor getDeviceDescriptor ()
從裝置資訊傳回 DeviceDescriptor,即可取得相關資訊,而無須傳遞實際的裝置物件。
| 傳回 | |
|---|---|
| DeviceDescriptor | |
getDeviceDescriptor
public DeviceDescriptor getDeviceDescriptor (boolean shortDescriptor)
從裝置資訊傳回 DeviceDescriptor,即可取得相關資訊,而無須傳遞實際的裝置物件。
| 參數 | |
|---|---|
| shortDescriptor | boolean:是否將描述符限制為最少必要資訊 | 
| 傳回 | |
|---|---|
| DeviceDescriptor | |
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 | Process或null | 
getExecuteShellCommandLog
public final File getExecuteShellCommandLog ()
包含所有 executeShellCommand(String) 記錄的記錄。
| 傳回 | |
|---|---|
| File | |
getExternalStoreFreeSpace
public long getExternalStoreFreeSpace ()
輔助方法,用於判斷裝置外部儲存空間的可用空間大小。
| 傳回 | |
|---|---|
| long | 可用空間大小 (以 KB 為單位) | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getFastbootPath
public String getFastbootPath ()
傳回所用快速系統啟動模式二進位檔的路徑。仍需要將 isFastbootEnabled() 設為 True,才能啟用 fastboot 功能。
| 傳回 | |
|---|---|
| String | |
getFastbootProductType
public String getFastbootProductType ()
在裝置處於快速系統啟動模式時,取得裝置產品類型的便利方法。
 只有在裝置處於快速啟動模式時,才應使用此方法。在這種情況下,這個變化版本比一般 getProductType() 方法安全一些,因為如果裝置處於不正確狀態或無回應,ITestDevice 就會知道要將裝置復原為 fastboot。
| 傳回 | |
|---|---|
| String | String產品類型名稱,如果無法判斷,則為null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getFastbootProductVariant
public String getFastbootProductVariant ()
在裝置處於快速系統啟動模式時,取得裝置產品類型的便利方法。
 只有在裝置處於快速啟動模式時,才應使用此方法。在這種情況下,這個變化版本比一般 getProductType() 方法安全一些,因為如果裝置處於不正確狀態或無回應,ITestDevice 就會知道要將裝置復原為 fastboot。
| 傳回 | |
|---|---|
| String | String產品類型名稱,如果無法判斷,則為null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getFastbootSerialNumber
public String getFastbootSerialNumber ()
傳回快速啟動模式序號。
| 傳回 | |
|---|---|
| String | |
getFastbootVariable
public String getFastbootVariable (String variableName)
從裝置擷取指定的 fastboot 變數值。
| 參數 | |
|---|---|
| variableName | String:變數名稱 | 
| 傳回 | |
|---|---|
| String | 屬性值,如果不存在則為 null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getFastbootVersion
public String getFastbootVersion ()
傳回所用 fastboot 二進位檔的版本字串。或在發生錯誤時為空值。
| 傳回 | |
|---|---|
| String | |
getFileEntry
public IFileEntry getFileEntry (String path)
擷取裝置上遠端檔案的參照。
| 參數 | |
|---|---|
| path | String:要擷取的檔案路徑。可以是絕對路徑或相對於「/」的路徑 (也就是說,系統支援「/system」和「system」兩種語法) | 
| 傳回 | |
|---|---|
| IFileEntry | 如果找不到指定 path 的檔案,則為 IFileEntry或null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getFileEntry
public IFileEntry getFileEntry (FileListingService.FileEntry entry)
非官方輔助程式,可從非根目錄路徑取得 FileEntry。FIXME:重新整理 FileEntry 系統,讓系統可從任何路徑存取。(即使未取得 Root 權限也一樣)。
| 參數 | |
|---|---|
| entry | FileListingService.FileEntry:FileEntry不一定是 Ddmlib 所需的根目錄。 | 
| 傳回 | |
|---|---|
| IFileEntry | 代表 FileEntry 的 FileEntryWrapper。 | 
| 擲回 | |
|---|---|
|  | com.android.tradefed.device.DeviceNotAvailableException | 
| DeviceNotAvailableException | |
getFoldableStates
publicgetFoldableStates () 
傳回裝置上的摺疊式狀態清單。可使用「cmd device_state print-states」取得。
| 傳回 | |
|---|---|
|  | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getIDevice
public IDevice getIDevice ()
傳回相關 ddmlib IDevice 的參照。
 每次裝置從 ADB 中斷連線並重新連線時,DDMS 都可能會分配新的 IDevice。因此,呼叫端不應保留 IDevice 的參照,因為該參照可能會失效。
| 傳回 | |
|---|---|
| IDevice | IDevice | 
getInstalledPackageNames
publicgetInstalledPackageNames () 
擷取裝置上的應用程式套件名稱。
| 傳回 | |
|---|---|
|  | 目前裝置上已安裝的 String套件名稱的ERROR(/Set)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getIntProperty
public long getIntProperty (String name, 
                long defaultValue)傳回裝置中指定屬性的整數值。
| 參數 | |
|---|---|
| name | String:屬性名稱 | 
| defaultValue | long:如果屬性為空白或不存在,則傳回預設值。 | 
| 傳回 | |
|---|---|
| long | 屬性值或 defaultValue(如果屬性為空白、不存在或沒有整數值)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getIpAddress
public String getIpAddress ()
取得裝置的 IP 位址。
| 傳回 | |
|---|---|
| String | 裝置的 IP 位址,如果裝置沒有 IP 位址,則為 null | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getKeyguardState
public KeyguardControllerState getKeyguardState ()
傳回物件,以取得鍵盤鎖的目前狀態,如果不支援則傳回空值。
| 傳回 | |
|---|---|
| KeyguardControllerState | KeyguardControllerState包含 Keyguard 狀態的快照,如果不支援 Keyguard 查詢,則會傳回空值。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getLastExpectedRebootTimeMillis
public long getLastExpectedRebootTimeMillis ()
傳回 Tradefed API 上次觸發重新啟動作業的時間,以自 System.currentTimeMillis() 傳回的 EPOCH 起算的毫秒為單位。
| 傳回 | |
|---|---|
| long | |
getLaunchApiLevel
public int getLaunchApiLevel ()
取得裝置首次啟動的 API 級別。預設值為 UNKNOWN_API_LEVEL。
| 傳回 | |
|---|---|
| int | 整數,表示裝置首次啟動的 API 級別 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getLogcat
public InputStreamSource getLogcat ()
擷取 logcat 資料的快照串流。
可在兩種模式下運作:
TestDeviceOptions.getMaxLogcatDataSize() 個位元組| 傳回 | |
|---|---|
| InputStreamSource | |
getLogcat
public InputStreamSource getLogcat (int maxBytes)
擷取最後 maxBytes 筆擷取的 Logcat 資料的快照串流。
適用於您想經常擷取已擷取的 logcat 資料快照,但又不想因擷取整個 getLogcat() 快照而耗用大量磁碟空間的情況。
| 參數 | |
|---|---|
| maxBytes | int:傳回的資料數量上限。應為可輕鬆放入記憶體的數量 | 
| 傳回 | |
|---|---|
| InputStreamSource | |
getLogcatDump
public InputStreamSource getLogcatDump ()
取得裝置目前的 Logcat 轉儲檔案。與 getLogcat() 不同,這個方法一律會傳回 logcat 的靜態傾印。
缺點是,如果無法連線到裝置,就不會傳回任何內容。
| 傳回 | |
|---|---|
| InputStreamSource | InputStreamSource的 Logcat 資料。如果擷取 logcat 資料失敗,系統會傳回空白串流。 | 
getLogcatSince
public InputStreamSource getLogcatSince (long date)
擷取從指定日期開始的擷取 Logcat 資料快照串流。應使用裝置上的時間 getDeviceDate()。
| 參數 | |
|---|---|
| date | long:以 Epoch 格式表示的毫秒數,代表從何時開始擷取快照到目前的時間。(可使用「date +%s」取得) | 
| 傳回 | |
|---|---|
| InputStreamSource | |
getMacAddress
public String getMacAddress ()
傳回裝置的 MAC 位址,如果無法從裝置查詢,則傳回空值。
| 傳回 | |
|---|---|
| String | |
getMainUserId
public Integer getMainUserId ()
傳回主要使用者 ID。
| 傳回 | |
|---|---|
| Integer | 主要使用者的 userId (如果有),如果沒有主要使用者,則為空值。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getMainlineModuleInfo
publicgetMainlineModuleInfo () 
取得裝置上安裝的主線程式模組相關資訊。
| 傳回 | |
|---|---|
|  | String主線模組目前在裝置上安裝的ERROR(/Set)。 | 
| 擲回 | |
|---|---|
| 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 中的快取資訊無法使用,則直接查詢裝置。
 TODO:將此行為移至 IDevice.getMountPoint(String)
| 參數 | |
|---|---|
| mountName | String:掛接點的名稱 | 
| 傳回 | |
|---|---|
| String | 掛接點或 null | 
getMountPointInfo
public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)
傳回與指定掛載點路徑相對應的 MountPointInfo,如果該路徑沒有任何掛載項目,或未以掛載點的形式顯示在 /proc/mounts 中,則傳回 null。
| 參數 | |
|---|---|
| mountpoint | String | 
| 傳回 | |
|---|---|
| ITestDevice.MountPointInfo | MountPointInfo的ERROR(/List),其中包含「/proc/mounts」中的資訊 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getMountPointInfo
publicgetMountPointInfo () 
傳回裝置上 /proc/mounts 中剖析版本的資訊
| 傳回 | |
|---|---|
|  | MountPointInfo的ERROR(/List),其中包含「/proc/mounts」中的資訊 | 
| 擲回 | |
|---|---|
| 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 ()
取得裝置產品類型的便利方法。
裝置處於 ADB 或 Fastboot 模式時,這個方法就會生效。
| 傳回 | |
|---|---|
| String | String產品類型名稱。不會為空值 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getProductVariant
public String getProductVariant ()
取得此裝置產品子類的便利方法。
裝置處於 ADB 或 Fastboot 模式時,這個方法就會生效。
| 傳回 | |
|---|---|
| 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:擴充上述實作項目,以支援「format」和「rescale」
| 參數 | |
|---|---|
| displayId | long:要擷取螢幕截圖的螢幕顯示 ID。 | 
| 傳回 | |
|---|---|
| InputStreamSource | 以格式呈現的螢幕截圖 InputStreamSource,如果螢幕截圖未成功,則為null。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getScreenshot
public InputStreamSource getScreenshot (String format)
擷取裝置的螢幕截圖。建議使用 getScreenshot(format) 搭配 JPEG 編碼,以縮減檔案大小
| 參數 | |
|---|---|
| format | String:支援 PNG、JPEG | 
| 傳回 | |
|---|---|
| InputStreamSource | 以格式呈現的螢幕截圖 InputStreamSource,如果螢幕截圖未成功,則為null。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getScreenshot
public InputStreamSource getScreenshot (String format, boolean rescale)
擷取裝置的螢幕截圖。建議改用 getScreenshot(String) 搭配 JPEG 編碼,以縮小檔案大小。
| 參數 | |
|---|---|
| format | String:支援 PNG、JPEG | 
| rescale | boolean:是否應重新調整螢幕截圖,以縮小產生的圖片大小 | 
| 傳回 | |
|---|---|
| InputStreamSource | 以格式呈現的螢幕截圖 InputStreamSource,如果螢幕截圖未成功,則為null。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getScreenshot
public InputStreamSource getScreenshot ()
擷取裝置的螢幕截圖。
| 傳回 | |
|---|---|
| InputStreamSource | 以 png 格式提供螢幕截圖的 InputStreamSource,如果螢幕截圖未成功,則提供null。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getSetting
public String getSetting (int userId, 
                String namespace, 
                String key)傳回所要求設定的值。命名空間必須為下列其中一個:{"system", "secure", "global"}
| 參數 | |
|---|---|
| userId | int | 
| namespace | String | 
| key | String | 
| 傳回 | |
|---|---|
| String | 與使用者 namespace:key 相關聯的值。如果找不到,則為空值。 | 
| 擲回 | |
|---|---|
| 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
publicgetTombstones () 
從裝置擷取並傳回墓碑清單。需要取得 root 權限。
方法是盡力而為,因此如果一個墓碑因任何原因無法拉取,就不會出現在清單中。只有 DeviceNotAvailableException 會提早終止方法。
| 傳回 | |
|---|---|
|  | 墓碑檔案清單,如果沒有墓碑,則為空白。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getTotalMemory
public long getTotalMemory ()
以位元組為單位傳回實體記憶體總大小,如果發生內部錯誤,則傳回 -1
| 傳回 | |
|---|---|
| long | |
getTrackingSerial
public String getTrackingSerial ()
為進行裝置管理,請取得用於追蹤裝置的序號。
| 傳回 | |
|---|---|
| String | |
getUninstallablePackageNames
publicgetUninstallablePackageNames () 
擷取可解除安裝的應用程式套件名稱。目前定義為非系統套件和更新的系統套件。
| 傳回 | |
|---|---|
|  | ERROR(/Set)目前已安裝在裝置上的可解除安裝String套件名稱。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getUseFastbootErase
public boolean getUseFastbootErase ()
取得是否要使用 fastboot erase 或 fastboot format 來清除裝置上的分區。
| 傳回 | |
|---|---|
| boolean | 如果使用 Quickboot 清除格式,則為 true;如果使用 Fastboot 格式,則為false。 | 
getUserFlags
public int getUserFlags (int userId)
尋找並傳回特定使用者的標記。標記是在 Android 開放原始碼計畫的 "android.content.pm.UserInfo" 類別中定義。
| 參數 | |
|---|---|
| userId | int | 
| 傳回 | |
|---|---|
| int | 與提供的 userId 相關聯的標記 (如果找到的話),否則為 -10000。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
getUserInfos
publicgetUserInfos () 
取得裝置上 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 | 如果找到功能,則傳回「是」;否則傳回「否」。 | 
| 擲回 | |
|---|---|
| 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 | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| 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 | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
installPackageForUser
public String installPackageForUser (File packageFile, 
                boolean reinstall, 
                int userId, 
                String... extraArgs)為特定使用者在裝置上安裝 Android 套件。
| 參數 | |
|---|---|
| packageFile | File:要安裝的 APK 檔案 | 
| reinstall | boolean:true(如果應執行重新安裝作業) | 
| userId | int:要為其安裝的整數使用者 ID。 | 
| extraArgs | String:要傳遞的選用額外引數。如要瞭解可用的選項,請參閱「adb shell pm -h」。 | 
| 傳回 | |
|---|---|
| String | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
installPackageForUser
public String installPackageForUser (File packageFile, 
                boolean reinstall, 
                boolean grantPermissions, 
                int userId, 
                String... extraArgs)為特定使用者在裝置上安裝 Android 套件。
注意:只有需要在安裝時明確控制授予執行階段權限的用途,才應呼叫此函式。
| 參數 | |
|---|---|
| packageFile | File:要安裝的 APK 檔案 | 
| reinstall | boolean:true(如果應執行重新安裝作業) | 
| grantPermissions | boolean:是否應在安裝時授予所有執行階段權限 | 
| userId | int:要為其安裝的整數使用者 ID。 | 
| extraArgs | String:要傳遞的選用額外引數。如要瞭解可用的選項,請參閱「adb shell pm -h」。 | 
| 傳回 | |
|---|---|
| String | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
invalidatePropertyCache
public void invalidatePropertyCache ()
isAdbTcp
public boolean isAdbTcp ()
| 傳回 | |
|---|---|
| boolean | |
isAppEnumerationSupported
public boolean isAppEnumerationSupported ()
檢查裝置上的平台是否支援應用程式列舉
| 傳回 | |
|---|---|
| boolean | 如果支援應用程式列舉,則傳回「是」;否則傳回「否」 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
isBypassLowTargetSdkBlockSupported
public boolean isBypassLowTargetSdkBlockSupported ()
檢查裝置平台是否支援在應用程式安裝時略過低目標 SDK 封鎖功能
| 傳回 | |
|---|---|
| boolean | 如果支援略過低目標 SDK 區塊,則傳回「是」,否則傳回「否」 | 
| 擲回 | |
|---|---|
| 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 根目錄 | 
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:我們要檢查套件安裝的使用者 ID。如果為空值,系統會使用主要使用者零。 | 
| 傳回 | |
|---|---|
| boolean | 如果套件已安裝,值為 True。否則為 False。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
isPackageInstalled
public boolean isPackageInstalled (String packageName)
針對特定套件名稱對裝置執行查詢,確認目前是否已安裝該套件。
| 參數 | |
|---|---|
| packageName | String | 
| 傳回 | |
|---|---|
| boolean | 如果套件已安裝,值為 True。否則為 False。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
isRuntimePermissionSupported
public boolean isRuntimePermissionSupported ()
檢查裝置上的平台是否支援授予執行階段權限
| 傳回 | |
|---|---|
| boolean | 如果支援執行階段權限,則傳回「是」;否則傳回「否」。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
isStateBootloaderOrFastbootd
public boolean isStateBootloaderOrFastbootd ()
如果裝置處於 TestDeviceState.FASTBOOT 或 TestDeviceState.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
publiclistDisplayIds () 
收集裝置上可用顯示器 ID 的清單,並由「dumpsys SurfaceFlinger」回報。
| 傳回 | |
|---|---|
|  | 螢幕清單。預設值一律會傳回預設顯示值 0。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
listDisplayIdsForStartingVisibleBackgroundUsers
publiclistDisplayIdsForStartingVisibleBackgroundUsers () 
取得可用於 start a user visible in the background 的螢幕清單。
| 傳回 | |
|---|---|
|  | |
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
listUsers
publiclistUsers () 
取得裝置上的使用者清單。如果裝置的輸出內容與預期不符,系統會擲回 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。 | 
nonBlockingReboot
public void nonBlockingReboot ()
發出指令重新啟動裝置,並在指令完成及裝置不再對 ADB 可見時傳回。
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
postAdbRootAction
public void postAdbRootAction ()
如果裝置需要在 adb 根目錄後,且在裝置重新上線前執行特定動作,請覆寫此值。預設實作方式不包含任何額外動作。系統不保證可在這個階段啟用 ADB 根目錄。
| 擲回 | |
|---|---|
|  | com.android.tradefed.device.DeviceNotAvailableException | 
| DeviceNotAvailableException | |
postAdbUnrootAction
public void postAdbUnrootAction ()
如果裝置需要在 adb 解除系統核心權限後,並在裝置重新上線前採取某些特定動作,請覆寫此值。預設實作方式不包含任何額外動作。系統不保證會在這個階段停用 ADB 根目錄。
| 擲回 | |
|---|---|
|  | com.android.tradefed.device.DeviceNotAvailableException | 
| DeviceNotAvailableException | |
postBootSetup
public void postBootSetup ()
執行操作說明,設定裝置以便每次啟動後進行測試。
應在裝置完全啟動/可用後呼叫
在一般情況下,您不需要明確呼叫這個方法,因為實作項目應在重新啟動時自動執行這些步驟。
當裝置因其他事件 (例如 fastboot 更新指令完成) 而重新啟動時,可能需要呼叫此方法。
| 擲回 | |
|---|---|
| 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)
將裝置重新啟動至 ADB 模式,並使用指定的 reason 在重新啟動時保留。
直到裝置可供使用為止。
您可以查詢 sys.boot.reason 屬性,取得上次重新啟動的原因。
| 參數 | |
|---|---|
| reason | String:重新啟動的原因,如果未指定原因,則為null。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
rebootIntoBootloader
public void rebootIntoBootloader ()
重新啟動裝置並進入系統啟動載入程式模式。
阻斷裝置,直到裝置進入系統啟動載入程式模式。
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
rebootIntoFastbootd
public void rebootIntoFastbootd ()
將裝置重新啟動至快速系統啟動模式。
直到裝置進入快速系統啟動模式為止。
| 擲回 | |
|---|---|
| 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 | |
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 | IRemoteAndroidTestRunner:執行測試的IRemoteAndroidTestRunner | 
| listeners | ITestLifeCycleReceiver:測試結果事件監聽器 | 
| 傳回 | |
|---|---|
| boolean | true,表示測試指令已完成。false表示無法完成,但復原作業成功 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
runInstrumentationTests
public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, 
                 listeners) 執行檢測設備測試,並提供裝置復原功能。
如果在測試執行完成前與裝置的連線中斷,且復原作業成功,則所有事件監聽器都會收到 testRunFailed 通知,並傳回「false」。系統不會重新執行測試指令。如有必要,呼叫端可重試。
如果在測試執行完成前與裝置的連線中斷,且復原作業失敗,則所有事件監聽器都會收到 testRunFailed 通知,並擲回 DeviceNotAvailableException。
| 參數 | |
|---|---|
| runner | IRemoteAndroidTestRunner:執行測試的IRemoteAndroidTestRunner | 
| listeners | :測試結果事件監聽器 | 
| 傳回 | |
|---|---|
| boolean | true,表示測試指令已完成。false:如果因裝置通訊例外狀況而無法完成,但復原作業成功 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
runInstrumentationTestsAsUser
public boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner, 
                int userId, 
                 listeners) | 參數 | |
|---|---|
| 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 | |
setConfiguration
public void setConfiguration (IConfiguration configuration)
插入正在使用的 IConfiguration。
| 參數 | |
|---|---|
| configuration | IConfiguration | 
setConnectionAvdInfo
public final void setConnectionAvdInfo (GceAvdInfo avdInfo)
| 參數 | |
|---|---|
| avdInfo | GceAvdInfo | 
setDate
public void setDate (Date date)
設定裝置上的日期
注意:在裝置上設定日期需要取得 root 權限
| 參數 | |
|---|---|
| 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 | TestDeviceState:TestDeviceState | 
setEmulatorOutputStream
public void setEmulatorOutputStream (SizeLimitedOutputStream output)
針對模擬器,將 SizeLimitedOutputStream 設為記錄輸出
| 參數 | |
|---|---|
| output | SizeLimitedOutputStream:記錄輸出內容 | 
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 | IDevice:IDevice | 
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 | IDeviceRecovery:IDeviceRecovery | 
setRecoveryMode
public void setRecoveryMode (ITestDevice.RecoveryMode mode)
設定裝置目前要使用的復原模式。
用於控制在發生裝置通訊問題時,要使用的復原方法。建議您只在必要時才使用此方法 (例如架構發生故障時)
| 參數 | |
|---|---|
| mode | ITestDevice.RecoveryMode:是否應開啟「recover till online only」模式。 | 
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 擦除功能,請使用true;如果應使用 fastboot 格式功能,請使用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 | 如果新 userId 與 userId 供應工具相符,則為「是」。否則為 False。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
switchUser
public boolean switchUser (int userId, 
                long timeout)以提供的逾時期限為期限,切換至其他 userId。在使用者變更成功後,嘗試停用鎖定畫面。
| 參數 | |
|---|---|
| userId | int | 
| timeout | long:等待後再傳回 false,表示切換使用者失敗。 | 
| 傳回 | |
|---|---|
| boolean | 如果新 userId 與 userId 供應工具相符,則為「是」。否則為 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 物件中參照的檔案。
| 傳回 | |
|---|---|
| Bugreport | |
uninstallPackage
public String uninstallPackage (String packageName)
從裝置上解除安裝 Android 套件。
| 參數 | |
|---|---|
| packageName | String:要解除安裝的 Android 套件 | 
| 傳回 | |
|---|---|
| String | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
uninstallPackageForUser
public String uninstallPackageForUser (String packageName, 
                int userId)針對特定使用者,從裝置上解除安裝 Android 套件。
| 參數 | |
|---|---|
| packageName | String:要解除安裝的 Android 套件 | 
| userId | int:要解除安裝的整數使用者 ID。 | 
| 傳回 | |
|---|---|
| String | String(含有錯誤代碼),或null(成功時)。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
unlockDevice
public boolean unlockDevice ()
如果裝置處於加密狀態,則解鎖裝置。
這個方法可能會重新啟動架構,但不會呼叫postBootSetup()。因此,在這個方法傳回時,裝置可能還未完全就緒,無法進行測試。
    | 傳回 | |
|---|---|
| boolean | true(如果成功或裝置未加密)。 | 
| 擲回 | |
|---|---|
| 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 | 如果裝置可用,則傳回「是」;如果裝置無法使用,則傳回「否」。 | 
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
waitForDeviceBootloader
public void waitForDeviceBootloader ()
直到裝置可透過 fastboot 顯示為止。使用預設逾時時間。
| 擲回 | |
|---|---|
| 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)
無法使用的裝置區塊,例如 ADB 中缺少的裝置
| 參數 | |
|---|---|
| waitTime | long:等待時間 (以毫秒為單位) | 
| 傳回 | |
|---|---|
| boolean | true如果裝置在時間到期前無法使用。其他情況則為false | 
waitForDeviceOnline
public void waitForDeviceOnline ()
直到裝置可透過 ADB 查看為止。使用預設逾時時間
 請注意,裝置可能不會在完成後回應指令。請改用 waitForDeviceAvailable()。
| 擲回 | |
|---|---|
| DeviceNotAvailableException | |
waitForDeviceOnline
public void waitForDeviceOnline (long waitTime)
直到裝置可透過 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 殼層指令工作階段和引數,建構 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。 | 
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 | |
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)如果本機檔案比遠端檔案新,則傳回 true。IFileEntry 精確到分鐘,如果時間相同,則會視為較新的檔案。
| 參數 | |
|---|---|
| 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 ()
重新啟動後可採取的其他可能動作。
| 擲回 | |
|---|---|
|  | 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 | 
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:等待發生不可用情形的時間。 | 
| 傳回 | |
|---|---|
| boolean | 如果裝置確實無法使用,則為「是」。 | 
