to top
public class

FastbootDeviceFlasher

extends Object
implements IDeviceFlasher
java.lang.Object
   ↳ com.android.tradefed.targetprep.FastbootDeviceFlasher
Known Direct Subclasses

Class Overview

A class that relies on fastboot to flash an image on physical Android hardware.

Summary

Constants
String BASEBAND_IMAGE_NAME
Public Constructors
FastbootDeviceFlasher()
Public Methods
void flash(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flashes build on device.
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 setDataWipeSkipList(Collection<String> dataWipeSkipList)
Sets the list of paths under /data to avoid clearing when using ERROR(/ITestsZipInsaller)

Note that the granularity of the skip list is direct children of /data.

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 setUserDataFlashOption(IDeviceFlasher.UserDataFlashOption flashOption)
Toggles whether the user data image should be flashed, wiped, or retained
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)
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.
void flashBaseband(ITestDevice device, File basebandImageFile)
Flashes the given baseband image and reboot back into bootloader
void flashBootloader(ITestDevice device, File bootloaderImageFile)
Flashes the given bootloader image and reboots back into bootloader
void flashPartition(ITestDevice device, File imgFile, String partition)
Flash an individual partition of a device
void flashSystem(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flash the system image on device.
void flashUserData(ITestDevice device, IDeviceBuildInfo deviceBuild)
Flash userdata partition on device.
String getBootPartitionName()
Get the boot partition name for this device flasher.
String getBootloaderFilePrefix(ITestDevice device)
Get the bootloader file prefix.
IFlashingResourcesRetriever getFlashingResourcesRetriever()
String getImageVersion(ITestDevice device, String imageName)
Helper method to get the current image version on device.
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>`
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.tradefed.targetprep.IDeviceFlasher

Constants

public static final String BASEBAND_IMAGE_NAME

Constant Value: "radio"

Public Constructors

public FastbootDeviceFlasher ()

Public Methods

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.

Parameters
device the ITestDevice to flash
deviceBuild the IDeviceBuildInfo to flash

public IDeviceFlasher.UserDataFlashOption getUserDataFlashOption ()

Gets whether the user data image should be flashed, wiped, or retained

Returns
  • Whether the user data image should be flashed, wiped, or retained

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.

public void setDataWipeSkipList (Collection<String> dataWipeSkipList)

Sets the list of paths under /data to avoid clearing when using ERROR(/ITestsZipInsaller)

Note that the granularity of the skip list is direct children of /data.

public void setFlashingResourcesRetriever (IFlashingResourcesRetriever retriever)

Sets the mechanism by which the flasher can retrieve resource files for flashing.

Parameters
retriever the IFlashingResourcesRetriever to use

public void setForceSystemFlash (boolean forceSystemFlash)

Sets if system should always be flashed even if running current build

public void setUserDataFlashOption (IDeviceFlasher.UserDataFlashOption flashOption)

Toggles whether the user data image should be flashed, wiped, or retained

Protected Methods

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 the ITestDevice to flash
deviceBuild the IDeviceBuildInfo that contains the baseband image to flash
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash baseband

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 the ITestDevice to flash
deviceBuild the IDeviceBuildInfo that contains the bootloader image to flash
Returns
  • true if bootloader was flashed, false if it was skipped
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash bootloader

protected boolean checkAndFlashSystem (ITestDevice device, String systemBuildId, String systemBuildFlavor, IDeviceBuildInfo deviceBuild)

If needed, flash the system image on device.

Please look at shouldFlashSystem(String, String, IDeviceBuildInfo)

Regardless of path chosen, after method execution device should be booting into userspace.

Parameters
device the ITestDevice to flash
systemBuildId the current build id running on the device
systemBuildFlavor the current build flavor running on the device
deviceBuild the IDeviceBuildInfo that contains the system image to flash
Returns
  • true if system was flashed, false if it was skipped
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash bootloader

protected boolean checkShouldFlashBaseband (ITestDevice device, IDeviceBuildInfo deviceBuild)

Check if the baseband on the provided device needs to be flashed.

Parameters
device the ITestDevice to check
deviceBuild the IDeviceBuildInfo that contains the baseband image to check
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash baseband

protected IFlashingResourcesParser createFlashingResourcesParser (IDeviceBuildInfo localBuild)

Factory method for creating a IFlashingResourcesParser.

Exposed for unit testing.

Parameters
localBuild the IDeviceBuildInfo to parse

protected void downloadExtraImageFiles (IFlashingResourcesParser resourceParser, IFlashingResourcesRetriever retriever, IDeviceBuildInfo localBuild)

Hook to allow subclasses to download extra custom image files if needed.

Parameters
resourceParser the IFlashingResourcesParser
retriever the IFlashingResourcesRetriever
localBuild the IDeviceBuildInfo

protected void downloadFlashingResources (ITestDevice device, IDeviceBuildInfo localBuild)

Downloads extra flashing image files needed

Parameters
device the ITestDevice to download resources for
localBuild the IDeviceBuildInfo to populate. Assumes device image file is already set
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to retrieve resources

protected String executeFastbootCmd (ITestDevice device, String... cmdArgs)

Helper method to execute fastboot command.

Parameters
device the ITestDevice to execute command on
cmdArgs the arguments to provide to fastboot
Returns
  • 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
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if fastboot command fails

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 executeFastbootCommand(String). However, when multiple devices are flashing devices at once, fastboot commands can take much longer than normal.

Parameters
device the ITestDevice to execute command on
cmdArgs the arguments to provide to fastboot
Returns
  • 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
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if fastboot command fails

protected void flashBaseband (ITestDevice device, File basebandImageFile)

Flashes the given baseband image and reboot back into bootloader

Parameters
device the ITestDevice to flash
basebandImageFile the baseband image File
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash baseband

protected void flashBootloader (ITestDevice device, File bootloaderImageFile)

Flashes the given bootloader image and reboots back into bootloader

Parameters
device the ITestDevice to flash
bootloaderImageFile the bootloader image File
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash

protected void flashPartition (ITestDevice device, File imgFile, String partition)

Flash an individual partition of a device

Parameters
device the ITestDevice to flash
imgFile a File pointing to the image to be flashed
partition the name of the partition to be flashed

protected void flashSystem (ITestDevice device, IDeviceBuildInfo deviceBuild)

Flash the system image on device.

Parameters
device the ITestDevice to flash
deviceBuild the IDeviceBuildInfo to flash
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if fastboot command fails

protected void flashUserData (ITestDevice device, IDeviceBuildInfo deviceBuild)

Flash userdata partition on device.

Parameters
device the ITestDevice to flash
deviceBuild the IDeviceBuildInfo that contains the files to flash
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash user data

protected String getBootPartitionName ()

Get the boot partition name for this device flasher.

Defaults to 'hboot'. Subclasses should override if necessary.

protected String getBootloaderFilePrefix (ITestDevice device)

Get the bootloader file prefix.

Defaults to getBootPartitionName(). Subclasses should override if necessary.

Parameters
device the ITestDevice to flash
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to get prefix

protected IFlashingResourcesRetriever getFlashingResourcesRetriever ()

protected String getImageVersion (ITestDevice device, String imageName)

Helper method to get the current image version on device.

Parameters
device the ITestDevice to execute command on
imageName the name of image to get.
Returns
  • String the stdout output from command
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if fastboot command fails or version could not be determined

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 getRequiredBoards() collection. Subclasses may override as desired.

Parameters
device the ITestDevice to be flashed
resourceParser the IFlashingResourcesParser
deviceProductType the device's product type
Throws
TargetSetupError if the build's required board info did not match the device

protected void wipeCache (ITestDevice device)

Wipe the cache partition on device.

Parameters
device the ITestDevice to flash
Throws
DeviceNotAvailableException if device is not available
TargetSetupError if failed to flash cache

protected void wipePartition (ITestDevice device, String partition)

Wipe the specified partition with `fastboot erase <name>`

Parameters
device the ITestDevice to operate on
partition the name of the partition to be wiped