DeviceImpl

public final class DeviceImpl
extends Object implements IDevice

java.lang.Object
   ↳ com.android.tradefed.device.server.DeviceImpl


裝置。可以是實體裝置或模擬器。

摘要

公用建構函式

DeviceImpl(String serialNumber, IDevice.DeviceState deviceState)

公用方法

boolean arePropertiesSet()

如果屬性已快取,則傳回 true

void createForward(int localPort, String remoteSocketName, IDevice.DeviceUnixSocketNamespace namespace)

在本地 TCP 連接埠和遠端 Unix 網域通訊端之間建立連接埠轉送。

void createForward(int localPort, int remotePort)

在本地和遠端通訊埠之間建立通訊埠轉送。

void createReverse(int remotePort, int localPort)

在遠端和本機通訊埠之間建立通訊埠反向。

void executeShellCommand(String command, IShellOutputReceiver receiver)

在裝置上執行殼層指令,並將結果傳送至 receiver

這與呼叫 executeShellCommand(command, receiver, DdmPreferences.getTimeOut()) 類似。

void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)
void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)

在裝置上執行殼層指令,並將結果傳送至 receiver

void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, InputStream is)

executeShell 指令的版本,可接收輸入串流並透過 stdin 傳送。

void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)

在裝置上執行殼層指令,並將結果傳送至 receiver

void forceStop(String applicationName)

依應用程式名稱強制停止應用程式。

List<String> getAbis()

傳回這部裝置支援的 ABI。

ListenableFuture<AvdData> getAvdData()

傳回模擬器執行的 AVD 相關資訊。

String getAvdName()

傳回模擬器執行的 AVD 名稱。

String getAvdPath()

傳回檔案系統中虛擬裝置的絕對路徑。

Future<Integer> getBattery(long freshnessTime, TimeUnit timeUnit)

傳回裝置的電池電量,範圍為 0 到 100%。

Future<Integer> getBattery()

傳回裝置的電池電量,範圍為 0 到 100%。

Integer getBatteryLevel(long freshnessMs)

傳回裝置的電池電量,範圍為 0 到 100%。

Integer getBatteryLevel()

傳回裝置的電池電量,範圍為 0 到 100%。

int getDensity()

讀取系統屬性 PROP_DEVICE_DENSITY 的值,傳回裝置螢幕的密度值區間。

FileListingService getFileListingService()

傳回這部裝置的 FileListingService

String getLanguage()

傳回使用者的語言。

InstallMetrics getLastInstallMetrics()

取得這部裝置上最近一次安裝的相關資訊。

String getMountPoint(String name)

傳回掛接點。

String getName()

傳回這部裝置的 (易記) 名稱。

Map<String, String> getProperties()

傳回快取的裝置屬性。

String getProperty(String name)

便利方法,會嘗試透過 getSystemProperty(String) 擷取屬性,等待時間非常短,並會忽略例外狀況。

String getPropertyCacheOrSync(String name)

getProperty(String)getPropertySync(String) 的組合,會嘗試從快取擷取屬性。

int getPropertyCount()

傳回這部裝置的屬性數量。

String getPropertySync(String name)

getProperty(String) 的變體,會嘗試直接從裝置擷取指定屬性,而不使用快取。

String getRegion()

傳回使用者的區域。

static String getScreenRecorderCommand(String remoteFilePath, ScreenRecorderOptions options)
RawImage getScreenshot()

擷取裝置螢幕截圖,並以 RawImage 形式傳回。

RawImage getScreenshot(long timeout, TimeUnit unit)
String getSerialNumber()

傳回裝置的序號。

IDevice.DeviceState getState()

傳回裝置的狀態。

SyncService getSyncService()

傳回 SyncService 物件,用於將檔案推送到裝置或從裝置拉取檔案。

ListenableFuture<String> getSystemProperty(String name)

針對系統屬性執行潛在的非同步查詢。

void installPackage(String packageFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)

在裝置上安裝 Android 應用程式。

void installPackage(String packageFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)

在裝置上安裝 Android 應用程式。

void installPackage(String packageFilePath, boolean reinstall, String... extraArgs)

