1 /*
2  * Copyright (C) 2019 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 package com.android.tradefed.device.cloud;
17 
18 import java.util.ArrayList;
19 import java.util.List;
20 
21 /** Utility helper to control Launch_cvd in the Cuttlefish VM. */
22 public class LaunchCvdHelper {
23 
24     /**
25      * Create the command line to start an additional device for a user.
26      *
27      * @param username The user that will run the device.
28      * @param daemon Whether or not to start the device as a daemon.
29      * @return The created command line;
30      */
createSimpleDeviceCommand(String username, boolean daemon)31     public static List<String> createSimpleDeviceCommand(String username, boolean daemon) {
32         return createSimpleDeviceCommand(username, daemon, true, true);
33     }
34 
35     /**
36      * Create the command line to start an additional device for a user.
37      *
38      * @param username The user that will run the device.
39      * @param daemon Whether or not to start the device as a daemon.
40      * @param alwaysCreateUserData Whether or not to create the userdata partition
41      * @param blankDataImage whether or not to create the data image.
42      * @return The created command line;
43      */
createSimpleDeviceCommand( String username, boolean daemon, boolean alwaysCreateUserData, boolean blankDataImage)44     public static List<String> createSimpleDeviceCommand(
45             String username, boolean daemon, boolean alwaysCreateUserData, boolean blankDataImage) {
46         List<String> command = new ArrayList<>();
47         command.add("sudo -u " + username);
48         command.add("/home/" + username + "/bin/launch_cvd");
49         command.add("-data_policy");
50         if (alwaysCreateUserData) {
51             command.add("always_create");
52         } else {
53             command.add("create_if_missing");
54         }
55         if (blankDataImage) {
56             command.add("-blank_data_image_mb");
57         }
58         command.add("8000");
59         if (daemon) {
60             command.add("-daemon");
61         }
62         return command;
63     }
64 }
65