GkiDeviceFlashPreparer

public class GkiDeviceFlashPreparer
extends BaseTargetPreparer implements ILabPreparer

java.lang.Object
   ↳ com.android.tradefed.targetprep.BaseTargetPreparer
     ↳ com.android.tradefed.targetprep.GkiDeviceFlashPreparer


A target preparer that flash the device with android common kernel generic image. Please see https://source.android.com/devices/architecture/kernel/android-common for details.

Summary

Public constructors

GkiDeviceFlashPreparer()

Public methods

void setUp(TestInformation testInfo)

Perform the target setup for testing.

void validateGkiBootImg(ITestDevice device, IBuildInfo buildInfo)

Validate GKI boot image is expected.

Protected methods

void addHashFooter(ITestDevice device, IBuildInfo buildInfo, File tmpDir)

Validate GKI boot image is expected.

void buildGkiSystemDlkmImg(ITestDevice device, IBuildInfo buildInfo, File tmpDir)

Build GKI system_dlkm image if the system_dlkm archive is provided.

File extractSystemDlkmTarGzip(File systemDlkmArchive)

Extracts the system_dlkm tar gzip file into the system_dlkm_staging folder.

void flattenSystemDlkm(ITestDevice device, File systemDlkmStagingDir)

Flatten the system_dlkm staging directory so that all the kernel modules are directly under /lib/modules.

String[] getDeviceKernelVersion(ITestDevice device)

Get device kernel version from the device before flashing.

IHostOptions getHostOptions()

Get a reference to the IHostOptions

String[] getKernelVersionFromImage(File image)

Extracts the kernel version from a boot/vendor_boot/system_dlkm/vendor_dlkm image files.

File getRequestedFile(ITestDevice device, String requestedFileName, File sourceFile, File tmpDir)

Get the requested file from the source file (zip or folder) by requested file name.

IRunUtil getRunUtil()

Get the IRunUtil instance to use.

String[] parseKernelVersion(String source, String kernelVersionString)
void validateGkiBootImg(ITestDevice device, IBuildInfo buildInfo, File tmpDir)

Validate GKI boot image is expected.

void validateKernelCompatibility(String imageName, String[] imageVersion, String[] bootVersion, ITestDevice device)
void validateKernelVersion(ITestDevice device, IBuildInfo buildInfo, File tmpDir)

Validate kernel versions in the images are expected.

Public constructors

GkiDeviceFlashPreparer

public GkiDeviceFlashPreparer ()

Public methods

setUp

public void setUp (TestInformation testInfo)

Perform the target setup for testing.

Parameters
testInfo TestInformation: The TestInformation of the invocation.

Throws
BuildError
DeviceNotAvailableException
TargetSetupError

validateGkiBootImg

public void validateGkiBootImg (ITestDevice device, 
                IBuildInfo buildInfo)

Validate GKI boot image is expected. (Obsoleted. Please call with tmpDir provided)

Parameters
device ITestDevice: the ITestDevice

buildInfo IBuildInfo: the IBuildInfo the build info

Throws
TargetSetupError if there is no valid gki boot.img

Protected methods

addHashFooter

protected void addHashFooter (ITestDevice device, 
                IBuildInfo buildInfo, 
                File tmpDir)

Validate GKI boot image is expected. Throw exception if there is no valid boot.img.

Parameters
device ITestDevice: the ITestDevice

buildInfo IBuildInfo: the IBuildInfo the build info

tmpDir File: the temporary directory File

Throws
TargetSetupError if there is no valid gki boot.img
DeviceNotAvailableException

buildGkiSystemDlkmImg

protected void buildGkiSystemDlkmImg (ITestDevice device, 
                IBuildInfo buildInfo, 
                File tmpDir)

Build GKI system_dlkm image if the system_dlkm archive is provided.

Parameters
device ITestDevice: the ITestDevice

buildInfo IBuildInfo: the IBuildInfo the build info

tmpDir File: the temporary directory File

Throws
TargetSetupError if there is an error building the image file.

extractSystemDlkmTarGzip

protected File extractSystemDlkmTarGzip (File systemDlkmArchive)