在裝置上安裝 Android 應用程式。

void installPackages(List<File> apks, boolean reinstall, List<String> installOptions, long timeout, TimeUnit timeoutUnit)

Installs an Android application made of several APK files (one main and 0..n split packages)

void installPackages(List<File> apks, boolean reinstall, List<String> installOptions)

安裝由多個 APK 檔案 (一個主要檔案和 0..n 個分割套件) 組成的 Android 應用程式,並使用預設逾時時間

void installRemotePackage(String remoteFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

void installRemotePackage(String remoteFilePath, boolean reinstall, String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

void installRemotePackage(String remoteFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

void installRemotePackages(List<String> remoteApks, boolean reinstall, List<String> installOptions, long timeout, TimeUnit timeoutUnit)

安裝由多個 APK 檔案組成的 Android 應用程式,這些檔案位於裝置本機

void installRemotePackages(List<String> remoteApks, boolean reinstall, List<String> installOptions)

在裝置上安裝由多個 APK 檔案組成的 Android 應用程式,並使用預設逾時時間

boolean isBootLoader()

傳回裝置是否處於系統啟動載入程式模式。

boolean isEmulator()

如果裝置是模擬器,則傳回 true

boolean isOffline()

傳回裝置是否離線。

boolean isOnline()

傳回裝置是否已準備就緒。

boolean isRoot()

查詢裝置目前的 Root 狀態。

void kill(String applicationName)

依應用程式名稱終止應用程式。

void pullFile(String remote, String local)

提取單一檔案。

void push(String[] local, String remote)

推送多個檔案或目錄。

void pushFile(String local, String remote)

推送單一檔案。

SocketChannel rawBinder(String service, String[] parameters)

在遠端裝置上叫用 Android Binder Bridge 服務。

SocketChannel rawExec(String executable, String[] parameters)

在遠端裝置上叫用 host:exec 服務。

void reboot(String into)

重新啟動裝置。

void removeForward(int localPort)

移除本機通訊埠與遠端通訊埠之間的通訊埠轉送。

void removeRemotePackage(String remoteFilePath)

從裝置移除檔案。

void removeReverse(int remotePort)

移除遠端通訊埠與本機通訊埠之間的通訊埠反向連線。

boolean root()

要求 adb daemon 在裝置上成為根使用者。

void startScreenRecorder(String remoteFilePath, ScreenRecorderOptions options, IShellOutputReceiver receiver)

如果裝置支援 Feature.SCREEN_RECORD,就會啟動螢幕錄影功能。

boolean supportsFeature(IDevice.HardwareFeature feature)

傳回這個裝置是否支援指定的硬體功能。

boolean supportsFeature(IDevice.Feature feature)

傳回這個裝置是否支援指定的軟體功能。

String syncPackageToDevice(String localFilePath)

將檔案推送至裝置

String toString()
String uninstallApp(String applicationID, String... extraArgs)

從裝置解除安裝應用程式。

String uninstallPackage(String packageName)

從裝置解除安裝套件。

公用建構函式

DeviceImpl

public DeviceImpl (String serialNumber, 
                IDevice.DeviceState deviceState)

參數
serialNumber String

deviceState IDevice.DeviceState

公用方法

arePropertiesSet

public boolean arePropertiesSet ()

如果已快取屬性,則傳回 true

傳回
boolean

createForward

public void createForward (int localPort, 
                String remoteSocketName, 
                IDevice.DeviceUnixSocketNamespace namespace)

在本地 TCP 連接埠和遠端 Unix 網域通訊端之間建立連接埠轉送。

參數
localPort int:要轉送的本機通訊埠

remoteSocketName String:裝置上建立的 Unix 網域通訊端名稱

namespace IDevice.DeviceUnixSocketNamespace:建立 Unix 網域通訊端的命名空間

擲回
AdbCommandRejectedException
IOException
TimeoutException

createForward

public void createForward (int localPort, 
                int remotePort)

在本地和遠端通訊埠之間建立通訊埠轉送。

參數
localPort int:要轉送的本機通訊埠

remotePort int:遠端通訊埠。

擲回
AdbCommandRejectedException
IOException
TimeoutException

createReverse

public void createReverse (int remotePort, 
                int localPort)

在遠端和本機通訊埠之間建立通訊埠反向轉送。

參數
remotePort int:要反向的遠端通訊埠。

localPort int:本機通訊埠

擲回
AdbCommandRejectedException
IOException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

在裝置上執行殼層指令,並將結果傳送至 receiver

這與呼叫 executeShellCommand(command, receiver, DdmPreferences.getTimeOut()) 類似。

參數
command String:要執行的殼層指令

receiver IShellOutputReceiver:接收殼層指令輸出內容的 IShellOutputReceiver

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                int maxTimeToOutputResponse)

參數
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse int

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits)

在裝置上執行殼層指令,並將結果傳送至 receiver

maxTimeToOutputResponse 用於預期裝置的指令輸出內容時,做為最長等待時間。
在任何時間,如果殼層指令在超過 maxTimeToOutputResponse 的時間內沒有輸出任何內容,這個方法就會擲回 ShellCommandUnresponsiveException

對於記錄輸出等指令,應使用 maxTimeToOutputResponse 值 0,表示方法絕不會擲回,且會封鎖,直到接收端的 IShellOutputReceiver.isCancelled() 傳回 true 為止。

參數
command String:要執行的殼層指令

receiver IShellOutputReceiver:接收殼層指令輸出內容的 IShellOutputReceiver

maxTimeout long:指令傳回的逾時時間上限。如果值為 0,表示不會套用逾時上限。

maxTimeToOutputResponse long:指令在沒有任何回應的情況下,允許的最長時間。如果值為 0,方法會無限期等待指令輸出內容 (直到 receiver 取消執行),且絕不會擲回。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的單位。

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                InputStream is)

