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()

公共方法

static String fetchImageVersion(IRunUtil runUtil, ITestDevice device, String imageName)

用于获取设备上的当前映像版本的辅助方法。

void flash(ITestDevice device, IDeviceBuildInfo deviceBuild)

在设备上构建刷写程序。

CommandStatus getSystemFlashingStatus()

检索刷写系统主分区的命令执行状态。

IDeviceFlasher.UserDataFlashOption getUserDataFlashOption()

获取应刷写、擦除还是保留用户数据映像

void overrideDeviceOptions(ITestDevice device)

替换设备的选项。

void preFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild)

在实际刷写关键部分之前必须执行的所有设置操作和检查。

void setDataWipeSkipList( dataWipeSkipList)

设置 /data 下的路径列表以避免在使用 ITestsZipInstaller 时被清除

请注意,跳过列表的粒度是 /data 的直接子项。

void setFlashOptions( flashOptions)

设置要使用 Flash/update 命令传递的选项列表。

void setFlashingResourcesRetriever(IFlashingResourcesRetriever retriever)

设置刷写程序检索资源文件进行刷写的机制。

void setForceSystemFlash(boolean forceSystemFlash)

设置是否应始终刷写系统(即使运行当前 build 也是如此)

void setIncrementalFlashing(IncrementalImageUtil incrementalUtil)
void setRamdiskPartition(String ramdiskPartition)

设置 ramdisk 分区

void setShouldFlashRamdisk(boolean shouldFlashRamdisk)

设置在通过映像 zip 更新设备后是否应刷写额外的 ramdisk

void setUserDataFlashOption(IDeviceFlasher.UserDataFlashOption flashOption)

用于切换是应该刷写、擦除还是保留用户数据映像

void setWipeTimeout(long timeout)

设置清除数据的超时时间。

boolean shouldFlashRamdisk()

检查闪存器是否设置为在通过映像 zip 更新设备后应刷写额外的 ramdisk

受保护的方法

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)

用于创建 IFlashingResourcesParser 的工厂方法。

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 命令的辅助方法。

