• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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;
17 
18 import com.android.ddmlib.Log.LogLevel;
19 import com.android.tradefed.config.Option;
20 import com.android.tradefed.error.HarnessRuntimeException;
21 import com.android.tradefed.result.error.InfraErrorIdentifier;
22 import com.android.tradefed.util.ArrayUtil;
23 import com.android.tradefed.util.FileUtil;
24 import com.android.tradefed.util.MultiMap;
25 
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.HashSet;
30 import java.util.LinkedHashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34 
35 /**
36  * Container for {@link ITestDevice} {@link Option}s
37  */
38 public class TestDeviceOptions {
39 
40     public enum InstanceType {
41         /** A device that we remotely access via ssh and adb connect */
42         GCE,
43         REMOTE_AVD,
44         /**
45          * A remote device inside an emulator that we access via ssh to the instance hosting the
46          * emulator then adb connect.
47          */
48         CUTTLEFISH,
49         REMOTE_NESTED_AVD,
50         /** An android emulator. */
51         EMULATOR,
52         /** Chrome OS VM (betty) */
53         CHEEPS,
54     }
55 
56     /** The size of the host which Oxygen virtual device will be running on. */
57     private enum DeviceSize {
58         STANDARD,
59         LARGE,
60         EXTRA_LARGE,
61     }
62 
63     public static final int DEFAULT_ADB_PORT = 5555;
64     public static final String INSTANCE_TYPE_OPTION = "instance-type";
65 
66     /** Do not provide a setter method for that Option as it might be misused. */
67     @Option(name = "enable-root", description = "enable adb root on boot.")
68     private boolean mEnableAdbRoot = true;
69 
70     @Option(name = "disable-keyguard",
71             description = "attempt to disable keyguard once boot is complete.")
72     private boolean mDisableKeyguard = true;
73 
74     @Option(name = "enable-logcat", description =
75             "Enable background logcat capture when invocation is running.")
76     private boolean mEnableLogcat = true;
77 
78     @Option(name = "max-tmp-logcat-file", description =
79         "The maximum size of tmp logcat data to retain, in bytes. " +
80         "Only used if --enable-logcat is set")
81     private long mMaxLogcatDataSize = 20 * 1024 * 1024;
82 
83     @Option(name = "logcat-options", description =
84             "Options to be passed down to logcat command, if unspecified, \"-v threadtime\" will " +
85             "be used. Only used if --enable-logcat is set")
86     private String mLogcatOptions = null;
87 
88     @Option(name = "fastboot-timeout", description =
89             "time in ms to wait for a device to boot into fastboot.")
90     private int mFastbootTimeout = 1 * 60 * 1000;
91 
92     @Option(
93             name = "fastboot-output-timeout",
94             isTimeVal = true,
95             description =
96                     "Maximum time to wait for a fastboot command to output something. If non"
97                             + " zero, timeout will be enforced.")
98     private long mFastbootOutputTimeout = 5 * 60 * 1000;
99 
100     @Option(name = "adb-command-timeout", description =
101             "time to wait for an adb command.", isTimeVal = true)
102     private long mAdbCommandTimeout = 2 * 60 * 1000;
103 
104     @Option(name = "adb-recovery-timeout", description =
105             "time in ms to wait for a device to boot into recovery.")
106     private int mAdbRecoveryTimeout = 1 * 60 * 1000;
107 
108     @Option(name = "reboot-timeout", description =
109             "time in ms to wait for a device to reboot to full system.")
110     private int mRebootTimeout = 2 * 60 * 1000;
111 
112     @Option(
113             name = "device-fastboot-binary",
114             description =
115                     "The fastboot binary to use for the test session. If null, will use "
116                             + "the same fastboot binary as DeviceManager.")
117     private File mFastbootBinary = null;
118 
119     @Option(name = "use-fastboot-erase", description =
120             "use fastboot erase instead of fastboot format to wipe partitions")
121     private boolean mUseFastbootErase = false;
122 
123     @Option(name = "unencrypt-reboot-timeout", description = "time in ms to wait for the device to "
124             + "format the filesystem and reboot after unencryption")
125     private int mUnencryptRebootTimeout = 0;
126 
127     @Option(name = "online-timeout", description = "default time in ms to wait for the device to "
128             + "be visible on adb.", isTimeVal = true)
129     private long mOnlineTimeout = 1 * 60 * 1000;
130 
131     @Option(name = "available-timeout", description = "default time in ms to wait for the device "
132             + "to be available aka fully boot.")
133     private long mAvailableTimeout = 6 * 60 * 1000;
134 
135     @Option(
136             name = "adb-root-unavailable-timeout",
137             description = "time in ms to wait for a device to become unavailable after adb root.",
138             isTimeVal = true)
139     private long mAdbRootUnavailableTimeout = 2 * 1000;
140 
141     @Option(
142             name = "snapuserd-timeout",
143             description = "time to wait for a device to finish committing patches with snapuserd",
144             isTimeVal = true)
145     private long mSnapuserdTimeout = 10 * 60 * 1000;
146 
147     @Option(name = "conn-check-url",
148             description = "default URL to be used for connectivity checks.")
149     private String mConnCheckUrl = "http://www.google.com";
150 
151     @Option(
152             name = "wifi-attempts",
153             description = "default number of attempts to connect to wifi network.")
154     private int mWifiAttempts = 4;
155 
156     @Option(
157             name = "wifi-retry-wait-time",
158             description =
159                     "the base wait time in ms between wifi connect retries. "
160                             + "The actual wait time would be a multiple of this value.")
161     private int mWifiRetryWaitTime = 15 * 1000;
162 
163     @Option(
164             name = "max-wifi-connect-time",
165             isTimeVal = true,
166             description = "the maximum amount of time to attempt to connect to wifi.")
167     private long mMaxWifiConnectTime = 5 * 60 * 1000;
168 
169     @Option(
170             name = "wifi-exponential-retry",
171             description =
172                     "Change the wifi connection retry strategy from a linear wait time into"
173                             + " a binary exponential back-offs when retrying.")
174     private boolean mWifiExpoRetryEnabled = false;
175 
176     @Option(name = "wifiutil-apk-path", description = "path to the wifiutil APK file")
177     private String mWifiUtilAPKPath = null;
178 
179     @Option(
180             name = "default-network-type",
181             description =
182                     "default network type to fallback to, if wifi helper fails to find the correct"
183                             + " network type for the specified network.")
184     private String mDefaultNetworkType = "wpa2";
185 
186     @Option(name = "post-boot-command",
187             description = "shell command to run after reboots during invocation")
188     private List<String> mPostBootCommands = new ArrayList<String>();
189 
190     @Option(name = "disable-reboot",
191             description = "disables device reboots globally, making them no-ops")
192     private boolean mDisableReboot = false;
193 
194     @Option(name = "cutoff-battery", description =
195             "the minimum battery level required to continue the invocation. Scale: 0-100")
196     private Integer mCutoffBattery = null;
197 
198     @Option(
199         name = "use-content-provider",
200         description =
201                 "Allow to disable the use of the content provider at the device level. "
202                         + "This results in falling back to standard adb push/pull."
203     )
204     private boolean mUseContentProvider = true;
205 
206     @Option(
207             name = "exit-status-workaround",
208             description =
209                     "On older devices that do not support ADB shell v2, use a workaround "
210                             + "to get the exit status of shell commands")
211     private boolean mExitStatusWorkaround = false;
212 
213     @Option(
214             name = "use-updated-bootloader-status",
215             description =
216                     "Feature flag to test out an updated approach to bootloader state status.")
217     private boolean mUpdatedBootloaderStatus = true;
218 
219     @Option(
220             name = "bugreportz-timeout",
221             description = "Timeout applied to bugreportz capture.",
222             isTimeVal = true)
223     private long mBugreportzTimeout = 5 * 60 * 1000;
224 
225     @Option(
226             name = "enable-device-connection",
227             description = "Use the new Connection descriptor for devices.")
228     private boolean mEnableConnectionFeature = true;
229 
230     @Option(
231             name = "adb-connect-wait-time",
232             description = "maximum time in ms to wait for a ADB connection.",
233             isTimeVal = true)
234     protected long mAdbConnectWaitTime = 2 * 60 * 1000;
235     // ====================== Options Related to Virtual Devices ======================
236     @Option(
237             name = INSTANCE_TYPE_OPTION,
238             description = "The type of virtual device instance to create")
239     private InstanceType mInstanceType = InstanceType.GCE;
240 
241     @Option(
242             name = "gce-boot-timeout",
243             description = "timeout to wait in ms for GCE to be online.",
244             isTimeVal = true)
245     private long mGceCmdTimeout = 30 * 60 * 1000; // 30 minutes.
246 
247     @Option(
248             name = "allow-gce-boot-timeout-override",
249             description =
250                     "Acloud can take boot-timeout as an arg already, this flag allows to use "
251                             + "the Acloud value as a basis instead of the gce-boot-timeout option.")
252     private boolean mAllowGceCmdTimeoutOverride = false;
253 
254     @Option(name = "gce-driver-path", description = "path of the binary to launch GCE devices")
255     private File mAvdDriverBinary = null;
256 
257     @Option(
258             name = "gce-driver-config-path",
259             description = "path of the config to use to launch GCE devices.")
260     private File mAvdConfigFile = null;
261 
262     @Option(
263             name = "gce-driver-service-account-json-key-path",
264             description = "path to the service account json key location.")
265     private File mJsonKeyFile = null;
266 
267     @Option(
268             name = "gce-private-key-path",
269             description = "path to the ssh key private key location.")
270     private File mSshPrivateKeyPath = new File("~/.ssh/id_rsa");
271 
272     @Option(name = "gce-driver-log-level", description = "Log level for gce driver")
273     private LogLevel mGceDriverLogLevel = LogLevel.DEBUG;
274 
275     @Option(
276         name = "gce-driver-param",
277         description = "Additional args to pass to gce driver as parameters."
278     )
279     private List<String> mGceDriverParams = new ArrayList<>();
280 
281     @Option(
282             name = "gce-driver-file-param",
283             description =
284                     "Additional file paths to pass to gce driver as parameters. For example, "
285                             + "local-image=/path/to/image is converted to "
286                             + "--local-image /path/to/image.")
287     private MultiMap<String, File> mGceDriverFileParams = new MultiMap<>();
288 
289     @Deprecated
290     @Option(
291         name = "gce-driver-build-id-param",
292         description =
293                 "The parameter to be paired with "
294                         + "build id from build info when passed down to gce driver"
295     )
296     private String mGceDriverBuildIdParam = "build_id";
297 
298     @Option(name = "gce-account", description = "email account to use with GCE driver.")
299     private String mGceAccount = null;
300 
301     @Option(
302         name = "max-gce-attempt",
303         description = "Maximum number of attempts to start Gce before throwing an exception."
304     )
305     private int mGceMaxAttempt = 1;
306 
307     @Option(
308             name = "skip-gce-teardown",
309             description =
310                     "Whether or not to skip the GCE tear down. Skipping tear down will "
311                             + "result in the instance being left.")
312     private boolean mSkipTearDown = false;
313 
314     @Option(
315             name = "use-oxygen",
316             description = "Whether or not to use virtual devices created by Oxygen.")
317     private boolean mUseOxygen = false;
318 
319     @Deprecated
320     @Option(
321             name = "use-oxygen-client",
322             description = "Whether or not to use Oxygen client tool to create virtual devices.")
323     private boolean mUseOxygenClient = true;
324 
325     @Option(name = "oxygen-target-region", description = "Oxygen device target region.")
326     private String mOxygenTargetRegion = null;
327 
328     @Option(
329             name = "oxygen-lease-length",
330             description = "Oxygen device lease length.",
331             isTimeVal = true)
332     private long mOxygenLeaseLength = 600 * 60 * 1000;
333 
334     @Option(
335             name = "oxygen-device-size",
336             description = "The size of the host which Oxygen virtual device will be running on.")
337     private DeviceSize mOxygenDeviceSize = DeviceSize.STANDARD;
338 
339     @Option(name = "oxygen-service-address", description = "Oxygen service address.")
340     private String mOxygenServiceAddress = null;
341 
342     @Option(name = "oxygen-accounting-user", description = "Oxygen account user.")
343     private String mOxygenAccountingUser = null;
344 
345     @Option(
346             name = "extra-oxygen-args",
347             description = "Extra arguments passed to Oxygen client to lease a device.")
348     private Map<String, String> mExtraOxygenArgs = new LinkedHashMap<>();
349 
350     @Option(
351             name = "wait-gce-teardown",
352             description = "Whether or not to block on gce teardown before proceeding.")
353     private boolean mWaitForGceTearDown = false;
354 
355     @Option(
356             name = "instance-user",
357             description =
358                     "The account to be used to interact with the "
359                             + "outer layer of the GCE VM, e.g. to SSH in")
360     private String mInstanceUser = "root";
361 
362     @Option(
363             name = "remote-adb-port",
364             description = "The port on remote instance where the adb " + "server listens to.")
365     private int mRemoteAdbPort = DEFAULT_ADB_PORT;
366 
367     @Option(
368             name = "base-host-image",
369             description = "The base image to be used for the GCE VM to host emulator.")
370     private String mBaseImage = null;
371 
372     @Option(
373         name = "remote-fetch-file-pattern",
374         description =
375                 "Only for remote VM devices. Allows to specify patterns to fetch file on the "
376                         + "remote VM via scp. Pattern must follow the scp notations."
377     )
378     private Set<String> mRemoteFetchFilePattern = new HashSet<>();
379 
380     @Option(name = "cros-user", description = "(CHEEPS ONLY) Account to log in to Chrome OS with.")
381     private String mCrosUser = null;
382 
383     @Option(
384         name = "cros-password",
385         description =
386                 "(CHEEPS ONLY) Password to log in to Chrome OS with. Only used if cros-user "
387                         + "is specified."
388     )
389     private String mCrosPassword = null;
390 
391     @Option(
392             name = "invocation-attribute-to-metadata",
393             description =
394                     "Pass the named attribute found in invocation context to GCE driver (acloud)"
395                             + " as metadata to be associated with the GCE VM. e.g. if invocation"
396                             + " context has form_factor=phone, it'll be added to GCE VM as metadata"
397                             + " form_factor=phone.")
398     private List<String> mInvocationAttributeToMetadata = new ArrayList<>();
399 
400     @Option(
401             name = "gce-extra-files",
402             description =
403                     "Path of extra files need to upload GCE instance during Acloud create."
404                             + "Key is local file, value is GCE destination path.")
405     private MultiMap<File, String> mGceExtraFiles = new MultiMap<>();
406 
407     @Option(
408             name = "use-cmd-wifi",
409             description = "Feature flag to switch the wifi connection to using cmd commands.")
410     private boolean mUseCmdWifi = true;
411 
412     @Option(name = "cmd-wifi-virtual", description = "Whether to use cmd wifi for virtual devices.")
413     private boolean mCmdWifiVirtual = true;
414 
415     @Option(
416             name = "use-oxygenation-device",
417             description =
418                     "Whether or not to use virtual devices created by Oxygenation. This is under"
419                             + " development, and should be set on demand for running platform"
420                             + " tests against an oxygenation device.")
421     private boolean mUseOxygenationDevice = false;
422 
423     @Option(name = "force-evaluate-connection")
424     private boolean mForceEvaluateDeviceConnection = false;
425 
426     // END ====================== Options Related to Virtual Devices ======================
427 
428     // Option related to Remote Device only
429 
430     public static final String REMOTE_TF_VERSION_OPTION = "remote-tf-version";
431 
432     @Option(
433         name = REMOTE_TF_VERSION_OPTION,
434         description =
435                 "The TF to push to the remote VM to drive the invocation. If null, current TF "
436                         + "will be pushed."
437     )
438     private File mRemoteTFVersion = null;
439 
440     /** Check whether adb root should be enabled on boot for this device */
isEnableAdbRoot()441     public boolean isEnableAdbRoot() {
442         return mEnableAdbRoot;
443     }
444 
445     /**
446      * Check whether or not we should attempt to disable the keyguard once boot has completed
447      */
isDisableKeyguard()448     public boolean isDisableKeyguard() {
449         return mDisableKeyguard;
450     }
451 
452     /**
453      * Set whether or not we should attempt to disable the keyguard once boot has completed
454      */
setDisableKeyguard(boolean disableKeyguard)455     public void setDisableKeyguard(boolean disableKeyguard) {
456         mDisableKeyguard = disableKeyguard;
457     }
458 
459     /**
460      * Get the approximate maximum size of a tmp logcat data to retain, in bytes.
461      */
getMaxLogcatDataSize()462     public long getMaxLogcatDataSize() {
463         return mMaxLogcatDataSize;
464     }
465 
466     /**
467      * Set the approximate maximum size of a tmp logcat to retain, in bytes
468      */
setMaxLogcatDataSize(long maxLogcatDataSize)469     public void setMaxLogcatDataSize(long maxLogcatDataSize) {
470         mMaxLogcatDataSize = maxLogcatDataSize;
471     }
472 
473     /**
474      * @return the timeout to send a command in msecs.
475      */
getAdbCommandTimeout()476     public long getAdbCommandTimeout() {
477         return mAdbCommandTimeout;
478     }
479 
480     /** Sets the timeout to send a command in msecs. */
setAdbCommandTimeout(long adbCommandTimeout)481     public void setAdbCommandTimeout(long adbCommandTimeout) {
482         mAdbCommandTimeout = adbCommandTimeout;
483     }
484 
485     /**
486      * @return the timeout to boot into fastboot mode in msecs.
487      */
getFastbootTimeout()488     public int getFastbootTimeout() {
489         return mFastbootTimeout;
490     }
491 
getFastbootOutputTimeout()492     public long getFastbootOutputTimeout() {
493         return mFastbootOutputTimeout;
494     }
495 
496     /**
497      * @param fastbootTimeout the timout in msecs to boot into fastboot mode.
498      */
setFastbootTimeout(int fastbootTimeout)499     public void setFastbootTimeout(int fastbootTimeout) {
500         mFastbootTimeout = fastbootTimeout;
501     }
502 
503     /**
504      * @return the timeout in msecs to boot into recovery mode.
505      */
getAdbRecoveryTimeout()506     public int getAdbRecoveryTimeout() {
507         return mAdbRecoveryTimeout;
508     }
509 
510     /**
511      * @param adbRecoveryTimeout the timeout in msecs to boot into recovery mode.
512      */
setAdbRecoveryTimeout(int adbRecoveryTimeout)513     public void setAdbRecoveryTimeout(int adbRecoveryTimeout) {
514         mAdbRecoveryTimeout = adbRecoveryTimeout;
515     }
516 
517     /**
518      * @return the timeout in msecs for the full system boot.
519      */
getRebootTimeout()520     public int getRebootTimeout() {
521         return mRebootTimeout;
522     }
523 
524     /**
525      * @param rebootTimeout the timeout in msecs for the system to fully boot.
526      */
setRebootTimeout(int rebootTimeout)527     public void setRebootTimeout(int rebootTimeout) {
528         mRebootTimeout = rebootTimeout;
529     }
530 
531     /**
532      * @return whether to use fastboot erase instead of fastboot format to wipe partitions.
533      */
getUseFastbootErase()534     public boolean getUseFastbootErase() {
535         return mUseFastbootErase;
536     }
537 
538     /**
539      * @param useFastbootErase whether to use fastboot erase instead of fastboot format to wipe
540      * partitions.
541      */
setUseFastbootErase(boolean useFastbootErase)542     public void setUseFastbootErase(boolean useFastbootErase) {
543         mUseFastbootErase = useFastbootErase;
544     }
545 
546     /** Returns a specified fastboot binary to be used. if null, use the DeviceManager one. */
getFastbootBinary()547     public File getFastbootBinary() {
548         return mFastbootBinary;
549     }
550 
551     /**
552      * @return the timeout in msecs for the filesystem to be formatted and the device to reboot
553      * after unencryption.
554      */
getUnencryptRebootTimeout()555     public int getUnencryptRebootTimeout() {
556         return mUnencryptRebootTimeout;
557     }
558 
559     /**
560      * @param unencryptRebootTimeout the timeout in msecs for the filesystem to be formatted and
561      * the device to reboot after unencryption.
562      */
setUnencryptRebootTimeout(int unencryptRebootTimeout)563     public void setUnencryptRebootTimeout(int unencryptRebootTimeout) {
564         mUnencryptRebootTimeout = unencryptRebootTimeout;
565     }
566 
567     /**
568      * @return the default time in ms to to wait for a device to be online.
569      */
getOnlineTimeout()570     public long getOnlineTimeout() {
571         return mOnlineTimeout;
572     }
573 
setOnlineTimeout(long onlineTimeout)574     public void setOnlineTimeout(long onlineTimeout) {
575         mOnlineTimeout = onlineTimeout;
576     }
577 
578     /**
579      * @return the default time in ms to to wait for a device to be available.
580      */
getAvailableTimeout()581     public long getAvailableTimeout() {
582         return mAvailableTimeout;
583     }
584 
585     /**
586      * @return the time in ms to wait for a device to become unavailable after adb root.
587      */
getAdbRootUnavailableTimeout()588     public long getAdbRootUnavailableTimeout() {
589         return mAdbRootUnavailableTimeout;
590     }
591 
592     /**
593      * @param adbRootUnavailableTimeout time in ms to wait for a device to become unavailable after
594      *     adb root.
595      */
setAdbRootUnavailableTimeout(long adbRootUnavailableTimeout)596     public void setAdbRootUnavailableTimeout(long adbRootUnavailableTimeout) {
597         mAdbRootUnavailableTimeout = adbRootUnavailableTimeout;
598     }
599 
600     /**
601      * @return the default URL to be used for connectivity tests.
602      */
getConnCheckUrl()603     public String getConnCheckUrl() {
604         return mConnCheckUrl;
605     }
606 
setConnCheckUrl(String url)607     public void setConnCheckUrl(String url) {
608       mConnCheckUrl = url;
609     }
610 
611     /**
612      * @return true if background logcat capture is enabled
613      */
isLogcatCaptureEnabled()614     public boolean isLogcatCaptureEnabled() {
615         return mEnableLogcat;
616     }
617 
618     /**
619      * @return the default number of attempts to connect to wifi network.
620      */
getWifiAttempts()621     public int getWifiAttempts() {
622         return mWifiAttempts;
623     }
624 
setWifiAttempts(int wifiAttempts)625     public void setWifiAttempts(int wifiAttempts) {
626         mWifiAttempts = wifiAttempts;
627     }
628 
629     /**
630      * @return the base wait time between wifi connect retries.
631      */
getWifiRetryWaitTime()632     public int getWifiRetryWaitTime() {
633         return mWifiRetryWaitTime;
634     }
635 
636     /** @return the maximum time to attempt to connect to wifi. */
getMaxWifiConnectTime()637     public long getMaxWifiConnectTime() {
638         return mMaxWifiConnectTime;
639     }
640 
641     /**
642      * @return a list of shell commands to run after reboots.
643      */
getPostBootCommands()644     public List<String> getPostBootCommands() {
645         return mPostBootCommands;
646     }
647 
648     /**
649      * @return the minimum battery level to continue the invocation.
650      */
getCutoffBattery()651     public Integer getCutoffBattery() {
652         return mCutoffBattery;
653     }
654 
655     /**
656      * set the minimum battery level to continue the invocation.
657      */
setCutoffBattery(int cutoffBattery)658     public void setCutoffBattery(int cutoffBattery) {
659         if (cutoffBattery < 0 || cutoffBattery > 100) {
660             // Prevent impossible value.
661             throw new RuntimeException(String.format("Battery cutoff wasn't changed,"
662                     + "the value %s isn't within possible range (0-100).", cutoffBattery));
663         }
664         mCutoffBattery = cutoffBattery;
665     }
666 
667     /**
668      * @return the configured logcat options
669      */
getLogcatOptions()670     public String getLogcatOptions() {
671         return mLogcatOptions;
672     }
673 
674     /**
675      * Set the options to be passed down to logcat
676      */
setLogcatOptions(String logcatOptions)677     public void setLogcatOptions(String logcatOptions) {
678         mLogcatOptions = logcatOptions;
679     }
680 
681     /**
682      * @return if device reboot should be disabled
683      */
shouldDisableReboot()684     public boolean shouldDisableReboot() {
685         return mDisableReboot;
686     }
687 
688     /**
689      * @return if the exponential retry strategy should be used.
690      */
isWifiExpoRetryEnabled()691     public boolean isWifiExpoRetryEnabled() {
692         return mWifiExpoRetryEnabled;
693     }
694 
695     /** @return the wifiutil apk path */
getWifiUtilAPKPath()696     public String getWifiUtilAPKPath() {
697         return mWifiUtilAPKPath;
698     }
699 
700     /** Returns the instance type of virtual device that should be created */
getInstanceType()701     public InstanceType getInstanceType() {
702         return mInstanceType;
703     }
704 
705     /** Sets the instance type of virtual device that should be created */
setInstanceType(InstanceType type)706     public void setInstanceType(InstanceType type) {
707         mInstanceType = type;
708     }
709 
710     /** Returns whether or not the Tradefed content provider can be used to push/pull files. */
shouldUseContentProvider()711     public boolean shouldUseContentProvider() {
712         return mUseContentProvider;
713     }
714 
715     /**
716      * Returns whether to use a workaround to get shell exit status on older devices without shell
717      * v2.
718      */
useExitStatusWorkaround()719     public boolean useExitStatusWorkaround() {
720         return mExitStatusWorkaround;
721     }
722 
723     // =========================== Getter and Setter for Virtual Devices
724     /** Return the Gce Avd timeout for the instance to come online. */
getGceCmdTimeout()725     public long getGceCmdTimeout() {
726         return mGceCmdTimeout;
727     }
728 
729     /** Set the Gce Avd timeout for the instance to come online. */
setGceCmdTimeout(long gceCmdTimeout)730     public void setGceCmdTimeout(long gceCmdTimeout) {
731         mGceCmdTimeout = gceCmdTimeout;
732     }
733 
734     /** Returns whether or not we should rely on the boot-timeout args from acloud if present. */
allowGceCmdTimeoutOverride()735     public boolean allowGceCmdTimeoutOverride() {
736         return mAllowGceCmdTimeoutOverride;
737     }
738 
739     /** Return the path to the binary to start the Gce Avd instance. */
getAvdDriverBinary()740     public File getAvdDriverBinary() {
741         if (mAvdDriverBinary == null) {
742             throw new HarnessRuntimeException(
743                     "The avd driver binary is not specified.",
744                     InfraErrorIdentifier.OPTION_CONFIGURATION_ERROR);
745         }
746         if (!mAvdDriverBinary.exists()) {
747             throw new HarnessRuntimeException(
748                     String.format(
749                             "Could not find the avd driver binary at %s",
750                             mAvdDriverBinary.getAbsolutePath()),
751                     InfraErrorIdentifier.CONFIGURED_ARTIFACT_NOT_FOUND);
752         }
753         if (!FileUtil.ensureGroupRWX(mAvdDriverBinary)) {
754             throw new HarnessRuntimeException(
755                     String.format(
756                             "Failed to change avd driver binary to be executable at %s",
757                             mAvdDriverBinary.getAbsolutePath()),
758                     InfraErrorIdentifier.CONFIGURED_ARTIFACT_NOT_FOUND);
759         }
760         return mAvdDriverBinary;
761     }
762 
763     /** Set the path to the binary to start the Gce Avd instance. */
setAvdDriverBinary(File avdDriverBinary)764     public void setAvdDriverBinary(File avdDriverBinary) {
765         mAvdDriverBinary = avdDriverBinary;
766     }
767 
768     /** Return the Gce Avd config file to start the instance. */
getAvdConfigFile()769     public File getAvdConfigFile() {
770         return mAvdConfigFile;
771     }
772 
773     /** Set the Gce Avd config file to start the instance. */
setAvdConfigFile(File avdConfigFile)774     public void setAvdConfigFile(File avdConfigFile) {
775         mAvdConfigFile = avdConfigFile;
776     }
777 
778     /** @return the service account json key file. */
getServiceAccountJsonKeyFile()779     public File getServiceAccountJsonKeyFile() {
780         return mJsonKeyFile;
781     }
782 
783     /**
784      * Set the service account json key file.
785      *
786      * @param jsonKeyFile the key file.
787      */
setServiceAccountJsonKeyFile(File jsonKeyFile)788     public void setServiceAccountJsonKeyFile(File jsonKeyFile) {
789         mJsonKeyFile = jsonKeyFile;
790     }
791 
792     /** Return the path of the ssh key to use for operations with the Gce Avd instance. */
getSshPrivateKeyPath()793     public File getSshPrivateKeyPath() {
794         return mSshPrivateKeyPath;
795     }
796 
797     /** Set the path of the ssh key to use for operations with the Gce Avd instance. */
setSshPrivateKeyPath(File sshPrivateKeyPath)798     public void setSshPrivateKeyPath(File sshPrivateKeyPath) {
799         mSshPrivateKeyPath = sshPrivateKeyPath;
800     }
801 
802     /** Return the log level of the Gce Avd driver. */
getGceDriverLogLevel()803     public LogLevel getGceDriverLogLevel() {
804         return mGceDriverLogLevel;
805     }
806 
807     /** Set the log level of the Gce Avd driver. */
setGceDriverLogLevel(LogLevel mGceDriverLogLevel)808     public void setGceDriverLogLevel(LogLevel mGceDriverLogLevel) {
809         this.mGceDriverLogLevel = mGceDriverLogLevel;
810     }
811 
812     /** Return the additional GCE driver parameters provided via option */
getGceDriverParams()813     public List<String> getGceDriverParams() {
814         return mGceDriverParams;
815     }
816 
817     /** Add a param to the gce driver params. */
addGceDriverParams(String param)818     public void addGceDriverParams(String param) {
819         mGceDriverParams.add(param);
820     }
821 
822     /** Return the additional file paths as GCE driver parameters provided via option. */
getGceDriverFileParams()823     public MultiMap<String, File> getGceDriverFileParams() {
824         return mGceDriverFileParams;
825     }
826 
827     /** Set the GCE driver parameter that should be paired with the build id from build info */
setGceDriverBuildIdParam(String gceDriverBuildIdParam)828     public void setGceDriverBuildIdParam(String gceDriverBuildIdParam) {
829         mGceDriverBuildIdParam = gceDriverBuildIdParam;
830     }
831 
832     /** Return the GCE driver parameter that should be paired with the build id from build info */
getGceDriverBuildIdParam()833     public String getGceDriverBuildIdParam() {
834         return mGceDriverBuildIdParam;
835     }
836 
837     /** Return the gce email account to use with the driver */
getGceAccount()838     public String getGceAccount() {
839         return mGceAccount;
840     }
841 
842     /** Return the max number of attempts to start a gce device */
getGceMaxAttempt()843     public int getGceMaxAttempt() {
844         if (mGceMaxAttempt < 1) {
845             throw new RuntimeException("--max-gce-attempt cannot be bellow 1 attempt.");
846         }
847         return mGceMaxAttempt;
848     }
849 
850     /** Set the max number of attempts to start a gce device */
setGceMaxAttempt(int gceMaxAttempt)851     public void setGceMaxAttempt(int gceMaxAttempt) {
852         mGceMaxAttempt = gceMaxAttempt;
853     }
854 
855     /** Returns true if GCE tear down should be skipped. False otherwise. */
setSkipTearDown(boolean shouldSkipTearDown)856     public void setSkipTearDown(boolean shouldSkipTearDown) {
857         mSkipTearDown = shouldSkipTearDown;
858     }
859 
860     /** Returns true if GCE tear down should be skipped. False otherwise. */
shouldSkipTearDown()861     public boolean shouldSkipTearDown() {
862         return mSkipTearDown;
863     }
864 
865     /** Returns true if we should block on GCE tear down completion before proceeding. */
waitForGceTearDown()866     public boolean waitForGceTearDown() {
867         return mWaitForGceTearDown;
868     }
869 
870     /** Returns true if use Oxygen to create virtual devices. False otherwise. */
useOxygen()871     public boolean useOxygen() {
872         return mUseOxygen;
873     }
874 
875     /** Returns the instance user of GCE virtual device that should be created */
getInstanceUser()876     public String getInstanceUser() {
877         return mInstanceUser;
878     }
879 
880     /** Set the instance user of GCE virtual device that should be created. */
setInstanceUser(String instanceUser)881     public void setInstanceUser(String instanceUser) {
882         mInstanceUser = instanceUser;
883     }
884 
885     /** Returns the remote port in instance that the adb server listens to */
getRemoteAdbPort()886     public int getRemoteAdbPort() {
887         return mRemoteAdbPort;
888     }
889 
890     /** Set the remote port in instance that the adb server listens to */
setRemoteAdbPort(int remoteAdbPort)891     public void setRemoteAdbPort(int remoteAdbPort) {
892         mRemoteAdbPort = remoteAdbPort;
893     }
894 
895     /** Returns the base image name to be used for the current instance */
getBaseImage()896     public String getBaseImage() {
897         return mBaseImage;
898     }
899 
900     /** Returns the list of pattern to attempt to fetch via scp. */
getRemoteFetchFilePattern()901     public Set<String> getRemoteFetchFilePattern() {
902         return mRemoteFetchFilePattern;
903     }
904 
905     /** Returns the Chrome OS User to log in as. */
getCrosUser()906     public String getCrosUser() {
907         return mCrosUser;
908     }
909 
910     /** Returns the password to log in to Chrome OS with. */
getCrosPassword()911     public String getCrosPassword() {
912         return mCrosPassword;
913     }
914 
915     /** The file pointing to the directory of the Tradefed version to be pushed to the remote. */
getRemoteTf()916     public File getRemoteTf() {
917         return mRemoteTFVersion;
918     }
919 
920     /** Return the extra files need to upload to GCE during acloud create. */
getExtraFiles()921     public MultiMap<File, String> getExtraFiles() {
922         return mGceExtraFiles;
923     }
924 
925     /** Set the extra files need to upload to GCE during acloud create. */
setExtraFiles(MultiMap<File, String> extraFiles)926     public void setExtraFiles(MultiMap<File, String> extraFiles) {
927         mGceExtraFiles = extraFiles;
928     }
929 
930     /** Returns whether or not to use cmd wifi commands instead of apk. */
useCmdWifiCommands()931     public boolean useCmdWifiCommands() {
932         return mUseCmdWifi;
933     }
934 
setUseCmdWifi(boolean useCmdWifi)935     public void setUseCmdWifi(boolean useCmdWifi) {
936         mUseCmdWifi = useCmdWifi;
937     }
938 
isCmdWifiVirtual()939     public boolean isCmdWifiVirtual() {
940         return mCmdWifiVirtual;
941     }
942 
getCreateCommandByInstanceType(InstanceType type)943     public static String getCreateCommandByInstanceType(InstanceType type) {
944         switch (type) {
945             case CHEEPS:
946             case GCE:
947             case REMOTE_AVD:
948             case CUTTLEFISH:
949             case REMOTE_NESTED_AVD:
950                 return "create";
951             case EMULATOR:
952                 return "create_gf";
953         }
954         throw new RuntimeException("Unexpected InstanceType: " + type);
955     }
956 
getExtraParamsByInstanceType(InstanceType type, String baseImage)957     public static List<String> getExtraParamsByInstanceType(InstanceType type, String baseImage) {
958         if (InstanceType.EMULATOR.equals(type)) {
959             // TODO(b/119440413) remove when base image can be passed via extra gce driver params
960             List<String> params = ArrayUtil.list();
961             if (baseImage != null) {
962                 params.add("--base_image");
963                 params.add(baseImage);
964             }
965             return params;
966         }
967         return Collections.emptyList();
968     }
969 
getInvocationAttributeToMetadata()970     public List<String> getInvocationAttributeToMetadata() {
971         return mInvocationAttributeToMetadata;
972     }
973 
974     /** Returns true if we want TradeFed directly call Oxygen to lease a device. */
975     @Deprecated
useOxygenProxy()976     public boolean useOxygenProxy() {
977         return mUseOxygenClient;
978     }
979 
980     /** Returns the target region of the Oxygen device. */
getOxygenTargetRegion()981     public String getOxygenTargetRegion() {
982         return mOxygenTargetRegion;
983     }
984 
985     /** Returns the length of leasing the Oxygen device in milliseconds. */
getOxygenLeaseLength()986     public long getOxygenLeaseLength() {
987         return mOxygenLeaseLength;
988     }
989 
990     /** Returns The size of the host which Oxygen virtual device will be running on. */
getOxygenDeviceSize()991     public DeviceSize getOxygenDeviceSize() {
992         return mOxygenDeviceSize;
993     }
994 
995     /** Returns the service address of the Oxygen device. */
getOxygenServiceAddress()996     public String getOxygenServiceAddress() {
997         return mOxygenServiceAddress;
998     }
999 
1000     /** Returns the accounting user of the Oxygen device. */
getOxygenAccountingUser()1001     public String getOxygenAccountingUser() {
1002         return mOxygenAccountingUser;
1003     }
1004 
1005     /** Returns the extra arguments to lease an Oxygen device. */
getExtraOxygenArgs()1006     public Map<String, String> getExtraOxygenArgs() {
1007         return mExtraOxygenArgs;
1008     }
1009 
1010     /** Returns whether or not to use the newer bootloader state status. */
useUpdatedBootloaderStatus()1011     public boolean useUpdatedBootloaderStatus() {
1012         return mUpdatedBootloaderStatus;
1013     }
1014 
1015     /** Returns the timeout value to be applied to bugreportz capture. */
getBugreportzTimeout()1016     public long getBugreportzTimeout() {
1017         return mBugreportzTimeout;
1018     }
1019 
1020     /** Return whether or not we should use the new connection feature. */
shouldUseConnection()1021     public boolean shouldUseConnection() {
1022         return mEnableConnectionFeature;
1023     }
1024 
1025     /** Return the timeout value in ms to be applied to ADB connection. */
getAdbConnectWaitTime()1026     public long getAdbConnectWaitTime() {
1027         return mAdbConnectWaitTime;
1028     }
1029 
setUseConnection(boolean useConnection)1030     public void setUseConnection(boolean useConnection) {
1031         mEnableConnectionFeature = useConnection;
1032     }
1033 
getDefaultNetworkType()1034     public String getDefaultNetworkType() {
1035         return mDefaultNetworkType;
1036     }
1037 
getSnapuserdTimeout()1038     public long getSnapuserdTimeout() {
1039         return mSnapuserdTimeout;
1040     }
1041 
1042     /** Returns true if it's to lease oxygenation devices in OmniLab's infra. False otherwise. */
useOxygenationDevice()1043     public boolean useOxygenationDevice() {
1044         return mUseOxygenationDevice;
1045     }
1046 
1047     /** Helper to return true if the device is launched by cvd, false otherwise. */
useCvdCF()1048     public boolean useCvdCF() {
1049         if (mUseOxygenationDevice || getExtraOxygenArgs().containsKey("use_cvd")) {
1050             return true;
1051         }
1052         return false;
1053     }
1054 
evaluateDeviceConnection()1055     public boolean evaluateDeviceConnection() {
1056         return mForceEvaluateDeviceConnection;
1057     }
1058 }
1059 
1060