executeShell 指令的版本,可接收輸入串流,透過 stdin 傳送。

參數
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse long

maxTimeUnits TimeUnit

is InputStream

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits)

在裝置上執行殼層指令,並將結果傳送至 receiver

maxTimeToOutputResponse 用於預期裝置的指令輸出內容時,做為最長等待時間。
在任何時間,如果殼層指令在超過 maxTimeToOutputResponse 的時間內沒有輸出任何內容,這個方法就會擲回 ShellCommandUnresponsiveException

對於記錄輸出等指令,應使用 maxTimeToOutputResponse 值 0,表示方法絕不會擲回,且會封鎖,直到接收端的 IShellOutputReceiver.isCancelled() 傳回 true 為止。

參數
command String:要執行的殼層指令

receiver IShellOutputReceiver:接收殼層指令輸出內容的 IShellOutputReceiver

maxTimeToOutputResponse long:指令在沒有任何回應的情況下,允許的最長時間。如果值為 0,方法會無限期等待指令輸出內容 (直到 receiver 取消執行),且絕不會擲回。

maxTimeUnits TimeUnit:非零 maxTimeToOutputResponse 值的單位。

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

forceStop

public void forceStop (String applicationName)

依應用程式名稱強制停止應用程式。這項操作會移除所有待處理的鬧鐘和排隊等候的運算作業。

參數
applicationName String:應用程式名稱

getAbis

public List<String> getAbis ()

傳回這部裝置支援的 ABI。ABI 會依偏好順序排序,第一個 ABI 是最偏好的。

傳回
List<String> ABI 清單。

getAvdData

public ListenableFuture<AvdData> getAvdData ()

傳回模擬器執行的 AVD 相關資訊。

AvdData.getName 是 AVD 的名稱,如果沒有名稱,則為 null

AvdData.getPath 是 AVD 路徑,如果是實體裝置、模擬器控制台子指令失敗,或模擬器版本舊於 30.0.18,則為空值

傳回
ListenableFuture<AvdData> 裝置的 AvdData

getAvdName

public String getAvdName ()

傳回模擬器執行的 AVD 名稱。

只有在 isEmulator() 傳回 True 時,這項設定才會生效。

如果模擬器未執行任何 AVD (例如從 Android 來源樹狀結構建構執行),這個方法會傳回「<build>」。

注意:如要控管逾時時間,建議使用 getAvdData()

