Home | History | Annotate | Download | only in device
      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.tradefed.config.Option;
     19 
     20 import java.util.ArrayList;
     21 import java.util.List;
     22 
     23 /**
     24  * Container for {@link ITestDevice} {@link Option}s
     25  */
     26 public class TestDeviceOptions {
     27 
     28     /** Do not provide a setter method for that Option as it might be misused. */
     29     @Option(name = "enable-root", description = "enable adb root on boot.")
     30     private boolean mEnableAdbRoot = true;
     31 
     32     @Option(name = "disable-keyguard",
     33             description = "attempt to disable keyguard once boot is complete.")
     34     private boolean mDisableKeyguard = true;
     35 
     36     @Option(name = "enable-logcat", description =
     37             "Enable background logcat capture when invocation is running.")
     38     private boolean mEnableLogcat = true;
     39 
     40     @Option(name = "max-tmp-logcat-file", description =
     41         "The maximum size of tmp logcat data to retain, in bytes. " +
     42         "Only used if --enable-logcat is set")
     43     private long mMaxLogcatDataSize = 20 * 1024 * 1024;
     44 
     45     @Option(name = "logcat-options", description =
     46             "Options to be passed down to logcat command, if unspecified, \"-v threadtime\" will " +
     47             "be used. Only used if --enable-logcat is set")
     48     private String mLogcatOptions = null;
     49 
     50     @Option(name = "fastboot-timeout", description =
     51             "time in ms to wait for a device to boot into fastboot.")
     52     private int mFastbootTimeout = 1 * 60 * 1000;
     53 
     54     @Option(name = "adb-recovery-timeout", description =
     55             "time in ms to wait for a device to boot into recovery.")
     56     private int mAdbRecoveryTimeout = 1 * 60 * 1000;
     57 
     58     @Option(name = "reboot-timeout", description =
     59             "time in ms to wait for a device to reboot to full system.")
     60     private int mRebootTimeout = 2 * 60 * 1000;
     61 
     62     @Option(name = "use-fastboot-erase", description =
     63             "use fastboot erase instead of fastboot format to wipe partitions")
     64     private boolean mUseFastbootErase = false;
     65 
     66     @Option(name = "unencrypt-reboot-timeout", description = "time in ms to wait for the device to "
     67             + "format the filesystem and reboot after unencryption")
     68     private int mUnencryptRebootTimeout = 0;
     69 
     70     @Option(name = "online-timeout", description = "default time in ms to wait for the device to "
     71             + "be visible on adb.", isTimeVal = true)
     72     private long mOnlineTimeout = 1 * 60 * 1000;
     73 
     74     @Option(name = "available-timeout", description = "default time in ms to wait for the device "
     75             + "to be available aka fully boot.")
     76     private long mAvailableTimeout = 6 * 60 * 1000;
     77 
     78     @Option(name = "conn-check-url",
     79             description = "default URL to be used for connectivity checks.")
     80     private String mConnCheckUrl = "http://www.google.com";
     81 
     82     @Option(name = "wifi-attempts",
     83             description = "default number of attempts to connect to wifi network.")
     84     private int mWifiAttempts = 5;
     85 
     86     @Option(name = "wifi-retry-wait-time",
     87             description = "the base wait time in ms between wifi connect retries. "
     88             + "The actual wait time would be a multiple of this value.")
     89     private int mWifiRetryWaitTime = 60 * 1000;
     90 
     91     @Option(
     92         name = "max-wifi-connect-time",
     93         isTimeVal = true,
     94         description = "the maximum amount of time to attempt to connect to wifi."
     95     )
     96     private long mMaxWifiConnectTime = 10 * 60 * 1000;
     97 
     98     @Option(name = "wifi-exponential-retry",
     99             description = "Change the wifi connection retry strategy from a linear wait time into"
    100                     + " a binary exponential back-offs when retrying.")
    101     private boolean mWifiExpoRetryEnabled = true;
    102 
    103     @Option(name = "wifiutil-apk-path", description = "path to the wifiutil APK file")
    104     private String mWifiUtilAPKPath = null;
    105 
    106     @Option(name = "post-boot-command",
    107             description = "shell command to run after reboots during invocation")
    108     private List<String> mPostBootCommands = new ArrayList<String>();
    109 
    110     @Option(name = "disable-reboot",
    111             description = "disables device reboots globally, making them no-ops")
    112     private boolean mDisableReboot = false;
    113 
    114     @Option(name = "cutoff-battery", description =
    115             "the minimum battery level required to continue the invocation. Scale: 0-100")
    116     private Integer mCutoffBattery = null;
    117 
    118     /**
    119      * Check whether adb root should be enabled on boot for this device
    120      */
    121     public boolean isEnableAdbRoot() {
    122         return mEnableAdbRoot;
    123     }
    124 
    125     /**
    126      * Check whether or not we should attempt to disable the keyguard once boot has completed
    127      */
    128     public boolean isDisableKeyguard() {
    129         return mDisableKeyguard;
    130     }
    131 
    132     /**
    133      * Set whether or not we should attempt to disable the keyguard once boot has completed
    134      */
    135     public void setDisableKeyguard(boolean disableKeyguard) {
    136         mDisableKeyguard = disableKeyguard;
    137     }
    138 
    139     /**
    140      * Get the approximate maximum size of a tmp logcat data to retain, in bytes.
    141      */
    142     public long getMaxLogcatDataSize() {
    143         return mMaxLogcatDataSize;
    144     }
    145 
    146     /**
    147      * Set the approximate maximum size of a tmp logcat to retain, in bytes
    148      */
    149     public void setMaxLogcatDataSize(long maxLogcatDataSize) {
    150         mMaxLogcatDataSize = maxLogcatDataSize;
    151     }
    152 
    153     /**
    154      * @return the timeout to boot into fastboot mode in msecs.
    155      */
    156     public int getFastbootTimeout() {
    157         return mFastbootTimeout;
    158     }
    159 
    160     /**
    161      * @param fastbootTimeout the timout in msecs to boot into fastboot mode.
    162      */
    163     public void setFastbootTimeout(int fastbootTimeout) {
    164         mFastbootTimeout = fastbootTimeout;
    165     }
    166 
    167     /**
    168      * @return the timeout in msecs to boot into recovery mode.
    169      */
    170     public int getAdbRecoveryTimeout() {
    171         return mAdbRecoveryTimeout;
    172     }
    173 
    174     /**
    175      * @param adbRecoveryTimeout the timeout in msecs to boot into recovery mode.
    176      */
    177     public void setAdbRecoveryTimeout(int adbRecoveryTimeout) {
    178         mAdbRecoveryTimeout = adbRecoveryTimeout;
    179     }
    180 
    181     /**
    182      * @return the timeout in msecs for the full system boot.
    183      */
    184     public int getRebootTimeout() {
    185         return mRebootTimeout;
    186     }
    187 
    188     /**
    189      * @param rebootTimeout the timeout in msecs for the system to fully boot.
    190      */
    191     public void setRebootTimeout(int rebootTimeout) {
    192         mRebootTimeout = rebootTimeout;
    193     }
    194 
    195     /**
    196      * @return whether to use fastboot erase instead of fastboot format to wipe partitions.
    197      */
    198     public boolean getUseFastbootErase() {
    199         return mUseFastbootErase;
    200     }
    201 
    202     /**
    203      * @param useFastbootErase whether to use fastboot erase instead of fastboot format to wipe
    204      * partitions.
    205      */
    206     public void setUseFastbootErase(boolean useFastbootErase) {
    207         mUseFastbootErase = useFastbootErase;
    208     }
    209 
    210     /**
    211      * @return the timeout in msecs for the filesystem to be formatted and the device to reboot
    212      * after unencryption.
    213      */
    214     public int getUnencryptRebootTimeout() {
    215         return mUnencryptRebootTimeout;
    216     }
    217 
    218     /**
    219      * @param unencryptRebootTimeout the timeout in msecs for the filesystem to be formatted and
    220      * the device to reboot after unencryption.
    221      */
    222     public void setUnencryptRebootTimeout(int unencryptRebootTimeout) {
    223         mUnencryptRebootTimeout = unencryptRebootTimeout;
    224     }
    225 
    226     /**
    227      * @return the default time in ms to to wait for a device to be online.
    228      */
    229     public long getOnlineTimeout() {
    230         return mOnlineTimeout;
    231     }
    232 
    233     public void setOnlineTimeout(long onlineTimeout) {
    234         mOnlineTimeout = onlineTimeout;
    235     }
    236 
    237     /**
    238      * @return the default time in ms to to wait for a device to be available.
    239      */
    240     public long getAvailableTimeout() {
    241         return mAvailableTimeout;
    242     }
    243 
    244     /**
    245      * @return the default URL to be used for connectivity tests.
    246      */
    247     public String getConnCheckUrl() {
    248         return mConnCheckUrl;
    249     }
    250 
    251     public void setConnCheckUrl(String url) {
    252       mConnCheckUrl = url;
    253     }
    254 
    255     /**
    256      * @return true if background logcat capture is enabled
    257      */
    258     public boolean isLogcatCaptureEnabled() {
    259         return mEnableLogcat;
    260     }
    261 
    262     /**
    263      * @return the default number of attempts to connect to wifi network.
    264      */
    265     public int getWifiAttempts() {
    266         return mWifiAttempts;
    267     }
    268 
    269     public void setWifiAttempts(int wifiAttempts) {
    270         mWifiAttempts = wifiAttempts;
    271     }
    272 
    273     /**
    274      * @return the base wait time between wifi connect retries.
    275      */
    276     public int getWifiRetryWaitTime() {
    277         return mWifiRetryWaitTime;
    278     }
    279 
    280     /** @return the maximum time to attempt to connect to wifi. */
    281     public long getMaxWifiConnectTime() {
    282         return mMaxWifiConnectTime;
    283     }
    284 
    285     /**
    286      * @return a list of shell commands to run after reboots.
    287      */
    288     public List<String> getPostBootCommands() {
    289         return mPostBootCommands;
    290     }
    291 
    292     /**
    293      * @return the minimum battery level to continue the invocation.
    294      */
    295     public Integer getCutoffBattery() {
    296         return mCutoffBattery;
    297     }
    298 
    299     /**
    300      * set the minimum battery level to continue the invocation.
    301      */
    302     public void setCutoffBattery(int cutoffBattery) {
    303         if (cutoffBattery < 0 || cutoffBattery > 100) {
    304             // Prevent impossible value.
    305             throw new RuntimeException(String.format("Battery cutoff wasn't changed,"
    306                     + "the value %s isn't within possible range (0-100).", cutoffBattery));
    307         }
    308         mCutoffBattery = cutoffBattery;
    309     }
    310 
    311     /**
    312      * @return the configured logcat options
    313      */
    314     public String getLogcatOptions() {
    315         return mLogcatOptions;
    316     }
    317 
    318     /**
    319      * Set the options to be passed down to logcat
    320      */
    321     public void setLogcatOptions(String logcatOptions) {
    322         mLogcatOptions = logcatOptions;
    323     }
    324 
    325     /**
    326      * @return if device reboot should be disabled
    327      */
    328     public boolean shouldDisableReboot() {
    329         return mDisableReboot;
    330     }
    331 
    332     /**
    333      * @return if the exponential retry strategy should be used.
    334      */
    335     public boolean isWifiExpoRetryEnabled() {
    336         return mWifiExpoRetryEnabled;
    337     }
    338 
    339     /** @return the wifiutil apk path */
    340     public String getWifiUtilAPKPath() {
    341         return mWifiUtilAPKPath;
    342     }
    343 }
    344