1 /*
2  * Copyright (C) 2015 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.compatibility.common.tradefed.targetprep;
17 
18 import com.android.tradefed.config.OptionClass;
19 import com.android.tradefed.device.DeviceNotAvailableException;
20 import com.android.tradefed.invoker.TestInformation;
21 import com.android.tradefed.targetprep.BuildError;
22 import com.android.tradefed.targetprep.TargetSetupError;
23 
24 /**
25  * Modifies the 'Stay Awake' setting of the device, so that the device's screen stays on
26  * whenever charging via USB
27  */
28 @OptionClass(alias="stay-awake-preparer")
29 public class StayAwakePreparer extends SettingsPreparer {
30 
31     private static final String STAY_AWAKE_SETTING = "stay_on_while_plugged_in";
32 
33     /*
34      * Values that are appropriate for the "Stay Awake" setting while running compatibility tests:
35      * (the second bit must be 'on' to allow screen to stay awake while charging via USB)
36      * 2 - Stay awake while charging via USB
37      * 3 - Stay awake while changing via USB or AC
38      * 6 - Stay awake while charging via USB or Wireless
39      * 7 - Stay awake while charging via USB or AC or Wireless
40      */
41     private static final String[] STAY_AWAKE_VALUES = new String[] {"2", "3", "6", "7"};
42     private static final String DEFAULT_VALUE = "7";
43 
44     @Override
run(TestInformation testInfo)45     public void run(TestInformation testInfo)
46             throws TargetSetupError, BuildError, DeviceNotAvailableException {
47 
48         mSettingName = STAY_AWAKE_SETTING;
49         mSettingType = SettingsPreparer.SettingType.GLOBAL;
50         mSetValue = DEFAULT_VALUE;
51         for (String value : STAY_AWAKE_VALUES) {
52             mExpectedSettingValues.add(value);
53         }
54         super.run(testInfo);
55     }
56 
57 }
58