1 /* 2 * Copyright (C) 2018 Google Inc. 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 package com.android.tradefed.targetprep; 17 18 import com.android.tradefed.build.IBuildInfo; 19 import com.android.tradefed.config.Option; 20 import com.android.tradefed.config.OptionClass; 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.device.ITestDevice; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * Target preparer that triggers fastboot and sends fastboot commands. 29 * 30 * <p>TODO(b/122592575): Add tests for this preparer. 31 */ 32 @OptionClass(alias = "fastboot-command-preparer") 33 public class FastbootCommandPreparer extends BaseTargetPreparer { 34 @Option(name = "command", description = "Fastboot commands to run.") 35 private List<String> mFastbootCommands = new ArrayList<String>(); 36 37 @Override setUp(ITestDevice device, IBuildInfo buildInfo)38 public void setUp(ITestDevice device, IBuildInfo buildInfo) 39 throws TargetSetupError, BuildError, DeviceNotAvailableException { 40 device.rebootIntoBootloader(); 41 42 for (String cmd : mFastbootCommands) { 43 // Ignore reboots since we'll reboot in the end. 44 if (cmd.trim().equals("reboot")) { 45 continue; 46 } 47 48 device.executeFastbootCommand(cmd.split("\\s+")); 49 } 50 51 device.reboot(); 52 } 53 } 54