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