FastbootDeviceFlasher
public
class
FastbootDeviceFlasher
extends Object
implements
IDeviceFlasher
| java.lang.Object
|
| ↳ |
com.android.tradefed.targetprep.FastbootDeviceFlasher
|
Known direct subclasses
| CdmaDeviceFlasher |
A class that flashes an image on a physical Android device with a CDMA radio.
|
|
A class that relies on fastboot to flash an image on physical Android hardware.
Summary
Public methods |
static
String
|
fetchImageVersion(IRunUtil runUtil, ITestDevice device, String imageName)
Helper method to get the current image version on device.
|
void
|
flash(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flashes build on device.
|
CommandStatus
|
getSystemFlashingStatus()
Retrieve the command execution status for flashing primary system partitions.
|
IDeviceFlasher.UserDataFlashOption
|
getUserDataFlashOption()
Gets whether the user data image should be flashed, wiped, or retained
|
void
|
overrideDeviceOptions(ITestDevice device)
Override options for a device.
|
void
|
preFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild)
All setup operations & checks that must occur before actual flashing critical section.
|
void
|
setDataWipeSkipList(Collection<String> dataWipeSkipList)
Sets the list of paths under /data to avoid clearing when using
ITestsZipInstaller
Note that the granularity of the skip list is direct children of /data.
|
void
|
setFlashOptions(Collection<String> flashOptions)
Sets a list of options to pass with flash/update commands.
|
void
|
setFlashingResourcesRetriever(IFlashingResourcesRetriever retriever)
Sets the mechanism by which the flasher can retrieve resource files for flashing.
|
void
|
setForceSystemFlash(boolean forceSystemFlash)
Sets if system should always be flashed even if running current build
|
void
|
setIncrementalFlashing(IncrementalImageUtil incrementalUtil)
|
void
|
setRamdiskPartition(String ramdiskPartition)
Sets ramdisk partition
|
void
|
setShouldFlashRamdisk(boolean shouldFlashRamdisk)
Sets if an additional ramdisk should be flashed after updating device via image zip
|
void
|
setUserDataFlashOption(IDeviceFlasher.UserDataFlashOption flashOption)
Toggles whether the user data image should be flashed, wiped, or retained
|
void
|
setWipeTimeout(long timeout)
Set the timeout for wiping the data.
|
boolean
|
shouldCheckBasebandVersionAfterFlash()
|
boolean
|
shouldFlashRamdisk()
Checks if the flasher is set to have an additional ramdisk should be flashed after updating
device via image zip
|
boolean
|
shouldSkipBasebandVersionCheck()
|
boolean
|
shouldSkipBootloaderVersionCheck()
|
static
boolean
|
stderrContainsFailed(String stderr, boolean skipBootloaderVersionCheck, boolean skipBasebandVersionCheck, boolean skipFastbootFailedMessage)
|
static
boolean
|
stderrContainsFailed(String stderr, boolean skipBootloaderVersionCheck, boolean skipBasebandVersionCheck)
|
Protected methods |
void
|
checkAndFlashBaseband(ITestDevice device, IDeviceBuildInfo deviceBuild)
If needed, flash the baseband image on device.
|
boolean
|
checkAndFlashBootloader(ITestDevice device, IDeviceBuildInfo deviceBuild)
If needed, flash the bootloader image on device.
|
boolean
|
checkAndFlashSystem(ITestDevice device, String systemBuildId, String systemBuildFlavor, IDeviceBuildInfo deviceBuild)
If needed, flash the system image on device.
|
boolean
|
checkShouldFlashBaseband(ITestDevice device, IDeviceBuildInfo deviceBuild)
Check if the baseband on the provided device needs to be flashed.
|
IFlashingResourcesParser
|
createFlashingResourcesParser(IDeviceBuildInfo localBuild, DeviceDescriptor descriptor)
Factory method for creating a IFlashingResourcesParser.
|
void
|
downloadExtraImageFiles(IFlashingResourcesParser resourceParser, IFlashingResourcesRetriever retriever, IDeviceBuildInfo localBuild)
Hook to allow subclasses to download extra custom image files if needed.
|
void
|
downloadFlashingResources(ITestDevice device, IDeviceBuildInfo localBuild)
Downloads extra flashing image files needed
|
String
|
executeFastbootCmd(ITestDevice device, String... cmdArgs)
Helper method to execute fastboot command.
|
String
|
executeLongFastbootCmd(ITestDevice device, String... cmdArgs)
Helper method to execute a long-running fastboot command.
|
String
|
executeLongFastbootCmd(ITestDevice device, Map<String, String> envVarMap, String... cmdArgs)
Helper method to execute a long-running fastboot command with environment variables.
|
void
|
flashBaseband(ITestDevice device, File basebandImageFile)
Flashes the given baseband image and reboot back into bootloader
|
void
|
flashBootloader(ITestDevice device, File bootloaderImageFile, boolean requireReboot)
Flashes the given bootloader image.
|
void
|
flashBootloader(ITestDevice device, File bootloaderImageFile)
Flashes the given bootloader image and reboots back into bootloader
|
void
|
flashExtraImages(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flash any device specific partitions before flashing system and rebooting.
|
void
|
flashPartition(ITestDevice device, File imgFile, String partition)
Flash an individual partition of a device
|
void
|
flashRamdiskIfNeeded(ITestDevice device, IDeviceBuildInfo deviceBuild)
|
void
|
flashSystem(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flash the system image on device.
|
void
|
flashTrusty(ITestDevice device, File trustyImageFile)
Flashes the given trusty image and reboots back into bootloader
|
void
|
flashUserData(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flash userdata partition on device.
|
void
|
flashUserDataFromDeviceImageFile(ITestDevice device, IDeviceBuildInfo deviceBuild)
Extracts the userdata.img from device image file and flashes it onto device
|
String
|
getBootPartitionName()
Get the boot partition name for this device flasher.
|
String
|
getBootloaderFilePrefix(ITestDevice device)
Get the bootloader file prefix.
|
String
|
getCurrentSlot(ITestDevice device)
Helper method to retrieve the current slot (for A/B capable devices).
|
IFlashingResourcesRetriever
|
getFlashingResourcesRetriever()
|
FuseUtil
|
getFuseUtil()
|
String
|
getImageVersion(ITestDevice device, String imageName)
|
IRunUtil
|
getRunUtil()
Exposed for testing.
|
void
|
handleUserDataFlashing(ITestDevice device, IDeviceBuildInfo deviceBuild)
Handle flashing of userdata/cache partition
|
boolean
|
hasPartition(ITestDevice device, String partition)
Checks with the bootloader if the specified partition exists or not
|
void
|
preFlashSetup(ITestDevice device, IDeviceBuildInfo deviceBuild)
Perform any additional pre-flashing setup required.
|
void
|
setCheckBasebandVersionAfterFlash(boolean checkBasebandVersionAfterFlash)
|
void
|
setSkipBasebandVersionCheck(boolean skipBasebandVersionCheck)
|
void
|
setSkipBootloaderVersionCheck(boolean skipBootloaderVersionCheck)
|
void
|
setSkipFastbootFailedMessage(boolean skipFastbootFailedMessage)
|
void
|
setSystemBuildInfo(String systemBuildId, String systemBuildFlavor)
|
void
|
verifyRequiredBoards(ITestDevice device, IFlashingResourcesParser resourceParser, String deviceProductType)
Verify that the device's product type supports the build-to-be-flashed.
|
void
|
wipeCache(ITestDevice device)
Wipe the cache partition on device.
|
void
|
wipePartition(ITestDevice device, String partition)
Wipe the specified partition with `fastboot erase <name>`
|
Constants
BASEBAND_IMAGE_NAME
public static final String BASEBAND_IMAGE_NAME
Constant Value:
"radio"
Public constructors
FastbootDeviceFlasher
public FastbootDeviceFlasher ()
Public methods
fetchImageVersion
public static String fetchImageVersion (IRunUtil runUtil,
ITestDevice device,
String imageName)
Helper method to get the current image version on device.
| Parameters |
runUtil |
IRunUtil |
device |
ITestDevice: the ITestDevice to execute command on |
imageName |
String: the name of image to get. |
| Returns |
String |
String the stdout output from command |
flash
public void flash (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Flashes build on device.
Returns immediately after flashing is complete. Callers should wait for device to be
online and available before proceeding with testing.
getSystemFlashingStatus
public CommandStatus getSystemFlashingStatus ()
Retrieve the command execution status for flashing primary system partitions.
Note that if system partitions are not flashed (system already has the build to be flashed)
the command status may be null
overrideDeviceOptions
public void overrideDeviceOptions (ITestDevice device)
Override options for a device. Used to override default option values if the defaults are not
supported by a particular device.
preFlashOperations
public void preFlashOperations (ITestDevice device,
IDeviceBuildInfo deviceBuild)
All setup operations & checks that must occur before actual flashing critical section. None
of those operations will be included in the concurrency-controlled critical section.
setDataWipeSkipList
public void setDataWipeSkipList (Collection<String> dataWipeSkipList)
Sets the list of paths under /data to avoid clearing when using
ITestsZipInstaller
Note that the granularity of the skip list is direct children of
/data.
| Parameters |
dataWipeSkipList |
Collection |
setFlashOptions
public void setFlashOptions (Collection<String> flashOptions)
Sets a list of options to pass with flash/update commands.
setFlashingResourcesRetriever
public void setFlashingResourcesRetriever (IFlashingResourcesRetriever retriever)
Sets the mechanism by which the flasher can retrieve resource files for flashing.
setForceSystemFlash
public void setForceSystemFlash (boolean forceSystemFlash)
Sets if system should always be flashed even if running current build
setIncrementalFlashing
public void setIncrementalFlashing (IncrementalImageUtil incrementalUtil)
| Parameters |
incrementalUtil |
IncrementalImageUtil |
setRamdiskPartition
public void setRamdiskPartition (String ramdiskPartition)
Sets ramdisk partition
setShouldFlashRamdisk
public void setShouldFlashRamdisk (boolean shouldFlashRamdisk)
Sets if an additional ramdisk should be flashed after updating device via image zip
setUserDataFlashOption
public void setUserDataFlashOption (IDeviceFlasher.UserDataFlashOption flashOption)
Toggles whether the user data image should be flashed, wiped, or retained
setWipeTimeout
public void setWipeTimeout (long timeout)
Set the timeout for wiping the data.
shouldCheckBasebandVersionAfterFlash
public boolean shouldCheckBasebandVersionAfterFlash ()
shouldFlashRamdisk
public boolean shouldFlashRamdisk ()
Checks if the flasher is set to have an additional ramdisk should be flashed after updating
device via image zip
shouldSkipBasebandVersionCheck
public boolean shouldSkipBasebandVersionCheck ()
shouldSkipBootloaderVersionCheck
public boolean shouldSkipBootloaderVersionCheck ()
stderrContainsFailed
public static boolean stderrContainsFailed (String stderr,
boolean skipBootloaderVersionCheck,
boolean skipBasebandVersionCheck,
boolean skipFastbootFailedMessage)
| Parameters |
stderr |
String |
skipBootloaderVersionCheck |
boolean |
skipBasebandVersionCheck |
boolean |
skipFastbootFailedMessage |
boolean |
stderrContainsFailed
public static boolean stderrContainsFailed (String stderr,
boolean skipBootloaderVersionCheck,
boolean skipBasebandVersionCheck)
| Parameters |
stderr |
String |
skipBootloaderVersionCheck |
boolean |
skipBasebandVersionCheck |
boolean |
Protected methods
checkAndFlashBaseband
protected void checkAndFlashBaseband (ITestDevice device,
IDeviceBuildInfo deviceBuild)
If needed, flash the baseband image on device. Will only flash baseband if current version on
device != required version
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the baseband image to flash |
checkAndFlashBootloader
protected boolean checkAndFlashBootloader (ITestDevice device,
IDeviceBuildInfo deviceBuild)
If needed, flash the bootloader image on device.
Will only flash bootloader if current version on device != required version.
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the bootloader image to flash |
| Returns |
boolean |
true if bootloader was flashed, false if it was skipped |
checkAndFlashSystem
protected boolean checkAndFlashSystem (ITestDevice device,
String systemBuildId,
String systemBuildFlavor,
IDeviceBuildInfo deviceBuild)
If needed, flash the system image on device.
Please look at ERROR(shouldFlashSystem(String,String,IDeviceBuildInfo)/#shouldFlashSystem(java.lang.String,java.lang.String,com.android.tradefed.build.IDeviceBuildInfo) shouldFlashSystem(String,String,IDeviceBuildInfo))
Regardless of path chosen, after method execution device should be booting into userspace.
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
systemBuildId |
String: the current build id running on the device |
systemBuildFlavor |
String: the current build flavor running on the device |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the system image to flash |
| Returns |
boolean |
true if system was flashed, false if it was skipped |
checkShouldFlashBaseband
protected boolean checkShouldFlashBaseband (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Check if the baseband on the provided device needs to be flashed.
| Parameters |
device |
ITestDevice: the ITestDevice to check |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the baseband image to check |
downloadFlashingResources
protected void downloadFlashingResources (ITestDevice device,
IDeviceBuildInfo localBuild)
Downloads extra flashing image files needed
| Parameters |
device |
ITestDevice: the ITestDevice to download resources for |
localBuild |
IDeviceBuildInfo: the IDeviceBuildInfo to populate. Assumes device image file is
already set |
executeFastbootCmd
protected String executeFastbootCmd (ITestDevice device,
String... cmdArgs)
Helper method to execute fastboot command.
| Parameters |
device |
ITestDevice: the ITestDevice to execute command on |
cmdArgs |
String: the arguments to provide to fastboot |
| Returns |
String |
String the stderr output from command if non-empty. Otherwise returns the stdout Some
fastboot commands are weird in that they dump output to stderr on success case |
executeLongFastbootCmd
protected String executeLongFastbootCmd (ITestDevice device,
String... cmdArgs)
Helper method to execute a long-running fastboot command.
Note: Most fastboot commands normally execute within the timeout allowed by ITestDevice.executeFastbootCommand(String...). However, when multiple devices are flashing
devices at once, fastboot commands can take much longer than normal.
| Parameters |
device |
ITestDevice: the ITestDevice to execute command on |
cmdArgs |
String: the arguments to provide to fastboot |
| Returns |
String |
String the stderr output from command if non-empty. Otherwise returns the stdout Some
fastboot commands are weird in that they dump output to stderr on success case |
executeLongFastbootCmd
protected String executeLongFastbootCmd (ITestDevice device,
Map<String, String> envVarMap,
String... cmdArgs)
Helper method to execute a long-running fastboot command with environment variables.
Note: Most fastboot commands normally execute within the timeout allowed by ITestDevice.executeFastbootCommand(String...). However, when multiple devices are flashing
devices at once, fastboot commands can take much longer than normal.
| Parameters |
device |
ITestDevice: the ITestDevice to execute command on |
envVarMap |
Map: the map which carries environment variables which need to be set before
running the fastboot command |
cmdArgs |
String: the arguments to provide to fastboot |
| Returns |
String |
String the stderr output from command if non-empty. Otherwise returns the stdout Some
fastboot commands are weird in that they dump output to stderr on success case |
flashBaseband
protected void flashBaseband (ITestDevice device,
File basebandImageFile)
Flashes the given baseband image and reboot back into bootloader
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
basebandImageFile |
File: the baseband image File |
flashBootloader
protected void flashBootloader (ITestDevice device,
File bootloaderImageFile,
boolean requireReboot)
Flashes the given bootloader image.
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
bootloaderImageFile |
File: the bootloader image File |
requireReboot |
boolean: whether to reboot after flashing |
flashBootloader
protected void flashBootloader (ITestDevice device,
File bootloaderImageFile)
Flashes the given bootloader image and reboots back into bootloader
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
bootloaderImageFile |
File: the bootloader image File |
flashExtraImages
protected void flashExtraImages (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Flash any device specific partitions before flashing system and rebooting. No-op unless
overridden.
flashPartition
protected void flashPartition (ITestDevice device,
File imgFile,
String partition)
Flash an individual partition of a device
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
imgFile |
File: a File pointing to the image to be flashed |
partition |
String: the name of the partition to be flashed |
flashRamdiskIfNeeded
protected void flashRamdiskIfNeeded (ITestDevice device,
IDeviceBuildInfo deviceBuild)
| Parameters |
device |
ITestDevice |
deviceBuild |
IDeviceBuildInfo |
flashTrusty
protected void flashTrusty (ITestDevice device,
File trustyImageFile)
Flashes the given trusty image and reboots back into bootloader
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
trustyImageFile |
File: the trusty image File |
flashUserDataFromDeviceImageFile
protected void flashUserDataFromDeviceImageFile (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Extracts the userdata.img from device image file and flashes it onto device
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the files to flash |
getBootPartitionName
protected String getBootPartitionName ()
Get the boot partition name for this device flasher.
Defaults to 'bootloader'. Subclasses should override if necessary.
getBootloaderFilePrefix
protected String getBootloaderFilePrefix (ITestDevice device)
Get the bootloader file prefix.
Defaults to
getBootPartitionName(). Subclasses should override if necessary.
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
getCurrentSlot
protected String getCurrentSlot (ITestDevice device)
Helper method to retrieve the current slot (for A/B capable devices).
| Parameters |
device |
ITestDevice: the ITestDevice to execute command on. |
| Returns |
String |
"a", "b" or null (if device is not A/B capable) |
getFuseUtil
protected FuseUtil getFuseUtil ()
getImageVersion
protected String getImageVersion (ITestDevice device,
String imageName)
| Parameters |
device |
ITestDevice |
imageName |
String |
getRunUtil
protected IRunUtil getRunUtil ()
Exposed for testing.
handleUserDataFlashing
protected void handleUserDataFlashing (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Handle flashing of userdata/cache partition
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo that contains the files to flash |
hasPartition
protected boolean hasPartition (ITestDevice device,
String partition)
Checks with the bootloader if the specified partition exists or not
| Parameters |
device |
ITestDevice: the ITestDevice to operate on |
partition |
String: the name of the partition to be checked |
preFlashSetup
protected void preFlashSetup (ITestDevice device,
IDeviceBuildInfo deviceBuild)
Perform any additional pre-flashing setup required. No-op unless overridden.
| Parameters |
device |
ITestDevice: the ITestDevice to prepare |
deviceBuild |
IDeviceBuildInfo: the IDeviceBuildInfo containing the build files |
setCheckBasebandVersionAfterFlash
protected void setCheckBasebandVersionAfterFlash (boolean checkBasebandVersionAfterFlash)
| Parameters |
checkBasebandVersionAfterFlash |
boolean |
setSkipBasebandVersionCheck
protected void setSkipBasebandVersionCheck (boolean skipBasebandVersionCheck)
| Parameters |
skipBasebandVersionCheck |
boolean |
setSkipBootloaderVersionCheck
protected void setSkipBootloaderVersionCheck (boolean skipBootloaderVersionCheck)
| Parameters |
skipBootloaderVersionCheck |
boolean |
setSkipFastbootFailedMessage
protected void setSkipFastbootFailedMessage (boolean skipFastbootFailedMessage)
| Parameters |
skipFastbootFailedMessage |
boolean |
setSystemBuildInfo
protected void setSystemBuildInfo (String systemBuildId,
String systemBuildFlavor)
| Parameters |
systemBuildId |
String |
systemBuildFlavor |
String |
verifyRequiredBoards
protected void verifyRequiredBoards (ITestDevice device,
IFlashingResourcesParser resourceParser,
String deviceProductType)
Verify that the device's product type supports the build-to-be-flashed.
The base implementation will verify that the deviceProductType is included in the IFlashingResourcesParser.getRequiredBoards() collection. Subclasses may override as desired.
| Parameters |
device |
ITestDevice: the ITestDevice to be flashed |
resourceParser |
IFlashingResourcesParser: the IFlashingResourcesParser |
deviceProductType |
String: the device's product type |
| Throws |
TargetSetupError |
if the build's required board info did not match the device |
wipeCache
protected void wipeCache (ITestDevice device)
Wipe the cache partition on device.
| Parameters |
device |
ITestDevice: the ITestDevice to flash |
wipePartition
protected void wipePartition (ITestDevice device,
String partition)
Wipe the specified partition with `fastboot erase <name>`
| Parameters |
device |
ITestDevice: the ITestDevice to operate on |
partition |
String: the name of the partition to be wiped |