blob: 7463c7c232bdd3668f317fe5f0878ff995ee3389 [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 @Override
40 public void prepare(ScrimState previousState) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080041 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080042 if (previousState == ScrimState.AOD) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080043 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
44 if (mDisplayRequiresBlanking) {
45 // DisplayPowerManager will blank the screen, we'll just
46 // set our scrim to black in this frame to avoid flickering and
47 // fade it out afterwards.
48 mBlankScreen = true;
Lucas Dupin43d0d732017-11-16 11:23:49 -080049 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070050 } else if (previousState == ScrimState.KEYGUARD) {
51 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
Lucas Dupin43d0d732017-11-16 11:23:49 -080052 } else {
53 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080054 }
Lyn Hanbde48202019-05-29 19:18:29 -070055 mFrontTint = Color.BLACK;
56 mBehindTint = Color.BLACK;
57 mBubbleTint = Color.TRANSPARENT;
58
59 mFrontAlpha = 0;
60 mBehindAlpha = mScrimBehindAlphaKeyguard;
61 mBubbleAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080062 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070063 },
64
65 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080066 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080067 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080068 BOUNCER(1) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080069 @Override
70 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -070071 mBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
72 mFrontAlpha = 0f;
73 mBubbleAlpha = 0f;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080074 }
75 },
76
77 /**
78 * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
79 */
Lucas Dupin05726cd2018-03-13 14:00:24 -070080 BOUNCER_SCRIMMED(2) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080081 @Override
82 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -070083 mBehindAlpha = 0;
84 mBubbleAlpha = 0f;
85 mFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080086 }
87 },
88
89 /**
90 * Changing screen brightness from quick settings.
91 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080092 BRIGHTNESS_MIRROR(3) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080093 @Override
94 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -070095 mBehindAlpha = 0;
96 mFrontAlpha = 0;
97 mBubbleAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080098 }
99 },
100
101 /**
102 * Always on display or screen off.
103 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800104 AOD(4) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800105 @Override
106 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800107 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800108 mBlankScreen = mDisplayRequiresBlanking;
Lyn Hanbde48202019-05-29 19:18:29 -0700109
110 mFrontTint = Color.BLACK;
111 mFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
112
113 mBehindTint = Color.BLACK;
114 mBehindAlpha = ScrimController.TRANSPARENT;
115
116 mBubbleTint = Color.TRANSPARENT;
117 mBubbleAlpha = ScrimController.TRANSPARENT;
118
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700119 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700120 // DisplayPowerManager may blank the screen for us,
121 // in this case we just need to set our state.
122 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800123 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700124
125 @Override
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800126 public float getBehindAlpha() {
Lucas Dupin9bee5822018-07-09 14:32:53 -0700127 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
128 }
129
130 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700131 public boolean isLowPowerState() {
132 return true;
133 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800134 },
135
136 /**
137 * When phone wakes up because you received a notification.
138 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800139 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800140 @Override
141 public void prepare(ScrimState previousState) {
Chris.CC Leed424e202019-09-16 12:17:19 +0800142 mFrontAlpha = mAodFrontScrimAlpha;
Lyn Hanbde48202019-05-29 19:18:29 -0700143 mBubbleAlpha = 0f;
144 mBehindTint = Color.BLACK;
Mady Mellor4035ef52019-07-25 11:10:02 -0700145 mFrontTint = Color.BLACK;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800146 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupina7eacf92019-07-24 12:40:34 -0700147 mAnimationDuration = mWakeLockScreenSensorActive
148 ? ScrimController.ANIMATION_DURATION_LONG : ScrimController.ANIMATION_DURATION;
Lucas Dupinfea9b862019-08-08 16:58:50 -0700149
150 // Wake sensor will show the wallpaper, let's fade from black. Otherwise it will
151 // feel like the screen is flashing if the wallpaper is light.
152 if (mWakeLockScreenSensorActive && previousState == AOD) {
153 updateScrimColor(mScrimBehind, 1f /* alpha */, Color.BLACK);
154 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800155 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700156
157 @Override
158 public float getBehindAlpha() {
159 return mWakeLockScreenSensorActive ? ScrimController.WAKE_SENSOR_SCRIM_ALPHA
160 : AOD.getBehindAlpha();
161 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800162 },
163
164 /**
165 * Unlocked on top of an app (launcher or any other activity.)
166 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800167 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800168 @Override
169 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700170 // State that UI will sync to.
171 mBehindAlpha = 0;
172 mFrontAlpha = 0;
173 mBubbleAlpha = 0;
174
Selim Cinek72cd9a72019-08-09 17:19:57 -0700175 mAnimationDuration = mKeyguardFadingAway
176 ? mKeyguardFadingAwayDuration
Selim Cinek84b2acc2019-07-07 00:40:38 -0700177 : StatusBar.FADE_KEYGUARD_DURATION;
Mady Mellor06792002019-08-13 14:33:24 -0700178
Lucas Dupin193677c2018-06-11 19:16:03 -0700179 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800180
Lyn Hanbde48202019-05-29 19:18:29 -0700181 mFrontTint = Color.TRANSPARENT;
182 mBehindTint = Color.TRANSPARENT;
183 mBubbleTint = Color.TRANSPARENT;
184 mBlankScreen = false;
185
Lucas Dupind35502f2018-06-27 13:35:52 -0700186 if (previousState == ScrimState.AOD) {
Lyn Hanbde48202019-05-29 19:18:29 -0700187 // Set all scrims black, before they fade transparent.
188 updateScrimColor(mScrimInFront, 1f /* alpha */, Color.BLACK /* tint */);
189 updateScrimColor(mScrimBehind, 1f /* alpha */, Color.BLACK /* tint */);
190 updateScrimColor(mScrimForBubble, 1f /* alpha */, Color.BLACK /* tint */);
191
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800192 // Scrims should still be black at the end of the transition.
Lyn Hanbde48202019-05-29 19:18:29 -0700193 mFrontTint = Color.BLACK;
194 mBehindTint = Color.BLACK;
195 mBubbleTint = Color.BLACK;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800196 mBlankScreen = true;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800197 }
198 }
Mady Mellor0c333772018-11-06 18:05:54 -0800199 },
200
201 /**
202 * Unlocked with a bubble expanded.
203 */
204 BUBBLE_EXPANDED(7) {
205 @Override
206 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700207 mFrontTint = Color.TRANSPARENT;
208 mBehindTint = Color.TRANSPARENT;
209 mBubbleTint = Color.TRANSPARENT;
210
211 mFrontAlpha = ScrimController.TRANSPARENT;
212 mBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Mady Mellor9b7c7fb2019-08-06 16:26:08 -0700213 mBubbleAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lyn Hanbde48202019-05-29 19:18:29 -0700214
Mady Mellor0c333772018-11-06 18:05:54 -0800215 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Mady Mellor0c333772018-11-06 18:05:54 -0800216 mBlankScreen = false;
217 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800218 };
219
220 boolean mBlankScreen = false;
221 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lyn Hanbde48202019-05-29 19:18:29 -0700222 int mFrontTint = Color.TRANSPARENT;
223 int mBehindTint = Color.TRANSPARENT;
224 int mBubbleTint = Color.TRANSPARENT;
225
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800226 boolean mAnimateChange = true;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800227 float mAodFrontScrimAlpha;
Lyn Hanbde48202019-05-29 19:18:29 -0700228 float mFrontAlpha;
229 float mBehindAlpha;
230 float mBubbleAlpha;
231
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800232 float mScrimBehindAlphaKeyguard;
233 ScrimView mScrimInFront;
234 ScrimView mScrimBehind;
Lyn Hanbde48202019-05-29 19:18:29 -0700235 ScrimView mScrimForBubble;
236
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800237 DozeParameters mDozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800238 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700239 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800240 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700241 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700242 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700243 boolean mWakeLockScreenSensorActive;
Selim Cinek72cd9a72019-08-09 17:19:57 -0700244 boolean mKeyguardFadingAway;
245 long mKeyguardFadingAwayDuration;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800246
247 ScrimState(int index) {
248 mIndex = index;
249 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800250
Lyn Hanbde48202019-05-29 19:18:29 -0700251 public void init(ScrimView scrimInFront, ScrimView scrimBehind, ScrimView scrimForBubble,
252 DozeParameters dozeParameters) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800253 mScrimInFront = scrimInFront;
254 mScrimBehind = scrimBehind;
Lyn Hanbde48202019-05-29 19:18:29 -0700255 mScrimForBubble = scrimForBubble;
256
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800257 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800258 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800259 }
260
Lyn Hanbde48202019-05-29 19:18:29 -0700261 /** Prepare state for transition. */
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800262 public void prepare(ScrimState previousState) {
263 }
264
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800265 public int getIndex() {
266 return mIndex;
267 }
268
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800269 public float getFrontAlpha() {
Lyn Hanbde48202019-05-29 19:18:29 -0700270 return mFrontAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800271 }
272
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800273 public float getBehindAlpha() {
Lyn Hanbde48202019-05-29 19:18:29 -0700274 return mBehindAlpha;
275 }
276
277 public float getBubbleAlpha() {
278 return mBubbleAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800279 }
280
281 public int getFrontTint() {
Lyn Hanbde48202019-05-29 19:18:29 -0700282 return mFrontTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800283 }
284
285 public int getBehindTint() {
Lyn Hanbde48202019-05-29 19:18:29 -0700286 return mBehindTint;
287 }
288
289 public int getBubbleTint() {
290 return mBubbleTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800291 }
292
293 public long getAnimationDuration() {
294 return mAnimationDuration;
295 }
296
297 public boolean getBlanksScreen() {
298 return mBlankScreen;
299 }
300
301 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
302 Trace.traceCounter(Trace.TRACE_TAG_APP,
303 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
304 (int) (alpha * 255));
305
306 Trace.traceCounter(Trace.TRACE_TAG_APP,
307 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
308 Color.alpha(tint));
309
310 scrim.setTint(tint);
311 scrim.setViewAlpha(alpha);
312 }
313
314 public boolean getAnimateChange() {
315 return mAnimateChange;
316 }
317
318 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
319 mAodFrontScrimAlpha = aodFrontScrimAlpha;
320 }
321
322 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
323 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
324 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700325
326 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
327 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
328 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700329
Lucas Dupin193677c2018-06-11 19:16:03 -0700330 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
331 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
332 }
333
Lucas Dupin38962d72018-03-14 12:41:39 -0700334 public boolean isLowPowerState() {
335 return false;
336 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700337
338 public void setHasBackdrop(boolean hasBackdrop) {
339 mHasBackdrop = hasBackdrop;
340 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700341
342 public void setWakeLockScreenSensorActive(boolean active) {
343 mWakeLockScreenSensorActive = active;
344 }
Selim Cinek84b2acc2019-07-07 00:40:38 -0700345
Selim Cinek72cd9a72019-08-09 17:19:57 -0700346 public void setKeyguardFadingAway(boolean fadingAway, long duration) {
347 mKeyguardFadingAway = fadingAway;
348 mKeyguardFadingAwayDuration = duration;
Selim Cinek84b2acc2019-07-07 00:40:38 -0700349 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800350}