傳回
String AVD 的名稱,或沒有名稱時為 null

getAvdPath

public String getAvdPath ()

傳回檔案系統中虛擬裝置的絕對路徑。路徑取決於作業系統,Linux 使用「/」分隔名稱,Windows 則使用「\」。

注意:如要控管逾時時間,建議使用 getAvdData()

傳回
String AVD 路徑,如果是實體裝置則為空值,模擬器控制台子指令失敗,或模擬器版本舊於 30.0.18

getBattery

public Future<Integer> getBattery (long freshnessTime, 
                TimeUnit timeUnit)

傳回裝置的電池電量,範圍為 0 到 100%。

系統可能會快取電池電量。只有在上次成功查詢後, freshnessTime已過期時,才會查詢裝置的電池電量。

參數
freshnessTime long:所需的電池電量最新狀態

timeUnit TimeUnitTimeUnitTimeUnit freshnessTime

傳回
Future<Integer> 可用於查詢電池電量。Future如果無法擷取電池電量,Future 會傳回 ExecutionException

getBattery

public Future<Integer> getBattery ()

傳回裝置的電池電量,範圍為 0 到 100%。

系統可能會快取電池電量。如果自上次成功查詢後已過 5 分鐘,才會查詢裝置的電池電量。

傳回
Future<Integer> 可用於查詢電池電量。Future如果無法擷取電池電量,Future 會傳回 ExecutionException

getBatteryLevel

public Integer getBatteryLevel (long freshnessMs)

傳回裝置的電池電量,範圍為 0 到 100%。

系統可能會快取電池電量。只有在上次成功查詢後經過 freshnessMs 毫秒時,才會查詢裝置的電池電量。

傳回
Integer 電池電量,或無法擷取時的 null

getBatteryLevel

public Integer getBatteryLevel ()

傳回裝置的電池電量,範圍為 0 到 100%。

系統可能會快取電池電量。如果自上次成功查詢後已過 5 分鐘,才會查詢裝置的電池電量。

傳回
Integer 電池電量,或無法擷取時的 null

getDensity

public int getDensity ()

讀取系統屬性 PROP_DEVICE_DENSITY 的值,傳回裝置螢幕的密度值區間。

傳回
int 密度,如果無法判斷,則為 -1。

getFileListingService

public FileListingService getFileListingService ()

傳回這部裝置的 FileListingService

傳回
FileListingService

getLanguage

public String getLanguage ()

傳回使用者的語言。

傳回
String 使用者的語言,如果不明則為空值

getLastInstallMetrics

public InstallMetrics getLastInstallMetrics ()

取得這部裝置上最近一次安裝的相關資訊。

傳回
InstallMetrics InstallMetrics 說明安裝作業的指標。

getMountPoint

public String getMountPoint (String name)

傳回掛接點。

參數
name String:要傳回的掛接點名稱

傳回
String

getName

public String getName ()

傳回這部裝置的 (人性化) 名稱。通常是 AVD 的 AVD 名稱,以及裝置的製造商名稱、型號名稱和序號組合。

傳回
String

getProperties

public Map<String, String> getProperties ()

傳回快取的裝置屬性。其中包含「getprop」的完整輸出內容

傳回
Map<String, String>

getProperty

public String getProperty (String name)

便利方法,會嘗試透過 getSystemProperty(String) 擷取屬性,等待時間非常短,並會忽略例外狀況。

注意:如要控管逾時時間,建議使用 getSystemProperty(String)

參數
name String:要傳回的值名稱。

傳回
String 值,或 null (如果屬性值無法立即取得)

getPropertyCacheOrSync

public String getPropertyCacheOrSync (String name)

getProperty(String)getPropertySync(String) 的組合,會嘗試從快取擷取屬性。如果找不到,系統會嘗試直接查詢裝置,並在成功時重新填入快取。

參數
name String:要傳回的值名稱。

傳回
String 如果屬性不存在,則為值或 null

getPropertyCount

public int getPropertyCount ()

傳回這部裝置的屬性數量。

傳回
int

getPropertySync

public String getPropertySync (String name)

