FastbootDeviceFlasher
public
class
FastbootDeviceFlasher
extends Object
implements
IDeviceFlasher
java.lang.Object | |
↳ | com.android.tradefed.targetprep.FastbootDeviceFlasher |
這個類別會使用 Fastboot 在實體 Android 硬體上刷新映像檔。
摘要
欄位 | |
---|---|
public
static
final
String |
BASEBAND_IMAGE_NAME
|
公用建構函式 | |
---|---|
FastbootDeviceFlasher()
|
公用方法 | |
---|---|
void
|
flash(ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上刷新版本。 |
CommandStatus
|
getSystemFlashingStatus()
擷取主要系統分區閃燈作業的指令執行狀態。 |
IDeviceFlasher.UserDataFlashOption
|
getUserDataFlashOption()
取得是否應閃過、清除或保留使用者資料映像檔的權限 |
void
|
overrideDeviceOptions(ITestDevice device)
覆寫裝置的選項。 |
void
|
setDataWipeSkipList(
設定
請注意,略過清單的精細程度是 |
void
|
setFlashOptions(
設定要透過閃燈/更新指令傳遞的選項清單。 |
void
|
setFlashingResourcesRetriever(IFlashingResourcesRetriever retriever)
設定裝置可透過哪種機制擷取資源檔案進行閃燈。 |
void
|
setForceSystemFlash(boolean forceSystemFlash)
設定是否應一律閃爍系統,即使正在執行目前版本也一樣 |
void
|
setRamdiskPartition(String ramdiskPartition)
設定 RAMDISK 分割區 |
void
|
setShouldFlashRamdisk(boolean shouldFlashRamdisk)
設定是否應在透過圖像 ZIP 檔案更新裝置後,再刷新額外的 RAM 磁碟 |
void
|
setUserDataFlashOption(IDeviceFlasher.UserDataFlashOption flashOption)
切換使用者資料映像檔應否閃過、擦除或保留 |
void
|
setWipeTimeout(long timeout)
設定資料清除的逾時值。 |
boolean
|
shouldFlashRamdisk()
檢查是否已設定閃燈程式,以便在透過圖片 ZIP 檔案更新裝置後,閃燈程式可額外執行 RAM 磁碟。 |
受保護的方法 | |
---|---|
void
|
checkAndFlashBaseband(ITestDevice device, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新基頻映像檔。 |
boolean
|
checkAndFlashBootloader(ITestDevice device, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新系統啟動載入程式映像檔。 |
boolean
|
checkAndFlashSystem(ITestDevice device, String systemBuildId, String systemBuildFlavor, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新系統映像檔。 |
boolean
|
checkShouldFlashBaseband(ITestDevice device, IDeviceBuildInfo deviceBuild)
檢查是否需要刷新所提供裝置的基地台。 |
IFlashingResourcesParser
|
createFlashingResourcesParser(IDeviceBuildInfo localBuild, DeviceDescriptor descriptor)
用於建立 |
void
|
downloadExtraImageFiles(IFlashingResourcesParser resourceParser, IFlashingResourcesRetriever retriever, IDeviceBuildInfo localBuild)
鉤子,可讓子類別在需要時下載額外自訂圖片檔案。 |
void
|
downloadFlashingResources(ITestDevice device, IDeviceBuildInfo localBuild)
下載所需的額外閃爍圖片檔案 |
String
|
executeFastbootCmd(ITestDevice device, String... cmdArgs)
執行 fastboot 指令的輔助方法。 |
String
|
executeLongFastbootCmd(ITestDevice device, String... cmdArgs)
執行長時間執行的 fastboot 指令的輔助方法。 |
void
|
flashBaseband(ITestDevice device, File basebandImageFile)
閃記指定的基地台映像檔,並重新啟動至系統啟動載入程式 |
void
|
flashBootloader(ITestDevice device, File bootloaderImageFile)
閃記指定的系統啟動載入程式映像檔,並重新啟動至系統啟動載入程式 |
void
|
flashExtraImages(ITestDevice device, IDeviceBuildInfo deviceBuild)
請先刷新任何裝置專屬分割區,再刷新系統並重新啟動。 |
void
|
flashPartition(ITestDevice device, File imgFile, String partition)
刷新裝置的個別分區 |
void
|
flashRamdiskIfNeeded(ITestDevice device, IDeviceBuildInfo deviceBuild)
|
void
|
flashSystem(ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上刷新系統映像檔。 |
void
|
flashUserData(ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上閃記 userdata 分區。 |
void
|
flashUserDataFromDeviceImageFile(ITestDevice device, IDeviceBuildInfo deviceBuild)
從裝置映像檔中擷取 userdata.img,並將其刷入裝置 |
String
|
getBootPartitionName()
取得裝置閃燈程式的開機分割區名稱。 |
String
|
getBootloaderFilePrefix(ITestDevice device)
取得系統啟動載入程式檔案前置字串。 |
String
|
getCurrentSlot(ITestDevice device)
用於擷取目前的插槽 (適用於支援 A/B 的裝置) 的輔助方法。 |
IFlashingResourcesRetriever
|
getFlashingResourcesRetriever()
|
String
|
getImageVersion(ITestDevice device, String imageName)
輔助方法,用於取得裝置上的目前圖片版本。 |
IRunUtil
|
getRunUtil()
供測試使用。 |
void
|
handleUserDataFlashing(ITestDevice device, IDeviceBuildInfo deviceBuild)
處理 userdata/cache 分區的閃燈作業 |
boolean
|
hasPartition(ITestDevice device, String partition)
透過系統啟動載入程式檢查指定的分區是否存在 |
void
|
preFlashSetup(ITestDevice device, IDeviceBuildInfo deviceBuild)
執行任何必要的預先刷新設定。 |
void
|
verifyRequiredBoards(ITestDevice device, IFlashingResourcesParser resourceParser, String deviceProductType)
確認裝置的產品類型支援要刷新的版本。 |
void
|
wipeCache(ITestDevice device)
清除裝置上的快取分區。 |
void
|
wipePartition(ITestDevice device, String partition)
使用 `fastboot erase <name>` 清除指定的分割區 |
欄位
BASEBAND_IMAGE_NAME
public static final String BASEBAND_IMAGE_NAME
公用建構函式
FastbootDeviceFlasher
public FastbootDeviceFlasher ()
公用方法
Flash
public void flash (ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上刷新版本。
閃燈完成後立即傳回。呼叫端應等待裝置上線並可供使用,再繼續進行測試。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :要閃爍的 IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
|
TargetSetupError |
getSystemFlashingStatus
public CommandStatus getSystemFlashingStatus ()
擷取主要系統分區閃燈作業的指令執行狀態。
請注意,如果系統分區未刷新 (系統已具有要刷新的版本),指令狀態可能會是 null
傳回 | |
---|---|
CommandStatus |
getUserDataFlashOption
public IDeviceFlasher.UserDataFlashOption getUserDataFlashOption ()
取得是否應閃過、清除或保留使用者資料映像檔的權限
傳回 | |
---|---|
IDeviceFlasher.UserDataFlashOption |
是否應閃過、清除或保留使用者資料映像檔 |
overrideDeviceOptions
public void overrideDeviceOptions (ITestDevice device)
覆寫裝置的選項。如果特定裝置不支援預設值,則可用於覆寫預設選項值。
setDataWipeSkipList
public void setDataWipeSkipList (dataWipeSkipList)
設定 /data
下的路徑清單,以免在使用 ITestsZipInstaller
時清除
請注意,略過清單的精細程度是 /data
的直接子項。
參數 | |
---|---|
dataWipeSkipList |
|
setFlashOptions
public void setFlashOptions (flashOptions)
設定要透過閃爍/更新指令傳遞的選項清單。
setFlashingResourcesRetriever
public void setFlashingResourcesRetriever (IFlashingResourcesRetriever retriever)
設定機制,讓閃記程式擷取資源檔案以進行閃記。
參數 | |
---|---|
retriever |
IFlashingResourcesRetriever :要使用的 IFlashingResourcesRetriever |
setForceSystemFlash
public void setForceSystemFlash (boolean forceSystemFlash)
設定是否應一律閃爍系統,即使執行目前版本也一樣
setRamdiskPartition
public void setRamdiskPartition (String ramdiskPartition)
設定 RAMDISK 分割區
setShouldFlashRamdisk
public void setShouldFlashRamdisk (boolean shouldFlashRamdisk)
設定是否應在透過圖像 ZIP 檔案更新裝置後,再閃記額外的 RAM 磁碟
setUserDataFlashOption
public void setUserDataFlashOption (IDeviceFlasher.UserDataFlashOption flashOption)
切換使用者資料映像檔應否閃過、清除或保留
setWipeTimeout
public void setWipeTimeout (long timeout)
設定資料清除的逾時值。
參數 | |
---|---|
timeout |
long |
shouldFlashRamdisk
public boolean shouldFlashRamdisk ()
檢查是否應在透過圖片 ZIP 檔案更新裝置後,將額外的 RAM 磁碟閃爍設定為閃爍器
傳回 | |
---|---|
boolean |
受保護的方法
checkAndFlashBaseband
protected void checkAndFlashBaseband (ITestDevice device, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新基頻映像檔。只有在裝置的目前版本 != 必要版本時,才會刷新基頻
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要刷新的基頻映像檔的 IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash baseband |
checkAndFlashBootloader
protected boolean checkAndFlashBootloader (ITestDevice device, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新系統啟動載入程式映像檔。
只有在裝置的目前版本 != 所需版本時,才會閃記系統啟動載入程式。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要刷新的 Bootloader 映像檔的 IDeviceBuildInfo |
傳回 | |
---|---|
boolean |
如果已刷新系統啟動載入程式,則為 true ;如果已略過,則為 false |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash bootloader |
checkAndFlashSystem
protected boolean checkAndFlashSystem (ITestDevice device, String systemBuildId, String systemBuildFlavor, IDeviceBuildInfo deviceBuild)
視需要在裝置上刷新系統映像檔。
請查看 ERROR(/#shouldFlashSystem(String,String,com.android.tradefed.build.IDeviceBuildInfo))
無論選擇哪個路徑,執行方法後,裝置應會啟動至使用者空間。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
systemBuildId |
String :裝置上目前執行的版本 ID |
systemBuildFlavor |
String :裝置上目前執行的版本變化 |
deviceBuild |
IDeviceBuildInfo :包含要閃燈的系統映像檔的 IDeviceBuildInfo |
傳回 | |
---|---|
boolean |
true (如果系統已更新) 或 false (如果已略過) |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash bootloader |
checkShouldFlashBaseband
protected boolean checkShouldFlashBaseband (ITestDevice device, IDeviceBuildInfo deviceBuild)
檢查是否需要刷新提供裝置的基地台。
參數 | |
---|---|
device |
ITestDevice :要檢查的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要檢查的基地台映像檔的 IDeviceBuildInfo |
傳回 | |
---|---|
boolean |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash baseband |
createFlashingResourcesParser
protected IFlashingResourcesParser createFlashingResourcesParser (IDeviceBuildInfo localBuild, DeviceDescriptor descriptor)
用於建立 IFlashingResourcesParser
的工廠方法。
公開供單元測試使用。
參數 | |
---|---|
localBuild |
IDeviceBuildInfo :要剖析的 IDeviceBuildInfo |
descriptor |
DeviceDescriptor :正在刷新的裝置描述項。 |
傳回 | |
---|---|
IFlashingResourcesParser |
工廠方法建立的 IFlashingResourcesParser 。 |
擲回 | |
---|---|
TargetSetupError |
downloadExtraImageFiles
protected void downloadExtraImageFiles (IFlashingResourcesParser resourceParser, IFlashingResourcesRetriever retriever, IDeviceBuildInfo localBuild)
鉤子,可讓子類別在需要時下載額外的自訂圖片檔案。
參數 | |
---|---|
resourceParser |
IFlashingResourcesParser :IFlashingResourcesParser |
retriever |
IFlashingResourcesRetriever :IFlashingResourcesRetriever |
localBuild |
IDeviceBuildInfo :IDeviceBuildInfo |
擲回 | |
---|---|
TargetSetupError |
downloadFlashingResources
protected void downloadFlashingResources (ITestDevice device, IDeviceBuildInfo localBuild)
下載所需的額外閃爍圖片檔案
參數 | |
---|---|
device |
ITestDevice :要下載資源的 ITestDevice |
localBuild |
IDeviceBuildInfo :要填入的 IDeviceBuildInfo 。假設裝置映像檔已設定 |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
無法擷取資源時 |
executeFastbootCmd
protected String executeFastbootCmd (ITestDevice device, String... cmdArgs)
執行 fastboot 指令的輔助方法。
參數 | |
---|---|
device |
ITestDevice :要執行指令的 ITestDevice |
cmdArgs |
String :提供給 Fastboot 的引數 |
傳回 | |
---|---|
String |
如果 stderr 輸出內容非空白,則將其轉為字串。否則會傳回 stdout。部分快速啟動指令會在成功的情況下將輸出內容轉儲至 stderr,這點相當奇怪 |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
如果 Fastboot 指令失敗 |
executeLongFastbootCmd
protected String executeLongFastbootCmd (ITestDevice device, String... cmdArgs)
輔助方法,用於執行長時間執行的 fastboot 指令。
注意:大多數 fastboot 指令通常會在 INativeDevice.executeFastbootCommand(String)
允許的逾時時間內執行。不過,如果同時有許多裝置正在刷機,fastboot 指令可能會比平常耗費更多時間。
參數 | |
---|---|
device |
ITestDevice :要執行指令的 ITestDevice |
cmdArgs |
String :提供給 Fastboot 的引數 |
傳回 | |
---|---|
String |
如果 stderr 輸出內容非空白,則將其轉為字串。否則會傳回 stdout。部分快速啟動指令會在成功的情況下將輸出內容轉儲至 stderr,這點相當奇怪 |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
如果 Fastboot 指令失敗 |
flashBaseband
protected void flashBaseband (ITestDevice device, File basebandImageFile)
閃記指定的基地台映像檔,並重新啟動至系統啟動載入程式
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
basebandImageFile |
File :基頻圖像 ERROR(/File) |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash baseband |
flashBootloader
protected void flashBootloader (ITestDevice device, File bootloaderImageFile)
閃記指定的系統啟動載入程式映像檔,並重新啟動至系統啟動載入程式
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
bootloaderImageFile |
File :bootloader 映像檔 ERROR(/File) |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash |
flashExtraImages
protected void flashExtraImages (ITestDevice device, IDeviceBuildInfo deviceBuild)
請先刷新裝置專屬分區,再刷新系統並重新啟動。除非覆寫,否則為無操作。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含建構檔案的 IDeviceBuildInfo |
擲回 | |
---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
TargetSetupError |
|
DeviceNotAvailableException |
flashPartition
protected void flashPartition (ITestDevice device, File imgFile, String partition)
刷新裝置的個別分區
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
imgFile |
File :指向要閃爍的圖片的 ERROR(/File) |
partition |
String :要刷新的分區名稱 |
擲回 | |
---|---|
DeviceNotAvailableException |
|
TargetSetupError |
flashRamdiskIfNeeded
protected void flashRamdiskIfNeeded (ITestDevice device, IDeviceBuildInfo deviceBuild)
參數 | |
---|---|
device |
ITestDevice |
deviceBuild |
IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
|
TargetSetupError |
flashSystem
protected void flashSystem (ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上刷新系統映像檔。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :要閃爍的 IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
如果 Fastboot 指令失敗 |
flashUserData
protected void flashUserData (ITestDevice device, IDeviceBuildInfo deviceBuild)
在裝置上閃記 userdata 分區。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要刷新的檔案的 IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash user data |
flashUserDataFromDeviceImageFile
protected void flashUserDataFromDeviceImageFile (ITestDevice device, IDeviceBuildInfo deviceBuild)
從裝置映像檔中擷取 userdata.img,並將其刷入裝置
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要刷新的檔案的 IDeviceBuildInfo |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
無法擷取或閃過使用者資料 |
getBootPartitionName
protected String getBootPartitionName ()
取得此裝置閃燈程式的開機分割區名稱。
預設值為「bootloader」。子類別應視需要覆寫。
傳回 | |
---|---|
String |
getBootloaderFilePrefix
protected String getBootloaderFilePrefix (ITestDevice device)
取得系統啟動載入程式檔案前置字串。
預設為 getBootPartitionName()
。子類別應視需要覆寫。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
傳回 | |
---|---|
String |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to get prefix |
getCurrentSlot
protected String getCurrentSlot (ITestDevice device)
輔助方法,用於擷取目前的時間間隔 (適用於支援 A/B 的裝置)。
參數 | |
---|---|
device |
ITestDevice :要執行指令的 ITestDevice 。 |
傳回 | |
---|---|
String |
「a」、「b」或空值 (如果裝置不支援 A/B 測試) |
擲回 | |
---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
TargetSetupError |
|
DeviceNotAvailableException |
getFlashingResourcesRetriever
protected IFlashingResourcesRetriever getFlashingResourcesRetriever ()
傳回 | |
---|---|
IFlashingResourcesRetriever |
getImageVersion
protected String getImageVersion (ITestDevice device, String imageName)
輔助方法,用於取得裝置上的目前圖片版本。
參數 | |
---|---|
device |
ITestDevice :要執行指令的 ITestDevice |
imageName |
String :要取得的圖片名稱。 |
傳回 | |
---|---|
String |
將指令的 stdout 輸出內容串連 |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
如果 fastboot 指令失敗或無法判斷版本 |
getRunUtil
protected IRunUtil getRunUtil ()
已公開供測試。
傳回 | |
---|---|
IRunUtil |
handleUserDataFlashing
protected void handleUserDataFlashing (ITestDevice device, IDeviceBuildInfo deviceBuild)
處理 userdata/cache 分區的閃燈作業
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含要刷新的檔案的 IDeviceBuildInfo |
擲回 | |
---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
TargetSetupError |
|
DeviceNotAvailableException |
hasPartition
protected boolean hasPartition (ITestDevice device, String partition)
透過系統啟動載入程式檢查指定的分區是否存在
參數 | |
---|---|
device |
ITestDevice :要運算的 ITestDevice |
partition |
String :要檢查的分區名稱 |
傳回 | |
---|---|
boolean |
擲回 | |
---|---|
DeviceNotAvailableException |
preFlashSetup
protected void preFlashSetup (ITestDevice device, IDeviceBuildInfo deviceBuild)
執行任何必要的預先刷新設定。除非覆寫,否則為無操作。
參數 | |
---|---|
device |
ITestDevice :要準備的 ITestDevice |
deviceBuild |
IDeviceBuildInfo :包含建構檔案的 IDeviceBuildInfo |
擲回 | |
---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
TargetSetupError |
|
DeviceNotAvailableException |
verifyRequiredBoards
protected void verifyRequiredBoards (ITestDevice device, IFlashingResourcesParser resourceParser, String deviceProductType)
確認裝置的產品類型支援要刷新的版本。
基本實作會驗證 deviceProductType 是否包含在 IFlashingResourcesParser.getRequiredBoards()
集合中。子類別可視需要覆寫。
參數 | |
---|---|
device |
ITestDevice :要刷新的 ITestDevice |
resourceParser |
IFlashingResourcesParser :IFlashingResourcesParser |
deviceProductType |
String :device 的產品類型 |
擲回 | |
---|---|
TargetSetupError |
如果版本的必要板卡資訊與裝置不符 |
wipeCache
protected void wipeCache (ITestDevice device)
清除裝置上的快取分區。
參數 | |
---|---|
device |
ITestDevice :要閃爍的 ITestDevice |
擲回 | |
---|---|
DeviceNotAvailableException |
如無法使用裝置 |
TargetSetupError |
if failed to flash cache |
wipePartition
protected void wipePartition (ITestDevice device, String partition)
使用 `fastboot erase <name>` 清除指定的分割區
參數 | |
---|---|
device |
ITestDevice :要運算的 ITestDevice |
partition |
String :要清除的分區名稱 |
擲回 | |
---|---|
DeviceNotAvailableException |
|
TargetSetupError |