• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package android.os.cts;
18 
19 import static android.os.PowerManagerInternalProto.Wakefulness.WAKEFULNESS_ASLEEP;
20 import static android.os.PowerManagerInternalProto.Wakefulness.WAKEFULNESS_AWAKE;
21 
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assume.assumeFalse;
24 import static org.junit.Assume.assumeTrue;
25 
26 import android.os.PowerManagerInternalProto.Wakefulness;
27 
28 import com.android.compatibility.common.util.PropertyUtil;
29 import com.android.compatibility.common.util.ProtoUtils;
30 import com.android.compatibility.common.util.WindowManagerUtil;
31 import com.android.server.power.PowerManagerServiceDumpProto;
32 import com.android.tradefed.device.ITestDevice;
33 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
34 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
35 
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 
41 import java.util.List;
42 
43 @RunWith(DeviceJUnit4ClassRunner.class)
44 public class QuiescentBootTests extends BaseHostJUnit4Test {
45     private static final String REBOOT_REASON_QUIESCENT = "quiescent";
46     private static final String FEATURE_LEANBACK_ONLY = "android.software.leanback_only";
47     private static final String CMD_DUMPSYS_POWER = "dumpsys power --proto";
48     private static final String CMD_INPUT_WAKEUP = "input keyevent WAKEUP";
49     private static final String CMD_INPUT_POWER = "input keyevent POWER";
50 
51     // A reference to the device under test, which gives us a handle to run commands.
52     private ITestDevice mDevice;
53 
54     @Before
setUp()55     public synchronized void setUp() throws Exception {
56         mDevice = getDevice();
57         assumeTrue("Test only applicable to TVs.", hasDeviceFeature(FEATURE_LEANBACK_ONLY));
58         assumeFalse("Test only applicable to devices launching on Android 11 or later.",
59             (PropertyUtil.getFirstApiLevel(mDevice) < 30));
60     }
61 
62     @After
tearDown()63     public void tearDown() throws Exception {
64         if (hasDeviceFeature(FEATURE_LEANBACK_ONLY)) {
65             mDevice.executeShellCommand(CMD_INPUT_WAKEUP);
66         }
67     }
68 
69     @Test
testQuiescentBoot_asleep()70     public void testQuiescentBoot_asleep() throws Exception {
71         mDevice.reboot(REBOOT_REASON_QUIESCENT);
72         assertEquals("Expected to boot into sleep state.", WAKEFULNESS_ASLEEP, getWakefulness());
73     }
74 
75     @Test
testQuiescentBoot_wakesUpWithPowerButton()76     public void testQuiescentBoot_wakesUpWithPowerButton() throws Exception {
77         mDevice.reboot(REBOOT_REASON_QUIESCENT);
78         mDevice.executeShellCommand(CMD_INPUT_POWER);
79         assertEquals("Expected to wake up when pressing the power button.",
80                 WAKEFULNESS_AWAKE, getWakefulness());
81     }
82 
83     @Test
testQuiescentBoot_asleepAfterQuiescentReboot()84     public void testQuiescentBoot_asleepAfterQuiescentReboot() throws Exception {
85         mDevice.reboot(REBOOT_REASON_QUIESCENT);
86         assertEquals("Expected to boot into sleep state.", WAKEFULNESS_ASLEEP, getWakefulness());
87     }
88 
89     @Test
testQuiescentBoot_activitiesNotResumedAfterBoot()90     public void testQuiescentBoot_activitiesNotResumedAfterBoot() throws Exception {
91         mDevice.reboot(REBOOT_REASON_QUIESCENT);
92         List<String> resumedActivities = WindowManagerUtil.getResumedActivities(getDevice());
93         assertEquals("Expected no resumed activities", 0, resumedActivities.size());
94     }
95 
getWakefulness()96     private Wakefulness getWakefulness() throws Exception {
97         return ((PowerManagerServiceDumpProto) ProtoUtils.getProto(getDevice(),
98                 PowerManagerServiceDumpProto.parser(),
99                 CMD_DUMPSYS_POWER)).getWakefulness();
100     }
101 }
102