getProperty(String) 的變體,會嘗試直接從裝置擷取指定屬性,而不使用快取。這個方法「只能」用於任何不穩定的屬性。

參數
name String:要傳回的值名稱。

傳回
String 如果屬性不存在,則為值或 null

getRegion

public String getRegion ()

傳回使用者的區域。

傳回
String 使用者的區域,如果不明則為空值

getScreenRecorderCommand

public static String getScreenRecorderCommand (String remoteFilePath, 
                ScreenRecorderOptions options)

參數
remoteFilePath String

options ScreenRecorderOptions

傳回
String

getScreenshot

public RawImage getScreenshot ()

擷取裝置螢幕截圖,並以 RawImage 形式傳回。

傳回
RawImage 如果發生錯誤,請提供螢幕截圖 (RawImagenull)。

擲回
AdbCommandRejectedException
IOException
TimeoutException

getScreenshot

public RawImage getScreenshot (long timeout, 
                TimeUnit unit)

參數
timeout long

unit TimeUnit

傳回
RawImage

擲回
AdbCommandRejectedException
IOException
TimeoutException

getSerialNumber

public String getSerialNumber ()

傳回裝置的序號。

傳回
String

getState

public IDevice.DeviceState getState ()

傳回裝置狀態。

傳回
IDevice.DeviceState

getSyncService

public SyncService getSyncService ()

傳回 SyncService 物件,用於將檔案推送/拉取至裝置或從裝置推送/拉取檔案。

傳回
SyncService null (如果無法建立 SyncService)。如果 adb 拒絕開啟連線,可能是因為 IDevice 無效 (或已中斷連線)。

擲回
AdbCommandRejectedException
IOException
TimeoutException

getSystemProperty

public ListenableFuture<String> getSystemProperty (String name)

針對系統屬性執行潛在的非同步查詢。

參數
name String:要傳回的值名稱。

傳回
ListenableFuture<String> ListenableFuture. get 可能會傳回空值。

installPackage

public void installPackage (String packageFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                String... extraArgs)

在裝置上安裝 Android 應用程式。這是輔助方法,可合併 syncPackageToDevice、installRemotePackage 和 removePackage 步驟

參數
packageFilePath String:本機主機上要安裝的檔案的絕對檔案系統路徑

reinstall boolean:如果應重新安裝應用程式,請設為 true

receiver InstallReceiver:用於監控安裝作業並取得最終狀態的 InstallReceiver

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installPackage

public void installPackage (String packageFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                String... extraArgs)

在裝置上安裝 Android 應用程式。這是輔助方法,可合併 syncPackageToDevice、installRemotePackage 和 removePackage 步驟

參數
packageFilePath String:本機主機上要安裝的檔案的絕對檔案系統路徑

reinstall boolean:如果應重新安裝應用程式,請設為 true

receiver InstallReceiver:用於監控安裝作業並取得最終狀態的 InstallReceiver

maxTimeout long:指令傳回的逾時時間上限。如果值為 0,表示不會套用逾時上限。

maxTimeToOutputResponse long:指令在沒有任何回應的情況下,允許的最長時間。如果值為 0,方法會無限期等待指令輸出內容 (直到 receiver 取消執行),且絕不會擲回。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的單位。

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installPackage

public void installPackage (String packageFilePath, 
                boolean reinstall, 
                String... extraArgs)

在裝置上安裝 Android 應用程式。這是輔助方法,可合併 syncPackageToDevice、installRemotePackage 和 removePackage 步驟

參數
packageFilePath String:本機主機上要安裝的檔案的絕對檔案系統路徑

reinstall boolean:如果應重新安裝應用程式,請設為 true

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installPackages

