diff options
author | jdesprez <jdesprez@google.com> | 2017-06-27 16:05:23 -0700 |
---|---|---|
committer | jdesprez <jdesprez@google.com> | 2017-07-03 02:44:46 -0700 |
commit | a140cfda112e0a480e75ed6c4af4759da507214b (patch) | |
tree | ccf7c5b4e211c9e2ea564049ccaee66eb2cf8da4 /src | |
parent | 8d14de37aa00f05a3fee67c2c380a6b0bc5ef915 (diff) | |
download | tradefederation-a140cfda112e0a480e75ed6c4af4759da507214b.tar.gz |
Add a check before flashing that device is matching build
Ensure that the device and the build info presented are
compatible and flashing could be attempted.
Test: unit tests
./tradefed.sh run google/util/flash --branch git_master --build-flavor
marlin-userdebug (against sailfish device)
Bug: 63041448
Change-Id: Icd6d7d66fad7e7edd68b4795533221a94ed66d29
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/tradefed/targetprep/DeviceFlashPreparer.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/com/android/tradefed/targetprep/DeviceFlashPreparer.java b/src/com/android/tradefed/targetprep/DeviceFlashPreparer.java index 96f4569ec..99a47fd8b 100644 --- a/src/com/android/tradefed/targetprep/DeviceFlashPreparer.java +++ b/src/com/android/tradefed/targetprep/DeviceFlashPreparer.java @@ -30,6 +30,8 @@ import com.android.tradefed.targetprep.IDeviceFlasher.UserDataFlashOption; import com.android.tradefed.util.IRunUtil; import com.android.tradefed.util.RunUtil; +import com.google.common.annotations.VisibleForTesting; + import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.Semaphore; @@ -62,6 +64,12 @@ public abstract class DeviceFlashPreparer implements ITargetCleaner { "specify if system should always be flashed even if already running desired build.") private boolean mForceSystemFlash = false; + @Option( + name = "skip-pre-flash-product-check", + description = "Specify if device product type should be checked before flashing" + ) + private boolean mSkipPreFlashProductType = false; + /* * A temporary workaround for special builds. Should be removed after changes from build team. * Bug: 18078421 @@ -247,6 +255,7 @@ public abstract class DeviceFlashPreparer implements ITargetCleaner { getRunUtil().allowInterrupt(false); try { IDeviceBuildInfo deviceBuild = (IDeviceBuildInfo)buildInfo; + checkDeviceProductType(device, deviceBuild); device.setRecoveryMode(RecoveryMode.ONLINE); IDeviceFlasher flasher = createFlasher(device); flasher.setWipeTimeout(mWipeTimeout); @@ -302,6 +311,31 @@ public abstract class DeviceFlashPreparer implements ITargetCleaner { } } + /** Check the device allocated against the build to ensure this is compatible to be flashed. */ + @VisibleForTesting + void checkDeviceProductType(ITestDevice device, IDeviceBuildInfo deviceBuild) + throws BuildError, DeviceNotAvailableException { + if (mSkipPreFlashProductType) { + CLog.d("Skipping pre flash device product check."); + return; + } + String buildFlavor = deviceBuild.getBuildFlavor(); + String deviceTypeFromBuild = buildFlavor; + // handle a case where build flavor format is not really quite as expected. + // <'device board'>-<user|userdebug> + if (buildFlavor.indexOf("-") != -1) { + deviceTypeFromBuild = buildFlavor.substring(0, buildFlavor.indexOf("-")); + } + String deviceProduct = device.getProductType(); // ro.hardware of the device + if (!deviceTypeFromBuild.equals(deviceProduct)) { + throw new BuildError( + String.format( + "Device allocated is a '%s' while build is meant for a '%s'", + deviceProduct, deviceTypeFromBuild), + device.getDeviceDescriptor()); + } + } + /** * Verifies the expected build matches the actual build on device after flashing * @throws DeviceNotAvailableException |