String executeLongFastbootCmd(ITestDevice device, envVarMap, 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()
FuseUtil getFuseUtil()
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 setSystemBuildInfo(String systemBuildId, String systemBuildFlavor)
void verifyRequiredBoards(ITestDevice device, IFlashingResourcesParser resourceParser, String deviceProductType)

验证设备的产品类型是否支持要刷写的 build。

void wipeCache(ITestDevice device)

擦除设备上的缓存分区。

void wipePartition(ITestDevice device, String partition)

使用“fastbootWipe <name>”擦除指定的分区

字段

BASEBAND_IMAGE_NAME

public static final String BASEBAND_IMAGE_NAME

公共构造函数

fastbootDeviceFlasher

public FastbootDeviceFlasher ()

公共方法

fetchImageVersion

public static String fetchImageVersion (IRunUtil runUtil, 
                ITestDevice device, 
                String imageName)

用于获取设备上的当前映像版本的辅助方法。

参数
runUtil IRunUtil

device ITestDevice:要在其中执行命令的 ITestDevice

imageName String:要获取的映像的名称。

返回
String 将命令中的 stdout 输出字符串化

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果 fastboot 命令失败或无法确定版本

闪光灯

public void flash (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

在设备上构建刷写程序。

刷写完成后立即返回。调用方应等待设备在线且可用,然后再继续测试。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:要刷写的 IDeviceBuildInfo

抛出
DeviceNotAvailableException
TargetSetupError

getSystemFlashingStatus

public CommandStatus getSystemFlashingStatus ()

检索刷写系统主分区的命令执行状态。

请注意,如果未刷写系统分区(系统已有要刷写的 build),命令状态可能为 null

返回
CommandStatus

getUserDataFlashOption

public IDeviceFlasher.UserDataFlashOption getUserDataFlashOption ()

获取是应该刷写、擦除还是保留用户数据映像

返回
IDeviceFlasher.UserDataFlashOption 是应刷写、擦除还是保留用户数据图片

替换设备选项

public void overrideDeviceOptions (ITestDevice device)

覆盖设备的选项。用于在特定设备不支持默认值时替换默认选项值。

preFlashOperations

public void preFlashOperations (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

在实际刷写关键部分之前必须执行的所有设置操作和检查。所有这些操作都不会包含在并发控制的关键部分中。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:要刷写的 IDeviceBuildInfo

抛出
DeviceNotAvailableException
TargetSetupError

setDataWipeSkipList

public void setDataWipeSkipList ( dataWipeSkipList)

设置 /data 下的路径列表以避免在使用 ITestsZipInstaller 时被清除

请注意,跳过列表的粒度是 /data 的直接子项。

参数
dataWipeSkipList

setFlashOptions

public void setFlashOptions ( flashOptions)

设置要使用 Flash/update 命令传递的选项列表。

setFlashingResourcesRetriever

public void setFlashingResourcesRetriever (IFlashingResourcesRetriever retriever)

设置刷写程序检索资源文件进行刷写的机制。

参数
retriever IFlashingResourcesRetriever:要使用的 IFlashingResourcesRetriever

setForceSystemFlash

public void setForceSystemFlash (boolean forceSystemFlash)

设置是否应始终刷写系统(即使运行当前 build)

set 增量 Flashing

public void setIncrementalFlashing (IncrementalImageUtil incrementalUtil)

参数
incrementalUtil IncrementalImageUtil

setRamdiskPartition

public void setRamdiskPartition (String ramdiskPartition)

设置 ramdisk 分区

setShouldFlashRamdisk

public void setShouldFlashRamdisk (boolean shouldFlashRamdisk)

设置在通过映像 zip 更新设备后是否应刷写额外的 ramdisk

setUserDataFlashOption

public void setUserDataFlashOption (IDeviceFlasher.UserDataFlashOption flashOption)

用于切换是应该刷写、擦除还是保留用户数据图片

setWipeTimeout

public void setWipeTimeout (long timeout)

设置擦除数据的超时时间。

参数
timeout long

shouldFlashRamdisk

public boolean shouldFlashRamdisk ()

检查闪存器是否设置为在通过映像 zip 更新设备后应刷写额外的 ramdisk

返回
boolean

受保护的方法

checkAndFlashBaseband

protected void checkAndFlashBaseband (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

如果需要,请刷写设备上的基带映像。仅当设备上的当前版本 != 所需版本时,才会刷写基带

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:包含要刷写的基带映像的 IDeviceBuildInfo

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果无法刷写基带

checkAndFlash 引导加载程序

protected boolean checkAndFlashBootloader (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

如果需要,刷写设备上的引导加载程序映像。

仅当设备上的当前版本为 != 所需版本时,才会刷写引导加载程序。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:包含要刷写的引导加载程序映像的 IDeviceBuildInfo

返回
boolean 如果刷写引导加载程序,则为 true;如果跳过引导加载程序,则为 false

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果未能刷写引导加载程序

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:设备上运行的当前 build ID

systemBuildFlavor String:设备上运行的当前 build 变种

deviceBuild IDeviceBuildInfo:包含要刷写的系统映像的 IDeviceBuildInfo

返回
boolean 如果刷写系统,则为 true;如果跳过,则为 false

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果未能刷写引导加载程序

checkShouldFlashBaseband

protected boolean checkShouldFlashBaseband (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

检查是否需要对所提供的设备上的基带进行刷写。

参数
device ITestDevice:要检查的 ITestDevice

deviceBuild IDeviceBuildInfo:包含要检查的基带映像的 IDeviceBuildInfo

返回
boolean

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果无法刷写基带

createFlashingResourcesParser

protected IFlashingResourcesParser createFlashingResourcesParser (IDeviceBuildInfo localBuild, 
                DeviceDescriptor descriptor)

用于创建 IFlashingResourcesParser 的工厂方法。

公开用于单元测试。

参数
localBuild IDeviceBuildInfo:要解析的 IDeviceBuildInfo

descriptor DeviceDescriptor:要刷写的设备的描述符。

返回
IFlashingResourcesParser 通过工厂方法创建的 IFlashingResourcesParser

抛出
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

下载额外图片文件

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

用于允许子类根据需要下载额外的自定义图片文件的钩子。

参数
resourceParser IFlashingResourcesParserIFlashingResourcesParser

retriever IFlashingResourcesRetrieverIFlashingResourcesRetriever

localBuild IDeviceBuildInfoIDeviceBuildInfo

抛出
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

下载 FlashingResources

protected void downloadFlashingResources (ITestDevice device, 
                IDeviceBuildInfo localBuild)

下载需要额外的 Flash 图片文件

参数
device ITestDevice:要下载其资源的 ITestDevice

localBuild IDeviceBuildInfo:要填充的 IDeviceBuildInfo。假设已设置设备映像文件

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果未能检索到资源

执行 FastbootCmd

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

用于执行 fastboot 命令的辅助方法。

参数
device ITestDevice:要在其中执行命令的 ITestDevice

cmdArgs String:要提供给 fastboot 的参数

返回
String 将命令的 stderr 输出的字符串(如果非空)字符串。否则会返回 stdout。一些 fastboot 命令很奇怪,它们会在成功时将输出转储到 stderr

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果 fastboot 命令失败

执行 LongFastbootCmd

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

用于执行长时间运行的 fastboot 命令的辅助方法。

注意:大多数 fastboot 命令通常在 INativeDevice.executeFastbootCommand(String) 允许的超时内执行。不过,当多个设备同时刷写设备时,fastboot 命令花费的时间会比平常长得多。

参数
device ITestDevice:要在其中执行命令的 ITestDevice

cmdArgs String:要提供给 fastboot 的参数

返回
String 将命令的 stderr 输出的字符串(如果非空)字符串。否则会返回 stdout。一些 fastboot 命令很奇怪,它们会在成功时将输出转储到 stderr

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果 fastboot 命令失败

执行 LongFastbootCmd

protected String executeLongFastbootCmd (ITestDevice device, 
                 envVarMap, 
                String... cmdArgs)

使用环境变量执行长时间运行的 fastboot 命令的辅助方法。

注意:大多数 fastboot 命令通常在 INativeDevice.executeFastbootCommand(String) 允许的超时内执行。不过,当多个设备同时刷写设备时,fastboot 命令花费的时间会比平常长得多。

参数
device ITestDevice:要在其中执行命令的 ITestDevice

envVarMap :包含需要在运行 fastboot 命令之前设置的环境变量的映射

cmdArgs String:要提供给 fastboot 的参数

返回
String 将命令的 stderr 输出的字符串(如果非空)字符串。否则会返回 stdout。一些 fastboot 命令很奇怪,它们会在成功时将输出转储到 stderr

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果 fastboot 命令失败

Flash 基带

protected void flashBaseband (ITestDevice device, 
                File basebandImageFile)

刷写指定的基带映像,然后重新启动回引导加载程序

参数
device ITestDevice:要刷写的 ITestDevice

basebandImageFile File:基带映像 ERROR(/File)

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果无法刷写基带

刷写引导加载程序

protected void flashBootloader (ITestDevice device, 
                File bootloaderImageFile)

刷写指定的引导加载程序映像,并重新启动回引导加载程序

参数
device ITestDevice:要刷写的 ITestDevice

bootloaderImageFile File:引导加载程序映像 ERROR(/File)

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果刷写失败

FlashExtraImages

protected void flashExtraImages (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

在刷写系统和重新启动之前,先刷写所有设备专属分区。除非被替换,否则不会执行任何操作。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:包含 build 文件的 IDeviceBuildInfo

抛出
com.android.tradefed.device.DeviceNotAvailableException
com.android.tradefed.targetprep.TargetSetupError
DeviceNotAvailableException
TargetSetupError

刷写分区

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

刷写设备的单个分区

参数
device ITestDevice:要刷写的 ITestDevice

imgFile File:指向要刷写的映像的 ERROR(/File)

partition String:要刷写的分区的名称

抛出
DeviceNotAvailableException
TargetSetupError

刷写 RamdiskIfNeeded

protected void flashRamdiskIfNeeded (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

参数
device ITestDevice

deviceBuild IDeviceBuildInfo

抛出
DeviceNotAvailableException
TargetSetupError

刷写系统

protected void flashSystem (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

刷写设备上的系统映像。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:要刷写的 IDeviceBuildInfo

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果 fastboot 命令失败

刷写用户数据

protected void flashUserData (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

在设备上刷写 userdata 分区。

参数
device ITestDevice:要刷写的 ITestDevice

deviceBuild IDeviceBuildInfo:包含要刷写的文件的 IDeviceBuildInfo

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果未能刷写用户数据

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 如果未能获取前缀

getCurrentSlot

protected String getCurrentSlot (ITestDevice device)

用于检索当前槽位的辅助方法(适用于支持 A/B 的设备)。

参数
device ITestDevice:要在其中执行命令的 ITestDevice

返回
String “a”“b”或 null(如果设备不支持 A/B 功能)

抛出
com.android.tradefed.device.DeviceNotAvailableException
com.android.tradefed.targetprep.TargetSetupError
DeviceNotAvailableException
TargetSetupError

getFlashingResourcesRetriever

protected IFlashingResourcesRetriever getFlashingResourcesRetriever ()

返回
IFlashingResourcesRetriever

getFuseUtil

protected FuseUtil getFuseUtil ()

返回
FuseUtil

getImageVersion

protected String getImageVersion (ITestDevice device, 
                String imageName)

参数
device ITestDevice

imageName String

返回
String

抛出
DeviceNotAvailableException
TargetSetupError

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
com.android.tradefed.targetprep.TargetSetupError
DeviceNotAvailableException
TargetSetupError

has 分区

protected boolean hasPartition (ITestDevice device, 
                String partition)

向引导加载程序检查指定的分区是否存在

参数
device ITestDevice:要操作的 ITestDevice

partition String:要检查的分区的名称

返回
boolean

抛出
DeviceNotAvailableException

预刷写设置

protected void preFlashSetup (ITestDevice device, 
                IDeviceBuildInfo deviceBuild)

执行所需的任何其他预刷写设置。除非被替换,否则不执行任何操作。

参数
device ITestDevice:要准备的 ITestDevice

deviceBuild IDeviceBuildInfo:包含 build 文件的 IDeviceBuildInfo

抛出
com.android.tradefed.device.DeviceNotAvailableException
com.android.tradefed.targetprep.TargetSetupError
DeviceNotAvailableException
TargetSetupError

setSystemBuildInfo

protected void setSystemBuildInfo (String systemBuildId, 
                String systemBuildFlavor)

参数
systemBuildId String

systemBuildFlavor String

verifyRequiredBoards

protected void verifyRequiredBoards (ITestDevice device, 
                IFlashingResourcesParser resourceParser, 
                String deviceProductType)

验证设备的产品类型是否支持要刷写的 build。

基本实现方案将验证 deviceProductType 是否包含在 IFlashingResourcesParser.getRequiredBoards() 集合中。子类可以根据需要替换子类。

参数
device ITestDevice:要刷写的 ITestDevice

resourceParser IFlashingResourcesParserIFlashingResourcesParser

deviceProductType Stringdevice 的商品类型

抛出
TargetSetupError 如果 build 所需的板级信息与设备不匹配

擦除缓存

protected void wipeCache (ITestDevice device)

擦除设备上的缓存分区。

参数
device ITestDevice:要刷写的 ITestDevice

抛出
DeviceNotAvailableException 如果设备不可用
TargetSetupError 如果刷写缓存失败

擦除分区

protected void wipePartition (ITestDevice device, 
                String partition)

使用 `fastbootWipe <name>` 擦除指定的分区

参数
device ITestDevice:要操作的 ITestDevice

partition String:要擦除的分区的名称

抛出
DeviceNotAvailableException
TargetSetupError