From 808cc9a8f0422b1a87a66b3f2f0d2ceef9155a2f Mon Sep 17 00:00:00 2001 From: Guang Zhu Date: Thu, 12 May 2016 14:21:11 -0700 Subject: change device wiping to `fastboot -w` directly In the past, device wiping equates to format/erase of userdata and cache. However, newer devices may not have cache partition, and `fastboot -w` has proper support for erasing and recreating the applicable partitions, so this change switches the approach for device wiping. Change-Id: I3e8c3353eaff034b18a0f56fb217be5d3a9ea485 --- .../android/tradefed/targetprep/DeviceCleaner.java | 3 +-- .../android/tradefed/targetprep/DeviceWiper.java | 7 +++++-- .../tradefed/targetprep/FastbootDeviceFlasher.java | 23 +++++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src/com/android/tradefed/targetprep') diff --git a/src/com/android/tradefed/targetprep/DeviceCleaner.java b/src/com/android/tradefed/targetprep/DeviceCleaner.java index e2d1c184d..60024f26a 100644 --- a/src/com/android/tradefed/targetprep/DeviceCleaner.java +++ b/src/com/android/tradefed/targetprep/DeviceCleaner.java @@ -104,8 +104,7 @@ public class DeviceCleaner implements ITargetCleaner { break; case FORMAT: device.rebootIntoBootloader(); - device.executeLongFastbootCommand("format", "cache"); - device.executeLongFastbootCommand("format", "userdata"); + device.executeLongFastbootCommand("-w"); device.executeFastbootCommand("reboot"); device.waitForDeviceAvailable(); break; diff --git a/src/com/android/tradefed/targetprep/DeviceWiper.java b/src/com/android/tradefed/targetprep/DeviceWiper.java index b3e1663c8..d916c364d 100644 --- a/src/com/android/tradefed/targetprep/DeviceWiper.java +++ b/src/com/android/tradefed/targetprep/DeviceWiper.java @@ -56,8 +56,11 @@ public class DeviceWiper implements ITargetPreparer { } private void doFormat(ITestDevice device) throws DeviceNotAvailableException, TargetSetupError { - performFastbootOp(device, "format", "cache"); - performFastbootOp(device, "format", "userdata"); + CLog.d("Attempting fastboot wiping"); + CommandResult r = device.executeLongFastbootCommand("-w"); + if (r.getStatus() != CommandStatus.SUCCESS) { + throw new TargetSetupError(String.format("fastboot wiping failed: %s", r.getStderr())); + } } private void doErase(ITestDevice device) throws DeviceNotAvailableException, TargetSetupError { diff --git a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java index 75c7e5ee1..88575d2e2 100644 --- a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java +++ b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java @@ -119,14 +119,31 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { device.rebootIntoBootloader(); downloadFlashingResources(device, deviceBuild); - + handleUserDataFlashing(device, deviceBuild); checkAndFlashBootloader(device, deviceBuild); checkAndFlashBaseband(device, deviceBuild); - flashUserData(device, deviceBuild); - wipeCache(device); checkAndFlashSystem(device, systemBuildId, systemBuildFlavor, deviceBuild); } + /** + * Handle flashing of userdata/cache partition + * @param device the {@link ITestDevice} to flash + * @param deviceBuild the {@link IDeviceBuildInfo} that contains the files to flash + * @throws DeviceNotAvailableException + * @throws TargetSetupError + */ + protected void handleUserDataFlashing(ITestDevice device, IDeviceBuildInfo deviceBuild) + throws DeviceNotAvailableException, TargetSetupError { + if (UserDataFlashOption.FORCE_WIPE.equals(mUserDataFlashOption) || + UserDataFlashOption.WIPE.equals(mUserDataFlashOption)) { + CommandResult result = device.executeFastbootCommand("-w"); + handleFastbootResult(device, result, "-w"); + } else { + flashUserData(device, deviceBuild); + wipeCache(device); + } + } + /** * Flash an individual partition of a device * -- cgit v1.2.3