OSDN Git Service

Merge "Don't lock down system user in demo mode" into oc-dr1-dev
[android-x86/frameworks-base.git] / packages / SystemUI / tests / src / com / android / systemui / doze / DozeScreenBrightnessTest.java
1 /*
2  * Copyright (C) 2017 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 com.android.systemui.doze;
18
19 import static com.android.systemui.doze.DozeMachine.State.DOZE;
20 import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD;
21 import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD_PAUSED;
22 import static com.android.systemui.doze.DozeMachine.State.DOZE_PULSE_DONE;
23 import static com.android.systemui.doze.DozeMachine.State.DOZE_PULSING;
24 import static com.android.systemui.doze.DozeMachine.State.DOZE_REQUEST_PULSE;
25 import static com.android.systemui.doze.DozeMachine.State.FINISH;
26 import static com.android.systemui.doze.DozeMachine.State.INITIALIZED;
27 import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotEquals;
31 import static org.junit.Assert.assertTrue;
32
33 import android.os.PowerManager;
34 import android.support.test.filters.SmallTest;
35 import android.support.test.runner.AndroidJUnit4;
36
37 import com.android.systemui.SysuiTestCase;
38 import com.android.systemui.utils.hardware.FakeSensorManager;
39
40 import org.junit.Before;
41 import org.junit.Ignore;
42 import org.junit.Test;
43 import org.junit.runner.RunWith;
44
45 @RunWith(AndroidJUnit4.class)
46 @SmallTest
47 @Ignore
48 public class DozeScreenBrightnessTest extends SysuiTestCase {
49
50     DozeServiceFake mServiceFake;
51     DozeScreenBrightness mScreen;
52     FakeSensorManager.FakeGenericSensor mSensor;
53     FakeSensorManager mSensorManager;
54     DozeHostFake mHostFake;
55
56     @Before
57     public void setUp() throws Exception {
58         mServiceFake = new DozeServiceFake();
59         mHostFake = new DozeHostFake();
60         mSensorManager = new FakeSensorManager(mContext);
61         mSensor = mSensorManager.getFakeLightSensor();
62         mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
63                 mSensor.getSensor(), mHostFake, null /* handler */);
64     }
65
66     @Test
67     public void testInitialize_setsScreenBrightnessToValidValue() throws Exception {
68         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
69
70         assertNotEquals(PowerManager.BRIGHTNESS_DEFAULT, mServiceFake.screenBrightness);
71         assertTrue(mServiceFake.screenBrightness <= PowerManager.BRIGHTNESS_ON);
72     }
73
74     @Test
75     public void testAod_usesLightSensor() throws Exception {
76         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
77         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
78
79         mSensor.sendSensorEvent(1000);
80
81         assertEquals(1000, mServiceFake.screenBrightness);
82     }
83
84     @Test
85     public void testPausingAod_pausesLightSensor() throws Exception {
86         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
87         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
88
89         mSensor.sendSensorEvent(1000);
90
91         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
92
93         mSensor.sendSensorEvent(1001);
94
95         assertNotEquals(1001, mServiceFake.screenBrightness);
96     }
97
98     @Test
99     public void testPausingAod_resetsBrightness() throws Exception {
100         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
101         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
102
103         mSensor.sendSensorEvent(1000);
104
105         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
106
107         assertNotEquals(1000, mServiceFake.screenBrightness);
108     }
109
110     @Test
111     public void testPulsing_usesLightSensor() throws Exception {
112         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
113         mScreen.transitionTo(INITIALIZED, DOZE);
114         mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
115
116         mSensor.sendSensorEvent(1000);
117
118         assertEquals(1000, mServiceFake.screenBrightness);
119     }
120
121     @Test
122     public void testDozingAfterPulsing_pausesLightSensor() throws Exception {
123         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
124         mScreen.transitionTo(INITIALIZED, DOZE);
125         mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
126         mScreen.transitionTo(DOZE_REQUEST_PULSE, DOZE_PULSING);
127         mScreen.transitionTo(DOZE_PULSING, DOZE_PULSE_DONE);
128         mScreen.transitionTo(DOZE_PULSE_DONE, DOZE);
129
130         mSensor.sendSensorEvent(1000);
131
132         assertNotEquals(1000, mServiceFake.screenBrightness);
133     }
134
135     @Test
136     public void testNullSensor() throws Exception {
137         mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
138                 null /* sensor */, mHostFake, null /* handler */);
139
140         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
141         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
142         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
143     }
144
145     @Test
146     public void testNoBrightnessDeliveredAfterFinish() throws Exception {
147         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
148         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
149         mScreen.transitionTo(DOZE_AOD, FINISH);
150
151         mSensor.sendSensorEvent(1000);
152
153         assertNotEquals(1000, mServiceFake.screenBrightness);
154     }
155
156     @Test
157     public void testBrightness_atLeastOne() throws Exception {
158         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
159         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
160
161         mSensor.sendSensorEvent(0);
162
163         assertTrue("Brightness must be at least 1, but was " + mServiceFake.screenBrightness,
164                 mServiceFake.screenBrightness >= 1);
165     }
166 }