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 // ====================== Options Related to Virtual Devices ====================== 231 @Option( 232 name = INSTANCE_TYPE_OPTION, 233 description = "The type of virtual device instance to create") 234 private InstanceType mInstanceType = InstanceType.GCE; 235 236 @Option( 237 name = "gce-boot-timeout", 238 description = "timeout to wait in ms for GCE to be online.", 239 isTimeVal = true) 240 private long mGceCmdTimeout = 30 * 60 * 1000; // 30 minutes. 241 242 @Option( 243 name = "allow-gce-boot-timeout-override", 244 description = 245 "Acloud can take boot-timeout as an arg already, this flag allows to use " 246 + "the Acloud value as a basis instead of the gce-boot-timeout option.") 247 private boolean mAllowGceCmdTimeoutOverride = false; 248 249 @Option(name = "gce-driver-path", description = "path of the binary to launch GCE devices") 250 private File mAvdDriverBinary = null; 251 252 @Option( 253 name = "gce-driver-config-path", 254 description = "path of the config to use to launch GCE devices.") 255 private File mAvdConfigFile = null; 256 257 @Option( 258 name = "gce-driver-service-account-json-key-path", 259 description = "path to the service account json key location.") 260 private File mJsonKeyFile = null; 261 262 @Option( 263 name = "gce-private-key-path", 264 description = "path to the ssh key private key location.") 265 private File mSshPrivateKeyPath = new File("~/.ssh/id_rsa"); 266 267 @Option(name = "gce-driver-log-level", description = "Log level for gce driver") 268 private LogLevel mGceDriverLogLevel = LogLevel.DEBUG; 269 270 @Option( 271 name = "gce-driver-param", 272 description = "Additional args to pass to gce driver as parameters." 273 ) 274 private List<String> mGceDriverParams = new ArrayList<>(); 275 276 @Option( 277 name = "gce-driver-file-param", 278 description = 279 "Additional file paths to pass to gce driver as parameters. For example, " 280 + "local-image=/path/to/image is converted to " 281 + "--local-image /path/to/image.") 282 private MultiMap<String, File> mGceDriverFileParams = new MultiMap<>(); 283 284 @Deprecated 285 @Option( 286 name = "gce-driver-build-id-param", 287 description = 288 "The parameter to be paired with " 289 + "build id from build info when passed down to gce driver" 290 ) 291 private String mGceDriverBuildIdParam = "build_id"; 292 293 @Option(name = "gce-account", description = "email account to use with GCE driver.") 294 private String mGceAccount = null; 295 296 @Option( 297 name = "max-gce-attempt", 298 description = "Maximum number of attempts to start Gce before throwing an exception." 299 ) 300 private int mGceMaxAttempt = 1; 301 302 @Option( 303 name = "skip-gce-teardown", 304 description = 305 "Whether or not to skip the GCE tear down. Skipping tear down will " 306 + "result in the instance being left.") 307 private boolean mSkipTearDown = false; 308 309 @Option( 310 name = "use-oxygen", 311 description = "Whether or not to use virtual devices created by Oxygen.") 312 private boolean mUseOxygen = false; 313 314 @Deprecated 315 @Option( 316 name = "use-oxygen-client", 317 description = "Whether or not to use Oxygen client tool to create virtual devices.") 318 private boolean mUseOxygenClient = true; 319 320 @Option(name = "oxygen-target-region", description = "Oxygen device target region.") 321 private String mOxygenTargetRegion = null; 322 323 @Option( 324 name = "oxygen-lease-length", 325 description = "Oxygen device lease length.", 326 isTimeVal = true) 327 private long mOxygenLeaseLength = 600 * 60 * 1000; 328 329 @Option( 330 name = "oxygen-device-size", 331 description = "The size of the host which Oxygen virtual device will be running on.") 332 private DeviceSize mOxygenDeviceSize = DeviceSize.STANDARD; 333 334 @Option(name = "oxygen-service-address", description = "Oxygen service address.") 335 private String mOxygenServiceAddress = null; 336 337 @Option(name = "oxygen-accounting-user", description = "Oxygen account user.") 338 private String mOxygenAccountingUser = null; 339 340 @Option( 341 name = "extra-oxygen-args", 342 description = "Extra arguments passed to Oxygen client to lease a device.") 343 private Map<String, String> mExtraOxygenArgs = new LinkedHashMap<>(); 344 345 @Option( 346 name = "wait-gce-teardown", 347 description = "Whether or not to block on gce teardown before proceeding.") 348 private boolean mWaitForGceTearDown = false; 349 350 @Option( 351 name = "instance-user", 352 description = 353 "The account to be used to interact with the " 354 + "outer layer of the GCE VM, e.g. to SSH in") 355 private String mInstanceUser = "root"; 356 357 @Option( 358 name = "remote-adb-port", 359 description = "The port on remote instance where the adb " + "server listens to.") 360 private int mRemoteAdbPort = DEFAULT_ADB_PORT; 361 362 @Option( 363 name = "base-host-image", 364 description = "The base image to be used for the GCE VM to host emulator.") 365 private String mBaseImage = null; 366 367 @Option( 368 name = "remote-fetch-file-pattern", 369 description = 370 "Only for remote VM devices. Allows to specify patterns to fetch file on the " 371 + "remote VM via scp. Pattern must follow the scp notations." 372 ) 373 private Set<String> mRemoteFetchFilePattern = new HashSet<>(); 374 375 @Option(name = "cros-user", description = "(CHEEPS ONLY) Account to log in to Chrome OS with.") 376 private String mCrosUser = null; 377 378 @Option( 379 name = "cros-password", 380 description = 381 "(CHEEPS ONLY) Password to log in to Chrome OS with. Only used if cros-user " 382 + "is specified." 383 ) 384 private String mCrosPassword = null; 385 386 @Option( 387 name = "invocation-attribute-to-metadata", 388 description = 389 "Pass the named attribute found in invocation context to GCE driver (acloud)" 390 + " as metadata to be associated with the GCE VM. e.g. if invocation" 391 + " context has form_factor=phone, it'll be added to GCE VM as metadata" 392 + " form_factor=phone.") 393 private List<String> mInvocationAttributeToMetadata = new ArrayList<>(); 394 395 @Option( 396 name = "gce-extra-files", 397 description = 398 "Path of extra files need to upload GCE instance during Acloud create." 399 + "Key is local file, value is GCE destination path.") 400 private MultiMap<File, String> mGceExtraFiles = new MultiMap<>(); 401 402 @Option( 403 name = "use-cmd-wifi", 404 description = "Feature flag to switch the wifi connection to using cmd commands.") 405 private boolean mUseCmdWifi = false; 406 407 @Option(name = "cmd-wifi-virtual", description = "Whether to use cmd wifi for virtual devices.") 408 private boolean mCmdWifiVirtual = true; 409 410 @Option( 411 name = "use-oxygenation-device", 412 description = 413 "Whether or not to use virtual devices created by Oxygenation. This is under" 414 + " development, and should be set on demand for running platform" 415 + " tests against an oxygenation device.") 416 private boolean mUseOxygenationDevice = false; 417 418 // END ====================== Options Related to Virtual Devices ====================== 419 420 // Option related to Remote Device only 421 422 public static final String REMOTE_TF_VERSION_OPTION = "remote-tf-version"; 423 424 @Option( 425 name = REMOTE_TF_VERSION_OPTION, 426 description = 427 "The TF to push to the remote VM to drive the invocation. If null, current TF " 428 + "will be pushed." 429 ) 430 private File mRemoteTFVersion = null; 431 432 /** Check whether adb root should be enabled on boot for this device */ isEnableAdbRoot()433 public boolean isEnableAdbRoot() { 434 return mEnableAdbRoot; 435 } 436 437 /** 438 * Check whether or not we should attempt to disable the keyguard once boot has completed 439 */ isDisableKeyguard()440 public boolean isDisableKeyguard() { 441 return mDisableKeyguard; 442 } 443 444 /** 445 * Set whether or not we should attempt to disable the keyguard once boot has completed 446 */ setDisableKeyguard(boolean disableKeyguard)447 public void setDisableKeyguard(boolean disableKeyguard) { 448 mDisableKeyguard = disableKeyguard; 449 } 450 451 /** 452 * Get the approximate maximum size of a tmp logcat data to retain, in bytes. 453 */ getMaxLogcatDataSize()454 public long getMaxLogcatDataSize() { 455 return mMaxLogcatDataSize; 456 } 457 458 /** 459 * Set the approximate maximum size of a tmp logcat to retain, in bytes 460 */ setMaxLogcatDataSize(long maxLogcatDataSize)461 public void setMaxLogcatDataSize(long maxLogcatDataSize) { 462 mMaxLogcatDataSize = maxLogcatDataSize; 463 } 464 465 /** 466 * @return the timeout to send a command in msecs. 467 */ getAdbCommandTimeout()468 public long getAdbCommandTimeout() { 469 return mAdbCommandTimeout; 470 } 471 472 /** Sets the timeout to send a command in msecs. */ setAdbCommandTimeout(long adbCommandTimeout)473 public void setAdbCommandTimeout(long adbCommandTimeout) { 474 mAdbCommandTimeout = adbCommandTimeout; 475 } 476 477 /** 478 * @return the timeout to boot into fastboot mode in msecs. 479 */ getFastbootTimeout()480 public int getFastbootTimeout() { 481 return mFastbootTimeout; 482 } 483 getFastbootOutputTimeout()484 public long getFastbootOutputTimeout() { 485 return mFastbootOutputTimeout; 486 } 487 488 /** 489 * @param fastbootTimeout the timout in msecs to boot into fastboot mode. 490 */ setFastbootTimeout(int fastbootTimeout)491 public void setFastbootTimeout(int fastbootTimeout) { 492 mFastbootTimeout = fastbootTimeout; 493 } 494 495 /** 496 * @return the timeout in msecs to boot into recovery mode. 497 */ getAdbRecoveryTimeout()498 public int getAdbRecoveryTimeout() { 499 return mAdbRecoveryTimeout; 500 } 501 502 /** 503 * @param adbRecoveryTimeout the timeout in msecs to boot into recovery mode. 504 */ setAdbRecoveryTimeout(int adbRecoveryTimeout)505 public void setAdbRecoveryTimeout(int adbRecoveryTimeout) { 506 mAdbRecoveryTimeout = adbRecoveryTimeout; 507 } 508 509 /** 510 * @return the timeout in msecs for the full system boot. 511 */ getRebootTimeout()512 public int getRebootTimeout() { 513 return mRebootTimeout; 514 } 515 516 /** 517 * @param rebootTimeout the timeout in msecs for the system to fully boot. 518 */ setRebootTimeout(int rebootTimeout)519 public void setRebootTimeout(int rebootTimeout) { 520 mRebootTimeout = rebootTimeout; 521 } 522 523 /** 524 * @return whether to use fastboot erase instead of fastboot format to wipe partitions. 525 */ getUseFastbootErase()526 public boolean getUseFastbootErase() { 527 return mUseFastbootErase; 528 } 529 530 /** 531 * @param useFastbootErase whether to use fastboot erase instead of fastboot format to wipe 532 * partitions. 533 */ setUseFastbootErase(boolean useFastbootErase)534 public void setUseFastbootErase(boolean useFastbootErase) { 535 mUseFastbootErase = useFastbootErase; 536 } 537 538 /** Returns a specified fastboot binary to be used. if null, use the DeviceManager one. */ getFastbootBinary()539 public File getFastbootBinary() { 540 return mFastbootBinary; 541 } 542 543 /** 544 * @return the timeout in msecs for the filesystem to be formatted and the device to reboot 545 * after unencryption. 546 */ getUnencryptRebootTimeout()547 public int getUnencryptRebootTimeout() { 548 return mUnencryptRebootTimeout; 549 } 550 551 /** 552 * @param unencryptRebootTimeout the timeout in msecs for the filesystem to be formatted and 553 * the device to reboot after unencryption. 554 */ setUnencryptRebootTimeout(int unencryptRebootTimeout)555 public void setUnencryptRebootTimeout(int unencryptRebootTimeout) { 556 mUnencryptRebootTimeout = unencryptRebootTimeout; 557 } 558 559 /** 560 * @return the default time in ms to to wait for a device to be online. 561 */ getOnlineTimeout()562 public long getOnlineTimeout() { 563 return mOnlineTimeout; 564 } 565 setOnlineTimeout(long onlineTimeout)566 public void setOnlineTimeout(long onlineTimeout) { 567 mOnlineTimeout = onlineTimeout; 568 } 569 570 /** 571 * @return the default time in ms to to wait for a device to be available. 572 */ getAvailableTimeout()573 public long getAvailableTimeout() { 574 return mAvailableTimeout; 575 } 576 577 /** 578 * @return the time in ms to wait for a device to become unavailable after adb root. 579 */ getAdbRootUnavailableTimeout()580 public long getAdbRootUnavailableTimeout() { 581 return mAdbRootUnavailableTimeout; 582 } 583 584 /** 585 * @param adbRootUnavailableTimeout time in ms to wait for a device to become unavailable after 586 * adb root. 587 */ setAdbRootUnavailableTimeout(long adbRootUnavailableTimeout)588 public void setAdbRootUnavailableTimeout(long adbRootUnavailableTimeout) { 589 mAdbRootUnavailableTimeout = adbRootUnavailableTimeout; 590 } 591 592 /** 593 * @return the default URL to be used for connectivity tests. 594 */ getConnCheckUrl()595 public String getConnCheckUrl() { 596 return mConnCheckUrl; 597 } 598 setConnCheckUrl(String url)599 public void setConnCheckUrl(String url) { 600 mConnCheckUrl = url; 601 } 602 603 /** 604 * @return true if background logcat capture is enabled 605 */ isLogcatCaptureEnabled()606 public boolean isLogcatCaptureEnabled() { 607 return mEnableLogcat; 608 } 609 610 /** 611 * @return the default number of attempts to connect to wifi network. 612 */ getWifiAttempts()613 public int getWifiAttempts() { 614 return mWifiAttempts; 615 } 616 setWifiAttempts(int wifiAttempts)617 public void setWifiAttempts(int wifiAttempts) { 618 mWifiAttempts = wifiAttempts; 619 } 620 621 /** 622 * @return the base wait time between wifi connect retries. 623 */ getWifiRetryWaitTime()624 public int getWifiRetryWaitTime() { 625 return mWifiRetryWaitTime; 626 } 627 628 /** @return the maximum time to attempt to connect to wifi. */ getMaxWifiConnectTime()629 public long getMaxWifiConnectTime() { 630 return mMaxWifiConnectTime; 631 } 632 633 /** 634 * @return a list of shell commands to run after reboots. 635 */ getPostBootCommands()636 public List<String> getPostBootCommands() { 637 return mPostBootCommands; 638 } 639 640 /** 641 * @return the minimum battery level to continue the invocation. 642 */ getCutoffBattery()643 public Integer getCutoffBattery() { 644 return mCutoffBattery; 645 } 646 647 /** 648 * set the minimum battery level to continue the invocation. 649 */ setCutoffBattery(int cutoffBattery)650 public void setCutoffBattery(int cutoffBattery) { 651 if (cutoffBattery < 0 || cutoffBattery > 100) { 652 // Prevent impossible value. 653 throw new RuntimeException(String.format("Battery cutoff wasn't changed," 654 + "the value %s isn't within possible range (0-100).", cutoffBattery)); 655 } 656 mCutoffBattery = cutoffBattery; 657 } 658 659 /** 660 * @return the configured logcat options 661 */ getLogcatOptions()662 public String getLogcatOptions() { 663 return mLogcatOptions; 664 } 665 666 /** 667 * Set the options to be passed down to logcat 668 */ setLogcatOptions(String logcatOptions)669 public void setLogcatOptions(String logcatOptions) { 670 mLogcatOptions = logcatOptions; 671 } 672 673 /** 674 * @return if device reboot should be disabled 675 */ shouldDisableReboot()676 public boolean shouldDisableReboot() { 677 return mDisableReboot; 678 } 679 680 /** 681 * @return if the exponential retry strategy should be used. 682 */ isWifiExpoRetryEnabled()683 public boolean isWifiExpoRetryEnabled() { 684 return mWifiExpoRetryEnabled; 685 } 686 687 /** @return the wifiutil apk path */ getWifiUtilAPKPath()688 public String getWifiUtilAPKPath() { 689 return mWifiUtilAPKPath; 690 } 691 692 /** Returns the instance type of virtual device that should be created */ getInstanceType()693 public InstanceType getInstanceType() { 694 return mInstanceType; 695 } 696 697 /** Sets the instance type of virtual device that should be created */ setInstanceType(InstanceType type)698 public void setInstanceType(InstanceType type) { 699 mInstanceType = type; 700 } 701 702 /** Returns whether or not the Tradefed content provider can be used to push/pull files. */ shouldUseContentProvider()703 public boolean shouldUseContentProvider() { 704 return mUseContentProvider; 705 } 706 707 /** 708 * Returns whether to use a workaround to get shell exit status on older devices without shell 709 * v2. 710 */ useExitStatusWorkaround()711 public boolean useExitStatusWorkaround() { 712 return mExitStatusWorkaround; 713 } 714 715 // =========================== Getter and Setter for Virtual Devices 716 /** Return the Gce Avd timeout for the instance to come online. */ getGceCmdTimeout()717 public long getGceCmdTimeout() { 718 return mGceCmdTimeout; 719 } 720 721 /** Set the Gce Avd timeout for the instance to come online. */ setGceCmdTimeout(long gceCmdTimeout)722 public void setGceCmdTimeout(long gceCmdTimeout) { 723 mGceCmdTimeout = gceCmdTimeout; 724 } 725 726 /** Returns whether or not we should rely on the boot-timeout args from acloud if present. */ allowGceCmdTimeoutOverride()727 public boolean allowGceCmdTimeoutOverride() { 728 return mAllowGceCmdTimeoutOverride; 729 } 730 731 /** Return the path to the binary to start the Gce Avd instance. */ getAvdDriverBinary()732 public File getAvdDriverBinary() { 733 if (mAvdDriverBinary == null) { 734 throw new HarnessRuntimeException( 735 "The avd driver binary is not specified.", 736 InfraErrorIdentifier.OPTION_CONFIGURATION_ERROR); 737 } 738 if (!mAvdDriverBinary.exists()) { 739 throw new HarnessRuntimeException( 740 String.format( 741 "Could not find the avd driver binary at %s", 742 mAvdDriverBinary.getAbsolutePath()), 743 InfraErrorIdentifier.CONFIGURED_ARTIFACT_NOT_FOUND); 744 } 745 if (!FileUtil.ensureGroupRWX(mAvdDriverBinary)) { 746 throw new HarnessRuntimeException( 747 String.format( 748 "Failed to change avd driver binary to be executable at %s", 749 mAvdDriverBinary.getAbsolutePath()), 750 InfraErrorIdentifier.CONFIGURED_ARTIFACT_NOT_FOUND); 751 } 752 return mAvdDriverBinary; 753 } 754 755 /** Set the path to the binary to start the Gce Avd instance. */ setAvdDriverBinary(File avdDriverBinary)756 public void setAvdDriverBinary(File avdDriverBinary) { 757 mAvdDriverBinary = avdDriverBinary; 758 } 759 760 /** Return the Gce Avd config file to start the instance. */ getAvdConfigFile()761 public File getAvdConfigFile() { 762 return mAvdConfigFile; 763 } 764 765 /** Set the Gce Avd config file to start the instance. */ setAvdConfigFile(File avdConfigFile)766 public void setAvdConfigFile(File avdConfigFile) { 767 mAvdConfigFile = avdConfigFile; 768 } 769 770 /** @return the service account json key file. */ getServiceAccountJsonKeyFile()771 public File getServiceAccountJsonKeyFile() { 772 return mJsonKeyFile; 773 } 774 775 /** 776 * Set the service account json key file. 777 * 778 * @param jsonKeyFile the key file. 779 */ setServiceAccountJsonKeyFile(File jsonKeyFile)780 public void setServiceAccountJsonKeyFile(File jsonKeyFile) { 781 mJsonKeyFile = jsonKeyFile; 782 } 783 784 /** Return the path of the ssh key to use for operations with the Gce Avd instance. */ getSshPrivateKeyPath()785 public File getSshPrivateKeyPath() { 786 return mSshPrivateKeyPath; 787 } 788 789 /** Set the path of the ssh key to use for operations with the Gce Avd instance. */ setSshPrivateKeyPath(File sshPrivateKeyPath)790 public void setSshPrivateKeyPath(File sshPrivateKeyPath) { 791 mSshPrivateKeyPath = sshPrivateKeyPath; 792 } 793 794 /** Return the log level of the Gce Avd driver. */ getGceDriverLogLevel()795 public LogLevel getGceDriverLogLevel() { 796 return mGceDriverLogLevel; 797 } 798 799 /** Set the log level of the Gce Avd driver. */ setGceDriverLogLevel(LogLevel mGceDriverLogLevel)800 public void setGceDriverLogLevel(LogLevel mGceDriverLogLevel) { 801 this.mGceDriverLogLevel = mGceDriverLogLevel; 802 } 803 804 /** Return the additional GCE driver parameters provided via option */ getGceDriverParams()805 public List<String> getGceDriverParams() { 806 return mGceDriverParams; 807 } 808 809 /** Add a param to the gce driver params. */ addGceDriverParams(String param)810 public void addGceDriverParams(String param) { 811 mGceDriverParams.add(param); 812 } 813 814 /** Return the additional file paths as GCE driver parameters provided via option. */ getGceDriverFileParams()815 public MultiMap<String, File> getGceDriverFileParams() { 816 return mGceDriverFileParams; 817 } 818 819 /** Set the GCE driver parameter that should be paired with the build id from build info */ setGceDriverBuildIdParam(String gceDriverBuildIdParam)820 public void setGceDriverBuildIdParam(String gceDriverBuildIdParam) { 821 mGceDriverBuildIdParam = gceDriverBuildIdParam; 822 } 823 824 /** Return the GCE driver parameter that should be paired with the build id from build info */ getGceDriverBuildIdParam()825 public String getGceDriverBuildIdParam() { 826 return mGceDriverBuildIdParam; 827 } 828 829 /** Return the gce email account to use with the driver */ getGceAccount()830 public String getGceAccount() { 831 return mGceAccount; 832 } 833 834 /** Return the max number of attempts to start a gce device */ getGceMaxAttempt()835 public int getGceMaxAttempt() { 836 if (mGceMaxAttempt < 1) { 837 throw new RuntimeException("--max-gce-attempt cannot be bellow 1 attempt."); 838 } 839 return mGceMaxAttempt; 840 } 841 842 /** Set the max number of attempts to start a gce device */ setGceMaxAttempt(int gceMaxAttempt)843 public void setGceMaxAttempt(int gceMaxAttempt) { 844 mGceMaxAttempt = gceMaxAttempt; 845 } 846 847 /** Returns true if GCE tear down should be skipped. False otherwise. */ setSkipTearDown(boolean shouldSkipTearDown)848 public void setSkipTearDown(boolean shouldSkipTearDown) { 849 mSkipTearDown = shouldSkipTearDown; 850 } 851 852 /** Returns true if GCE tear down should be skipped. False otherwise. */ shouldSkipTearDown()853 public boolean shouldSkipTearDown() { 854 return mSkipTearDown; 855 } 856 857 /** Returns true if we should block on GCE tear down completion before proceeding. */ waitForGceTearDown()858 public boolean waitForGceTearDown() { 859 return mWaitForGceTearDown; 860 } 861 862 /** Returns true if use Oxygen to create virtual devices. False otherwise. */ useOxygen()863 public boolean useOxygen() { 864 return mUseOxygen; 865 } 866 867 /** Returns the instance user of GCE virtual device that should be created */ getInstanceUser()868 public String getInstanceUser() { 869 return mInstanceUser; 870 } 871 872 /** Set the instance user of GCE virtual device that should be created. */ setInstanceUser(String instanceUser)873 public void setInstanceUser(String instanceUser) { 874 mInstanceUser = instanceUser; 875 } 876 877 /** Returns the remote port in instance that the adb server listens to */ getRemoteAdbPort()878 public int getRemoteAdbPort() { 879 return mRemoteAdbPort; 880 } 881 882 /** Set the remote port in instance that the adb server listens to */ setRemoteAdbPort(int remoteAdbPort)883 public void setRemoteAdbPort(int remoteAdbPort) { 884 mRemoteAdbPort = remoteAdbPort; 885 } 886 887 /** Returns the base image name to be used for the current instance */ getBaseImage()888 public String getBaseImage() { 889 return mBaseImage; 890 } 891 892 /** Returns the list of pattern to attempt to fetch via scp. */ getRemoteFetchFilePattern()893 public Set<String> getRemoteFetchFilePattern() { 894 return mRemoteFetchFilePattern; 895 } 896 897 /** Returns the Chrome OS User to log in as. */ getCrosUser()898 public String getCrosUser() { 899 return mCrosUser; 900 } 901 902 /** Returns the password to log in to Chrome OS with. */ getCrosPassword()903 public String getCrosPassword() { 904 return mCrosPassword; 905 } 906 907 /** The file pointing to the directory of the Tradefed version to be pushed to the remote. */ getRemoteTf()908 public File getRemoteTf() { 909 return mRemoteTFVersion; 910 } 911 912 /** Return the extra files need to upload to GCE during acloud create. */ getExtraFiles()913 public MultiMap<File, String> getExtraFiles() { 914 return mGceExtraFiles; 915 } 916 917 /** Set the extra files need to upload to GCE during acloud create. */ setExtraFiles(MultiMap<File, String> extraFiles)918 public void setExtraFiles(MultiMap<File, String> extraFiles) { 919 mGceExtraFiles = extraFiles; 920 } 921 922 /** Returns whether or not to use cmd wifi commands instead of apk. */ useCmdWifiCommands()923 public boolean useCmdWifiCommands() { 924 return mUseCmdWifi; 925 } 926 setUseCmdWifi(boolean useCmdWifi)927 public void setUseCmdWifi(boolean useCmdWifi) { 928 mUseCmdWifi = useCmdWifi; 929 } 930 isCmdWifiVirtual()931 public boolean isCmdWifiVirtual() { 932 return mCmdWifiVirtual; 933 } 934 getCreateCommandByInstanceType(InstanceType type)935 public static String getCreateCommandByInstanceType(InstanceType type) { 936 switch (type) { 937 case CHEEPS: 938 case GCE: 939 case REMOTE_AVD: 940 case CUTTLEFISH: 941 case REMOTE_NESTED_AVD: 942 return "create"; 943 case EMULATOR: 944 return "create_gf"; 945 } 946 throw new RuntimeException("Unexpected InstanceType: " + type); 947 } 948 getExtraParamsByInstanceType(InstanceType type, String baseImage)949 public static List<String> getExtraParamsByInstanceType(InstanceType type, String baseImage) { 950 if (InstanceType.EMULATOR.equals(type)) { 951 // TODO(b/119440413) remove when base image can be passed via extra gce driver params 952 List<String> params = ArrayUtil.list(); 953 if (baseImage != null) { 954 params.add("--base_image"); 955 params.add(baseImage); 956 } 957 return params; 958 } 959 return Collections.emptyList(); 960 } 961 getInvocationAttributeToMetadata()962 public List<String> getInvocationAttributeToMetadata() { 963 return mInvocationAttributeToMetadata; 964 } 965 966 /** Returns true if we want TradeFed directly call Oxygen to lease a device. */ 967 @Deprecated useOxygenProxy()968 public boolean useOxygenProxy() { 969 return mUseOxygenClient; 970 } 971 972 /** Returns the target region of the Oxygen device. */ getOxygenTargetRegion()973 public String getOxygenTargetRegion() { 974 return mOxygenTargetRegion; 975 } 976 977 /** Returns the length of leasing the Oxygen device in milliseconds. */ getOxygenLeaseLength()978 public long getOxygenLeaseLength() { 979 return mOxygenLeaseLength; 980 } 981 982 /** Returns The size of the host which Oxygen virtual device will be running on. */ getOxygenDeviceSize()983 public DeviceSize getOxygenDeviceSize() { 984 return mOxygenDeviceSize; 985 } 986 987 /** Returns the service address of the Oxygen device. */ getOxygenServiceAddress()988 public String getOxygenServiceAddress() { 989 return mOxygenServiceAddress; 990 } 991 992 /** Returns the accounting user of the Oxygen device. */ getOxygenAccountingUser()993 public String getOxygenAccountingUser() { 994 return mOxygenAccountingUser; 995 } 996 997 /** Returns the extra arguments to lease an Oxygen device. */ getExtraOxygenArgs()998 public Map<String, String> getExtraOxygenArgs() { 999 return mExtraOxygenArgs; 1000 } 1001 1002 /** Returns whether or not to use the newer bootloader state status. */ useUpdatedBootloaderStatus()1003 public boolean useUpdatedBootloaderStatus() { 1004 return mUpdatedBootloaderStatus; 1005 } 1006 1007 /** Returns the timeout value to be applied to bugreportz capture. */ getBugreportzTimeout()1008 public long getBugreportzTimeout() { 1009 return mBugreportzTimeout; 1010 } 1011 1012 /** Return whether or not we should use the new connection feature. */ shouldUseConnection()1013 public boolean shouldUseConnection() { 1014 return mEnableConnectionFeature; 1015 } 1016 setUseConnection(boolean useConnection)1017 public void setUseConnection(boolean useConnection) { 1018 mEnableConnectionFeature = useConnection; 1019 } 1020 getDefaultNetworkType()1021 public String getDefaultNetworkType() { 1022 return mDefaultNetworkType; 1023 } 1024 getSnapuserdTimeout()1025 public long getSnapuserdTimeout() { 1026 return mSnapuserdTimeout; 1027 } 1028 1029 /** Returns true if it's to lease oxygenation devices in OmniLab's infra. False otherwise. */ useOxygenationDevice()1030 public boolean useOxygenationDevice() { 1031 return mUseOxygenationDevice; 1032 } 1033 } 1034 1035