Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2012 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.targetprep;
     17 
     18 import com.android.tradefed.build.IBuildInfo;
     19 import com.android.tradefed.config.Option;
     20 import com.android.tradefed.config.OptionClass;
     21 import com.android.tradefed.device.DeviceNotAvailableException;
     22 import com.android.tradefed.device.ITestDevice;
     23 import com.android.tradefed.log.LogUtil.CLog;
     24 import com.android.tradefed.util.IRunUtil;
     25 import com.android.tradefed.util.RunUtil;
     26 
     27 /**
     28  * A simple target preparer to waste time and potentially restart the device.
     29  */
     30 @OptionClass(alias = "time-waster")
     31 public class TimeWaster implements ITargetPreparer {
     32     @Option(name = "delay", description = "Time to delay, in msecs", mandatory = true)
     33     private long mDelayMsecs = 0;
     34 
     35     @Option(name = "reboot-before-sleep", description = "Whether to reboot the device before " +
     36             "sleeping")
     37     private boolean mRebootBeforeSleep = false;
     38 
     39     @Option(name = "reboot-after-sleep", description = "Whether to reboot the device after " +
     40             "sleeping")
     41     private boolean mRebootAfterSleep = false;
     42 
     43     /**
     44      * {@inheritDoc}
     45      */
     46     @Override
     47     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
     48             DeviceNotAvailableException {
     49         if (mRebootBeforeSleep) {
     50             CLog.d("Pre-sleep device reboot on %s", device.getSerialNumber());
     51             device.reboot();
     52         }
     53 
     54         CLog.d("Sleeping %d msecs on device %s", mDelayMsecs, device.getSerialNumber());
     55         getRunUtil().sleep(mDelayMsecs);
     56 
     57         if (mRebootAfterSleep) {
     58             CLog.d("Post-sleep device reboot on %s", device.getSerialNumber());
     59             device.reboot();
     60         }
     61     }
     62 
     63     IRunUtil getRunUtil() {
     64         return RunUtil.getDefault();
     65     }
     66 }
     67