public void installPackages (List<File> apks, 
                boolean reinstall, 
                List<String> installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

安裝由多個 APK 檔案組成的 Android 應用程式 (一個主要套件和 0..n 個分割套件)

參數
apks List:要安裝的 APK 清單 (1 個主要 APK + 0 到 n 個分割 APK)

reinstall boolean:如果應重新安裝應用程式,請設為 true

installOptions List:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

timeout long:安裝逾時

timeoutUnit TimeUnit:對應逾時參數的 TimeUnit

擲回
InstallException

installPackages

public void installPackages (List<File> apks, 
                boolean reinstall, 
                List<String> installOptions)

安裝由多個 APK 檔案 (一個主要檔案和 0..n 個分割套件) 組成的 Android 應用程式,並使用預設逾時

參數
apks List:要安裝的 APK 清單 (1 個主要 APK + 0 到 n 個分割 APK)

reinstall boolean:如果應重新安裝應用程式,請設為 true

installOptions List:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installRemotePackage

public void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

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

reinstall boolean:如果應重新安裝應用程式,請設為 true

receiver InstallReceiver:用於監控安裝作業並取得最終狀態的 InstallReceiver

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installRemotePackage

public void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

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

reinstall boolean:如果應重新安裝應用程式,請設為 true

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installRemotePackage

public void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                String... extraArgs)

安裝已推送至裝置暫時位置的應用程式套件。

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

reinstall boolean:如果應重新安裝應用程式,請設為 true

receiver InstallReceiver:用於監控安裝作業並取得最終狀態的 InstallReceiver

maxTimeout long:指令傳回的逾時時間上限。如果值為 0,表示不會套用逾時上限。

maxTimeToOutputResponse long:指令在沒有任何回應的情況下,允許的最長時間。如果值為 0,方法會無限期等待指令輸出內容 (直到 receiver 取消執行),且絕不會擲回。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的單位。

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

installRemotePackages

