1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tradefed.targetprep; 18 19 import com.android.tradefed.build.IDeviceBuildInfo; 20 import com.android.tradefed.device.DeviceNotAvailableException; 21 import com.android.tradefed.device.ITestDevice; 22 import com.android.tradefed.util.CommandStatus; 23 24 import java.util.Collection; 25 import java.util.Collections; 26 import java.util.Set; 27 28 /** 29 * Flashes a device image on a device. 30 */ 31 public interface IDeviceFlasher { 32 33 /** 34 * Enum of options for handling the userdata image 35 */ 36 public enum UserDataFlashOption { 37 /** flash the given userdata image on device */ 38 FLASH, 39 /** flash the userdata image included in device image zip */ 40 FLASH_IMG_ZIP, 41 /** wipe the device's userdata partition using fastboot erase, if supported by device */ 42 WIPE, 43 /** wipe the device's userdata partition using fastboot erase, even if it's unadvised */ 44 FORCE_WIPE, 45 /** delete content from the device's /data partition using adb shell rm */ 46 WIPE_RM, 47 /** push the contents of the tests zip file onto the device's userdata partition */ 48 TESTS_ZIP, 49 /** leave the userdata partition as is */ 50 RETAIN; 51 } 52 53 /** 54 * Override options for a device. Used to override default option values if the defaults are not 55 * supported by a particular device. 56 * 57 * @param device 58 */ overrideDeviceOptions(ITestDevice device)59 public void overrideDeviceOptions(ITestDevice device); 60 61 /** 62 * Sets the mechanism by which the flasher can retrieve resource files for flashing. 63 * 64 * @param retriever the {@link IFlashingResourcesRetriever} to use 65 */ setFlashingResourcesRetriever(IFlashingResourcesRetriever retriever)66 public void setFlashingResourcesRetriever(IFlashingResourcesRetriever retriever); 67 68 /** 69 * Toggles whether the user data image should be flashed, wiped, or retained 70 * 71 * @param flashOption 72 */ setUserDataFlashOption(UserDataFlashOption flashOption)73 public void setUserDataFlashOption(UserDataFlashOption flashOption); 74 75 /** 76 * Sets the list of paths under {@code /data} to avoid clearing when using 77 * {@link ITestsZipInstaller} 78 * <p /> 79 * Note that the granularity of the skip list is direct children of {@code /data}. 80 */ setDataWipeSkipList(Collection<String> dataWipeSkipList)81 public void setDataWipeSkipList(Collection<String> dataWipeSkipList); 82 83 /** 84 * Gets whether the user data image should be flashed, wiped, or retained 85 * 86 * @return Whether the user data image should be flashed, wiped, or retained 87 */ getUserDataFlashOption()88 public UserDataFlashOption getUserDataFlashOption(); 89 90 /** 91 * Set the timeout for wiping the data. 92 */ setWipeTimeout(long timeout)93 public void setWipeTimeout(long timeout); 94 95 /** 96 * Sets if system should always be flashed even if running current build 97 * @param forceSystemFlash 98 */ setForceSystemFlash(boolean forceSystemFlash)99 public void setForceSystemFlash(boolean forceSystemFlash); 100 101 /** 102 * All setup operations & checks that must occur before actual flashing critical section. None 103 * of those operations will be included in the concurrency-controlled critical section. 104 * 105 * @param device the {@link ITestDevice} to flash 106 * @param deviceBuild the {@link IDeviceBuildInfo} to flash 107 * @throws TargetSetupError if any setup fails 108 * @throws DeviceNotAvailableException if device becomes unresponsive 109 */ preFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild)110 public default void preFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild) 111 throws TargetSetupError, DeviceNotAvailableException { 112 // Empty by default 113 } 114 115 /** 116 * Flashes build on device. 117 * <p/> 118 * Returns immediately after flashing is complete. Callers should wait for device to be 119 * online and available before proceeding with testing. 120 * 121 * @param device the {@link ITestDevice} to flash 122 * @param deviceBuild the {@link IDeviceBuildInfo} to flash 123 * 124 * @throws TargetSetupError if failed to flash build 125 * @throws DeviceNotAvailableException if device becomes unresponsive 126 */ flash(ITestDevice device, IDeviceBuildInfo deviceBuild)127 public void flash(ITestDevice device, IDeviceBuildInfo deviceBuild) throws TargetSetupError, 128 DeviceNotAvailableException; 129 130 /** 131 * All clean up operations & checks that must occur after actual flashing critical section. None 132 * of those operations will be included in the concurrency-controlled critical section. 133 * 134 * @param device the {@link ITestDevice} to flash 135 * @param deviceBuild the {@link IDeviceBuildInfo} to flash 136 * @throws TargetSetupError if any setup fails 137 * @throws DeviceNotAvailableException if device becomes unresponsive 138 */ postFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild)139 public default void postFlashOperations(ITestDevice device, IDeviceBuildInfo deviceBuild) 140 throws TargetSetupError, DeviceNotAvailableException { 141 // Empty by default 142 } 143 144 /** 145 * Retrieve the command execution status for flashing primary system partitions. 146 * <p> 147 * Note that if system partitions are not flashed (system already has the build to be flashed) 148 * the command status may be <code>null</code> 149 */ getSystemFlashingStatus()150 public CommandStatus getSystemFlashingStatus(); 151 152 /** 153 * Sets if an additional ramdisk should be flashed after updating device via image zip 154 * 155 * @param shouldFlashRamdisk 156 */ setShouldFlashRamdisk(boolean shouldFlashRamdisk)157 public default void setShouldFlashRamdisk(boolean shouldFlashRamdisk) { 158 // Ignore 159 } 160 161 /** 162 * Sets ramdisk partition 163 * 164 * @param ramdiskPartition 165 */ setRamdiskPartition(String ramdiskPartition)166 public default void setRamdiskPartition(String ramdiskPartition) { 167 // Ignore 168 } 169 170 /** 171 * Checks if the flasher is set to have an additional ramdisk should be flashed after updating 172 * device via image zip 173 */ shouldFlashRamdisk()174 public default boolean shouldFlashRamdisk() { 175 return false; 176 } 177 178 /** 179 * Whether the device that implements the flasher can be flashed in fastbootd mode. 180 */ supportsFlashingInFastbootD()181 public default boolean supportsFlashingInFastbootD() { 182 return false; 183 } 184 185 /** 186 * Get filters for additional build artifacts. 187 * 188 * <p>Some flashers need certain build artifacts which are not among the default ones used. Such 189 * flashers should override this method, so every user of the flashing tools doesn't need to 190 * know about these files and provide command line options. 191 * 192 * <p>Note that this method is invoked on a temporary instance of the IDeviceFlasher, so no 193 * state beyond that provided in the default constructor should be relied upon. 194 * 195 * <p>Strings in the Set are interpreted as file patterns, and all files matching the pattern 196 * will be retrieved. 197 * 198 * <p>By default, this method returns an empty Set. 199 */ getAdditionalFileFilters()200 public default Set<String> getAdditionalFileFilters() { 201 return Collections.<String>emptySet(); 202 } 203 } 204