blob: 9fdd3b88e9d0cf704f4f93208492e312df7de9a3 [file] [log] [blame]
Lucas Dupin9e3fa102017-11-08 17:16:55 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.graphics.Color;
20import android.os.Trace;
21
22import com.android.systemui.statusbar.ScrimView;
Rohan Shah20790b82018-07-02 17:21:04 -070023import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080024
25/**
26 * Possible states of the ScrimController state machine.
27 */
28public enum ScrimState {
29
30 /**
31 * Initial state.
32 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080033 UNINITIALIZED(-1),
Lucas Dupin9e3fa102017-11-08 17:16:55 -080034
35 /**
36 * On the lock screen.
37 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080038 KEYGUARD(0) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080039
40 @Override
41 public void prepare(ScrimState previousState) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080042 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080043 if (previousState == ScrimState.AOD) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080044 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
45 if (mDisplayRequiresBlanking) {
46 // DisplayPowerManager will blank the screen, we'll just
47 // set our scrim to black in this frame to avoid flickering and
48 // fade it out afterwards.
49 mBlankScreen = true;
Lucas Dupin43d0d732017-11-16 11:23:49 -080050 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070051 } else if (previousState == ScrimState.KEYGUARD) {
52 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
Lucas Dupin43d0d732017-11-16 11:23:49 -080053 } else {
54 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080055 }
Lucas Dupin1113fdf2019-03-07 17:32:00 -080056 mCurrentInFrontTint = Color.BLACK;
57 mCurrentBehindTint = Color.BLACK;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080058 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
59 mCurrentInFrontAlpha = 0;
60 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070061 },
62
63 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080064 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080065 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080066 BOUNCER(1) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080067 @Override
68 public void prepare(ScrimState previousState) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080069 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
70 mCurrentInFrontAlpha = 0f;
71 }
72 },
73
74 /**
75 * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
76 */
Lucas Dupin05726cd2018-03-13 14:00:24 -070077 BOUNCER_SCRIMMED(2) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080078 @Override
79 public void prepare(ScrimState previousState) {
80 mCurrentBehindAlpha = 0;
81 mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080082 }
83 },
84
85 /**
86 * Changing screen brightness from quick settings.
87 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080088 BRIGHTNESS_MIRROR(3) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080089 @Override
90 public void prepare(ScrimState previousState) {
91 mCurrentBehindAlpha = 0;
92 mCurrentInFrontAlpha = 0;
93 }
94 },
95
96 /**
97 * Always on display or screen off.
98 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080099 AOD(4) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800100 @Override
101 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800102 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800103 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800104 mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
105 mCurrentInFrontTint = Color.BLACK;
106 mCurrentBehindTint = Color.BLACK;
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700107 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700108 // DisplayPowerManager may blank the screen for us,
109 // in this case we just need to set our state.
110 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800111 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700112
113 @Override
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800114 public float getBehindAlpha() {
Lucas Dupin9bee5822018-07-09 14:32:53 -0700115 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
116 }
117
118 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700119 public boolean isLowPowerState() {
120 return true;
121 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800122 },
123
124 /**
125 * When phone wakes up because you received a notification.
126 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800127 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800128 @Override
129 public void prepare(ScrimState previousState) {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800130 mCurrentInFrontAlpha = 0f;
Lucas Dupin3113db62019-03-08 18:21:27 -0800131 mCurrentBehindTint = Color.BLACK;
Lucas Dupina7eacf92019-07-24 12:40:34 -0700132 mCurrentInFrontTint = Color.BLACK;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800133 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupina7eacf92019-07-24 12:40:34 -0700134 mAnimationDuration = mWakeLockScreenSensorActive
135 ? ScrimController.ANIMATION_DURATION_LONG : ScrimController.ANIMATION_DURATION;
Lucas Dupinfea9b862019-08-08 16:58:50 -0700136
137 // Wake sensor will show the wallpaper, let's fade from black. Otherwise it will
138 // feel like the screen is flashing if the wallpaper is light.
139 if (mWakeLockScreenSensorActive && previousState == AOD) {
140 updateScrimColor(mScrimBehind, 1f /* alpha */, Color.BLACK);
141 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800142 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700143
144 @Override
145 public float getBehindAlpha() {
146 return mWakeLockScreenSensorActive ? ScrimController.WAKE_SENSOR_SCRIM_ALPHA
147 : AOD.getBehindAlpha();
148 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800149 },
150
151 /**
152 * Unlocked on top of an app (launcher or any other activity.)
153 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800154 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800155 @Override
156 public void prepare(ScrimState previousState) {
157 mCurrentBehindAlpha = 0;
158 mCurrentInFrontAlpha = 0;
Selim Cinek72cd9a72019-08-09 17:19:57 -0700159 mAnimationDuration = mKeyguardFadingAway
160 ? mKeyguardFadingAwayDuration
Selim Cinek84b2acc2019-07-07 00:40:38 -0700161 : StatusBar.FADE_KEYGUARD_DURATION;
Lucas Dupin193677c2018-06-11 19:16:03 -0700162 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800163
Lucas Dupind35502f2018-06-27 13:35:52 -0700164 if (previousState == ScrimState.AOD) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800165 // Fade from black to transparent when coming directly from AOD
166 updateScrimColor(mScrimInFront, 1, Color.BLACK);
167 updateScrimColor(mScrimBehind, 1, Color.BLACK);
168 // Scrims should still be black at the end of the transition.
169 mCurrentInFrontTint = Color.BLACK;
170 mCurrentBehindTint = Color.BLACK;
171 mBlankScreen = true;
172 } else {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800173 mCurrentInFrontTint = Color.TRANSPARENT;
174 mCurrentBehindTint = Color.TRANSPARENT;
175 mBlankScreen = false;
176 }
177 }
Mady Mellor0c333772018-11-06 18:05:54 -0800178 },
179
180 /**
181 * Unlocked with a bubble expanded.
182 */
183 BUBBLE_EXPANDED(7) {
184 @Override
185 public void prepare(ScrimState previousState) {
186 mCurrentInFrontTint = Color.TRANSPARENT;
187 mCurrentBehindTint = Color.TRANSPARENT;
188 mAnimationDuration = ScrimController.ANIMATION_DURATION;
189 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
190 mBlankScreen = false;
191 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800192 };
193
194 boolean mBlankScreen = false;
195 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
196 int mCurrentInFrontTint = Color.TRANSPARENT;
197 int mCurrentBehindTint = Color.TRANSPARENT;
198 boolean mAnimateChange = true;
199 float mCurrentInFrontAlpha;
200 float mCurrentBehindAlpha;
201 float mAodFrontScrimAlpha;
202 float mScrimBehindAlphaKeyguard;
203 ScrimView mScrimInFront;
204 ScrimView mScrimBehind;
205 DozeParameters mDozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800206 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700207 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800208 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700209 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700210 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700211 boolean mWakeLockScreenSensorActive;
Selim Cinek72cd9a72019-08-09 17:19:57 -0700212 boolean mKeyguardFadingAway;
213 long mKeyguardFadingAwayDuration;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800214
215 ScrimState(int index) {
216 mIndex = index;
217 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800218
219 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
220 mScrimInFront = scrimInFront;
221 mScrimBehind = scrimBehind;
222 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800223 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800224 }
225
226 public void prepare(ScrimState previousState) {
227 }
228
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800229 public int getIndex() {
230 return mIndex;
231 }
232
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800233 public float getFrontAlpha() {
234 return mCurrentInFrontAlpha;
235 }
236
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800237 public float getBehindAlpha() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800238 return mCurrentBehindAlpha;
239 }
240
241 public int getFrontTint() {
242 return mCurrentInFrontTint;
243 }
244
245 public int getBehindTint() {
246 return mCurrentBehindTint;
247 }
248
249 public long getAnimationDuration() {
250 return mAnimationDuration;
251 }
252
253 public boolean getBlanksScreen() {
254 return mBlankScreen;
255 }
256
257 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
258 Trace.traceCounter(Trace.TRACE_TAG_APP,
259 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
260 (int) (alpha * 255));
261
262 Trace.traceCounter(Trace.TRACE_TAG_APP,
263 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
264 Color.alpha(tint));
265
266 scrim.setTint(tint);
267 scrim.setViewAlpha(alpha);
268 }
269
270 public boolean getAnimateChange() {
271 return mAnimateChange;
272 }
273
274 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
275 mAodFrontScrimAlpha = aodFrontScrimAlpha;
276 }
277
278 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
279 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
280 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700281
282 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
283 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
284 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700285
Lucas Dupin193677c2018-06-11 19:16:03 -0700286 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
287 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
288 }
289
Lucas Dupin38962d72018-03-14 12:41:39 -0700290 public boolean isLowPowerState() {
291 return false;
292 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700293
294 public void setHasBackdrop(boolean hasBackdrop) {
295 mHasBackdrop = hasBackdrop;
296 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700297
298 public void setWakeLockScreenSensorActive(boolean active) {
299 mWakeLockScreenSensorActive = active;
300 }
Selim Cinek84b2acc2019-07-07 00:40:38 -0700301
Selim Cinek72cd9a72019-08-09 17:19:57 -0700302 public void setKeyguardFadingAway(boolean fadingAway, long duration) {
303 mKeyguardFadingAway = fadingAway;
304 mKeyguardFadingAwayDuration = duration;
Selim Cinek84b2acc2019-07-07 00:40:38 -0700305 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800306}