public void installRemotePackages (List<String> remoteApks, 
                boolean reinstall, 
                List<String> installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

安裝由多個 APK 檔案組成的 Android 應用程式 (這些檔案位於裝置本機)

參數
remoteApks List:裝置上要安裝的 APK 檔案路徑清單

reinstall boolean:如果應重新安裝應用程式,請設為 true

installOptions List:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

timeout long:安裝逾時

timeoutUnit TimeUnit:對應逾時參數的 TimeUnit

擲回
InstallException

installRemotePackages

public void installRemotePackages (List<String> remoteApks, 
                boolean reinstall, 
                List<String> installOptions)

在裝置上安裝由多個 APK 檔案組成的 Android 應用程式,並使用預設逾時

參數
remoteApks List:要在裝置上安裝的 APK 檔案路徑清單

reinstall boolean:如果應重新安裝應用程式,請設為 true

installOptions List:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

擲回
InstallException

isBootLoader

public boolean isBootLoader ()

傳回裝置是否處於系統啟動載入程式模式。

傳回
boolean 如果 getState() 傳回 DeviceState.BOOTLOADER,則為 true

isEmulator

public boolean isEmulator ()

如果裝置是模擬器,則傳回 true

傳回
boolean

isOffline

public boolean isOffline ()

傳回裝置是否離線。

傳回
boolean 如果 getState() 傳回 DeviceState.OFFLINE,則為 true

isOnline

public boolean isOnline ()

傳回裝置是否已準備就緒。

傳回
boolean 如果 getState() 傳回 DeviceState.ONLINE,則為 true

isRoot

public boolean isRoot ()

查詢裝置目前的 Root 狀態。詳情請參閱「adb root」。

傳回
boolean 如果 adb daemon 以根身分執行,則為 true,否則為 false。

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

kill

public void kill (String applicationName)

依應用程式名稱終止應用程式。這只會刪除活動,將其狀態留在 Android 系統中。

參數
applicationName String:應用程式名稱

pullFile

public void pullFile (String remote, 
                String local)

提取單一檔案。

參數
remote String:遠端檔案的完整路徑

local String:本機目的地。

擲回
AdbCommandRejectedException
IOException
SyncException
TimeoutException

推送

public void push (String[] local, 
                String remote)

推送多個檔案或目錄。

參數
local String:要推送的本機檔案

remote String:代表目錄的遠端路徑

擲回
AdbCommandRejectedException
IOException
SyncException
TimeoutException

pushFile

public void pushFile (String local, 
                String remote)

推送單一檔案。

參數
local String:本機檔案路徑。

remote String:遠端檔案路徑

擲回
AdbCommandRejectedException
IOException
SyncException
TimeoutException

rawBinder

public SocketChannel rawBinder (String service, 
                String[] parameters)

在遠端裝置上叫用 Android Binder Bridge 服務。傳回已連線至裝置繫結器指令的通訊端管道。

SocketChannel 的擁有權會交給呼叫端,使用後必須明確關閉。

參數
service String:要連線的 Android 服務名稱

parameters String:繫結器指令的參數

傳回
SocketChannel 連線至裝置上執行程序的 SocketChannel。使用完畢後,

擲回
AdbCommandRejectedException
IOException
TimeoutException

rawExec

public SocketChannel rawExec (String executable, 
                String[] parameters)

在遠端裝置上叫用 host:exec 服務。傳回已連線至執行中程序的 Socket 管道。請注意,exec 服務不會區分 stdout 和 stderr,因此從通訊端讀取的任何內容都可能來自任一輸出,且可能會交錯。

SocketChannel 的擁有權會交給呼叫端,使用後必須明確關閉。

參數
executable String

parameters String

傳回
SocketChannel 連線至裝置上執行程序的 SocketChannel。使用完畢後,

擲回
AdbCommandRejectedException
IOException
TimeoutException

重新開機

public void reboot (String into)

重新啟動裝置。

參數
into String:要重新啟動的系統啟動載入程式名稱,或為空值,僅重新啟動裝置。

擲回
AdbCommandRejectedException
IOException
TimeoutException

removeForward

public void removeForward (int localPort)

移除本機通訊埠與遠端通訊埠之間的通訊埠轉送。

參數
localPort int:要轉送的本機通訊埠

擲回
AdbCommandRejectedException
IOException
TimeoutException

removeRemotePackage

public void removeRemotePackage (String remoteFilePath)

從裝置中移除檔案。

參數
remoteFilePath String:要移除的檔案在裝置上的路徑

擲回
InstallException

removeReverse

public void removeReverse (int remotePort)

移除遠端通訊埠與本機通訊埠之間的通訊埠反向。

參數
remotePort int:遠端通訊埠。

擲回
AdbCommandRejectedException
IOException
TimeoutException

root

public boolean root ()

要求 adb daemon 在裝置上成為根使用者。這項作業可能會無聲無息地失敗,而且只能在開發人員建構版本中成功。詳情請參閱「adb root」。

傳回
boolean 如果 adb daemon 以根身分執行,則為 true,否則為 false。

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

startScreenRecorder

public void startScreenRecorder (String remoteFilePath, 
                ScreenRecorderOptions options, 
                IShellOutputReceiver receiver)

如果裝置支援 Feature.SCREEN_RECORD,就會啟動螢幕錄影功能。

參數
remoteFilePath String

options ScreenRecorderOptions

receiver IShellOutputReceiver

擲回
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

supportsFeature

public boolean supportsFeature (IDevice.HardwareFeature feature)

傳回這部裝置是否支援指定的硬體功能。

參數
feature IDevice.HardwareFeature

傳回
boolean

supportsFeature

public boolean supportsFeature (IDevice.Feature feature)

傳回這部裝置是否支援指定軟體功能。

參數
feature IDevice.Feature

傳回
boolean

syncPackageToDevice

public String syncPackageToDevice (String localFilePath)

將檔案推送至裝置

參數
localFilePath String:本機主機上檔案的絕對路徑

傳回
String String 裝置上的檔案目的地路徑

擲回
AdbCommandRejectedException
IOException
SyncException
TimeoutException

toString

public String toString ()

傳回
String

uninstallApp

public String uninstallApp (String applicationID, 
                String... extraArgs)

從裝置解除安裝應用程式。

參數
applicationID String:要解除安裝的 Android 應用程式 ID

extraArgs String:要傳遞的選用額外引數。如要瞭解可用選項,請參閱「adb shell pm install --help」。

傳回
String 含有錯誤代碼的 String,或成功時的 null

擲回
InstallException

uninstallPackage

public String uninstallPackage (String packageName)

從裝置解除安裝套件。

參數
packageName String:要解除安裝的 Android 應用程式 ID

傳回
String 含有錯誤代碼的 String,或成功時的 null

擲回
InstallException