Extracts the system_dlkm tar gzip file into the system_dlkm_staging folder. This function is a wrapper around ERROR(/TarUtil.extractTarGzipToTemp) in order to stub out the untarring for unit testing.

Parameters
systemDlkmArchive File: the system_dlkm tar gzip file containing GKI modules.

Returns
File File containing the system_dlkm tar gzip contents.

Throws
java.io.IOException
IOException

flattenSystemDlkm

protected void flattenSystemDlkm (ITestDevice device, 
                File systemDlkmStagingDir)

Flatten the system_dlkm staging directory so that all the kernel modules are directly under /lib/modules. This is necessary to match the expected system_dlkm file layout for platform builds.

Parameters
device ITestDevice: the ITestDevice

systemDlkmStagingDir File: the system_dlkm staging directory File

Throws
IOException or TargetSetupError if there is an error flattening the system_dlkm.
TargetSetupError

getDeviceKernelVersion

protected String[] getDeviceKernelVersion (ITestDevice device)

Get device kernel version from the device before flashing.

Parameters
device ITestDevice: The ITestDevice to get kernel version from.

Returns
String[] A ERROR(/String[]) containing the parsed kernel version info: [kernelVersion, patchLevel, pageSize]. Returns null if the version string cannot be parsed.2

Throws
DeviceNotAvailableException

getHostOptions

protected IHostOptions getHostOptions ()

Get a reference to the IHostOptions

Returns
IHostOptions the IHostOptions to use

getKernelVersionFromImage

protected String[] getKernelVersionFromImage (File image)

Extracts the kernel version from a boot/vendor_boot/system_dlkm/vendor_dlkm image files. This method reads the boot/vendor_boot/system_dlkm/vendor_dlkm image file and searches for a specific pattern in Android kernel version strings. It then parses the found string to extract the kernel version in a standardized format.

Parameters
image File: The File to the boot image file (e.g., boot.img).

Returns
String[] A ERROR(/String[]) containing the parsed kernel version info: [kernelVersion, patchLevel, pageSize]. Returns null if the version string cannot be parsed.

getRequestedFile

protected File getRequestedFile (ITestDevice device, 
                String requestedFileName, 
                File sourceFile, 
                File tmpDir)

Get the requested file from the source file (zip or folder) by requested file name.

The provided source file can be a zip file. The method will unzip it to tempary directory and find the requested file by the provided file name.

The provided source file can be a file folder. The method will find the requestd file by the provided file name.

Parameters
device ITestDevice: the ITestDevice

requestedFileName String: the requeste file name String

sourceFile File: the source file

tmpDir File

Returns
File the file that is specified by the requested file name

Throws
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

getRunUtil

protected IRunUtil getRunUtil ()

Get the IRunUtil instance to use.

Returns
IRunUtil the IRunUtil to use

parseKernelVersion

protected String[] parseKernelVersion (String source, 
                String kernelVersionString)

Parameters
source String

kernelVersionString String

Returns
String[]

validateGkiBootImg

protected void validateGkiBootImg (ITestDevice device, 
                IBuildInfo buildInfo, 
                File tmpDir)

Validate GKI boot image is expected. Throw exception if there is no valid boot.img.

Parameters
device ITestDevice: the ITestDevice

buildInfo IBuildInfo: the IBuildInfo the build info

tmpDir File: the temporary directory File

Throws
TargetSetupError if there is no valid gki boot.img

validateKernelCompatibility

protected void validateKernelCompatibility (String imageName, 
                String[] imageVersion, 
                String[] bootVersion, 
                ITestDevice device)

Parameters
imageName String

imageVersion String

bootVersion String

device ITestDevice

Throws
TargetSetupError

validateKernelVersion

protected void validateKernelVersion (ITestDevice device, 
                IBuildInfo buildInfo, 
                File tmpDir)

Validate kernel versions in the images are expected. Throw exception if not valid.

Parameters
device ITestDevice: the ITestDevice

buildInfo IBuildInfo: the IBuildInfo the build info

tmpDir File: the temporary directory File

Throws
TargetSetupError if there is no valid gki boot.img
DeviceNotAvailableException