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