OSDN Git Service

Merge "Low ram devices now use 60% reduction for task snap shots" into oc-mr1-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                 new AlwaysOnDisplayPolicy(mContext));
65     }
66
67     @Test
68     public void testInitialize_setsScreenBrightnessToValidValue() throws Exception {
69         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
70
71         assertNotEquals(PowerManager.BRIGHTNESS_DEFAULT, mServiceFake.screenBrightness);
72         assertTrue(mServiceFake.screenBrightness <= PowerManager.BRIGHTNESS_ON);
73     }
74
75     @Test
76     public void testAod_usesLightSensor() throws Exception {
77         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
78         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
79
80         mSensor.sendSensorEvent(1000);
81
82         assertEquals(1000, mServiceFake.screenBrightness);
83     }
84
85     @Test
86     public void testPausingAod_pausesLightSensor() throws Exception {
87         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
88         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
89
90         mSensor.sendSensorEvent(1000);
91
92         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
93
94         mSensor.sendSensorEvent(1001);
95
96         assertNotEquals(1001, mServiceFake.screenBrightness);
97     }
98
99     @Test
100     public void testPausingAod_resetsBrightness() throws Exception {
101         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
102         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
103
104         mSensor.sendSensorEvent(1000);
105
106         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
107
108         assertNotEquals(1000, mServiceFake.screenBrightness);
109     }
110
111     @Test
112     public void testPulsing_usesLightSensor() throws Exception {
113         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
114         mScreen.transitionTo(INITIALIZED, DOZE);
115         mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
116
117         mSensor.sendSensorEvent(1000);
118
119         assertEquals(1000, mServiceFake.screenBrightness);
120     }
121
122     @Test
123     public void testDozingAfterPulsing_pausesLightSensor() throws Exception {
124         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
125         mScreen.transitionTo(INITIALIZED, DOZE);
126         mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
127         mScreen.transitionTo(DOZE_REQUEST_PULSE, DOZE_PULSING);
128         mScreen.transitionTo(DOZE_PULSING, DOZE_PULSE_DONE);
129         mScreen.transitionTo(DOZE_PULSE_DONE, DOZE);
130
131         mSensor.sendSensorEvent(1000);
132
133         assertNotEquals(1000, mServiceFake.screenBrightness);
134     }
135
136     @Test
137     public void testNullSensor() throws Exception {
138         mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
139                 null /* sensor */, mHostFake, null /* handler */,
140                 new AlwaysOnDisplayPolicy(mContext));
141
142         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
143         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
144         mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED);
145     }
146
147     @Test
148     public void testNoBrightnessDeliveredAfterFinish() throws Exception {
149         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
150         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
151         mScreen.transitionTo(DOZE_AOD, FINISH);
152
153         mSensor.sendSensorEvent(1000);
154
155         assertNotEquals(1000, mServiceFake.screenBrightness);
156     }
157
158     @Test
159     public void testBrightness_atLeastOne() throws Exception {
160         mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
161         mScreen.transitionTo(INITIALIZED, DOZE_AOD);
162
163         mSensor.sendSensorEvent(0);
164
165         assertTrue("Brightness must be at least 1, but was " + mServiceFake.screenBrightness,
166                 mServiceFake.screenBrightness >= 1);
167     }
168 }