blob: c23fd0a3d5d635f766628286a331b8ca24dc83ec [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
Jerry Chang50c5da42019-10-16 17:21:07 +080022import com.android.systemui.dock.DockManager;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080023import com.android.systemui.statusbar.ScrimView;
Rohan Shah20790b82018-07-02 17:21:04 -070024import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080025
26/**
27 * Possible states of the ScrimController state machine.
28 */
29public enum ScrimState {
30
31 /**
32 * Initial state.
33 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -070034 UNINITIALIZED,
35
36 /**
37 * When turned off by sensors (prox, presence.)
38 */
39 OFF {
40 @Override
41 public void prepare(ScrimState previousState) {
42 mFrontTint = Color.BLACK;
Lucas Dupin36ec73c2019-10-18 13:39:04 -070043 mBehindTint = Color.BLACK;
Lucas Dupinedbe45b2019-10-14 15:43:03 -070044 mBubbleTint = previousState.mBubbleTint;
45
46 mFrontAlpha = 1f;
Lucas Dupin36ec73c2019-10-18 13:39:04 -070047 mBehindAlpha = 1f;
Lucas Dupinedbe45b2019-10-14 15:43:03 -070048 mBubbleAlpha = previousState.mBubbleAlpha;
49
50 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
51 }
Lucas Dupin36ec73c2019-10-18 13:39:04 -070052
53 @Override
54 public boolean isLowPowerState() {
55 return true;
56 }
Lucas Dupinedbe45b2019-10-14 15:43:03 -070057 },
Lucas Dupin9e3fa102017-11-08 17:16:55 -080058
59 /**
60 * On the lock screen.
61 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -070062 KEYGUARD {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080063 @Override
64 public void prepare(ScrimState previousState) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080065 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080066 if (previousState == ScrimState.AOD) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080067 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
68 if (mDisplayRequiresBlanking) {
69 // DisplayPowerManager will blank the screen, we'll just
70 // set our scrim to black in this frame to avoid flickering and
71 // fade it out afterwards.
72 mBlankScreen = true;
Lucas Dupin43d0d732017-11-16 11:23:49 -080073 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070074 } else if (previousState == ScrimState.KEYGUARD) {
75 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
Lucas Dupin43d0d732017-11-16 11:23:49 -080076 } else {
77 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080078 }
Lyn Hanbde48202019-05-29 19:18:29 -070079 mFrontTint = Color.BLACK;
80 mBehindTint = Color.BLACK;
81 mBubbleTint = Color.TRANSPARENT;
82
83 mFrontAlpha = 0;
84 mBehindAlpha = mScrimBehindAlphaKeyguard;
85 mBubbleAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080086 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070087 },
88
89 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080090 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080091 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -070092 BOUNCER {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080093 @Override
94 public void prepare(ScrimState previousState) {
Lucas Dupin43d01242020-02-03 11:58:33 -080095 mBehindAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Lyn Hanbde48202019-05-29 19:18:29 -070096 mFrontAlpha = 0f;
97 mBubbleAlpha = 0f;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080098 }
99 },
100
101 /**
102 * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
103 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700104 BOUNCER_SCRIMMED {
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800105 @Override
106 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700107 mBehindAlpha = 0;
108 mBubbleAlpha = 0f;
Lucas Dupin43d01242020-02-03 11:58:33 -0800109 mFrontAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800110 }
111 },
112
113 /**
114 * Changing screen brightness from quick settings.
115 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700116 BRIGHTNESS_MIRROR {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800117 @Override
118 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700119 mBehindAlpha = 0;
120 mFrontAlpha = 0;
121 mBubbleAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800122 }
123 },
124
125 /**
126 * Always on display or screen off.
127 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700128 AOD {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800129 @Override
130 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800131 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Jerry Chang50c5da42019-10-16 17:21:07 +0800132 final boolean isDocked = mDockManager.isDocked();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800133 mBlankScreen = mDisplayRequiresBlanking;
Lyn Hanbde48202019-05-29 19:18:29 -0700134
135 mFrontTint = Color.BLACK;
Jerry Chang50c5da42019-10-16 17:21:07 +0800136 mFrontAlpha = (alwaysOnEnabled || isDocked) ? mAodFrontScrimAlpha : 1f;
Lyn Hanbde48202019-05-29 19:18:29 -0700137
138 mBehindTint = Color.BLACK;
139 mBehindAlpha = ScrimController.TRANSPARENT;
140
141 mBubbleTint = Color.TRANSPARENT;
142 mBubbleAlpha = ScrimController.TRANSPARENT;
143
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700144 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700145 // DisplayPowerManager may blank the screen for us,
146 // in this case we just need to set our state.
147 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800148 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700149
150 @Override
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800151 public float getBehindAlpha() {
Lucas Dupin9bee5822018-07-09 14:32:53 -0700152 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
153 }
154
155 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700156 public boolean isLowPowerState() {
157 return true;
158 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800159 },
160
161 /**
162 * When phone wakes up because you received a notification.
163 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700164 PULSING {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800165 @Override
166 public void prepare(ScrimState previousState) {
Chris.CC Leed424e202019-09-16 12:17:19 +0800167 mFrontAlpha = mAodFrontScrimAlpha;
Lyn Hanbde48202019-05-29 19:18:29 -0700168 mBubbleAlpha = 0f;
169 mBehindTint = Color.BLACK;
Mady Mellor4035ef52019-07-25 11:10:02 -0700170 mFrontTint = Color.BLACK;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800171 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupina7eacf92019-07-24 12:40:34 -0700172 mAnimationDuration = mWakeLockScreenSensorActive
173 ? ScrimController.ANIMATION_DURATION_LONG : ScrimController.ANIMATION_DURATION;
Lucas Dupinfea9b862019-08-08 16:58:50 -0700174
175 // Wake sensor will show the wallpaper, let's fade from black. Otherwise it will
176 // feel like the screen is flashing if the wallpaper is light.
177 if (mWakeLockScreenSensorActive && previousState == AOD) {
178 updateScrimColor(mScrimBehind, 1f /* alpha */, Color.BLACK);
179 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800180 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700181
182 @Override
183 public float getBehindAlpha() {
184 return mWakeLockScreenSensorActive ? ScrimController.WAKE_SENSOR_SCRIM_ALPHA
185 : AOD.getBehindAlpha();
186 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800187 },
188
189 /**
190 * Unlocked on top of an app (launcher or any other activity.)
191 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700192 UNLOCKED {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800193 @Override
194 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700195 // State that UI will sync to.
196 mBehindAlpha = 0;
197 mFrontAlpha = 0;
198 mBubbleAlpha = 0;
199
Selim Cinek72cd9a72019-08-09 17:19:57 -0700200 mAnimationDuration = mKeyguardFadingAway
201 ? mKeyguardFadingAwayDuration
Selim Cinek84b2acc2019-07-07 00:40:38 -0700202 : StatusBar.FADE_KEYGUARD_DURATION;
Mady Mellor06792002019-08-13 14:33:24 -0700203
Lucas Dupin193677c2018-06-11 19:16:03 -0700204 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800205
Lyn Hanbde48202019-05-29 19:18:29 -0700206 mFrontTint = Color.TRANSPARENT;
207 mBehindTint = Color.TRANSPARENT;
208 mBubbleTint = Color.TRANSPARENT;
209 mBlankScreen = false;
210
Lucas Dupind35502f2018-06-27 13:35:52 -0700211 if (previousState == ScrimState.AOD) {
Lyn Hanbde48202019-05-29 19:18:29 -0700212 // Set all scrims black, before they fade transparent.
213 updateScrimColor(mScrimInFront, 1f /* alpha */, Color.BLACK /* tint */);
214 updateScrimColor(mScrimBehind, 1f /* alpha */, Color.BLACK /* tint */);
215 updateScrimColor(mScrimForBubble, 1f /* alpha */, Color.BLACK /* tint */);
216
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800217 // Scrims should still be black at the end of the transition.
Lyn Hanbde48202019-05-29 19:18:29 -0700218 mFrontTint = Color.BLACK;
219 mBehindTint = Color.BLACK;
220 mBubbleTint = Color.BLACK;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800221 mBlankScreen = true;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800222 }
223 }
Mady Mellor0c333772018-11-06 18:05:54 -0800224 },
225
226 /**
227 * Unlocked with a bubble expanded.
228 */
Lucas Dupinedbe45b2019-10-14 15:43:03 -0700229 BUBBLE_EXPANDED {
Mady Mellor0c333772018-11-06 18:05:54 -0800230 @Override
231 public void prepare(ScrimState previousState) {
Lyn Hanbde48202019-05-29 19:18:29 -0700232 mFrontTint = Color.TRANSPARENT;
233 mBehindTint = Color.TRANSPARENT;
234 mBubbleTint = Color.TRANSPARENT;
235
236 mFrontAlpha = ScrimController.TRANSPARENT;
Lucas Dupin43d01242020-02-03 11:58:33 -0800237 mBehindAlpha = ScrimController.BUSY_SCRIM_ALPHA;
238 mBubbleAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Lyn Hanbde48202019-05-29 19:18:29 -0700239
Mady Mellor0c333772018-11-06 18:05:54 -0800240 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Mady Mellor0c333772018-11-06 18:05:54 -0800241 mBlankScreen = false;
242 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800243 };
244
245 boolean mBlankScreen = false;
246 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lyn Hanbde48202019-05-29 19:18:29 -0700247 int mFrontTint = Color.TRANSPARENT;
248 int mBehindTint = Color.TRANSPARENT;
249 int mBubbleTint = Color.TRANSPARENT;
250
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800251 boolean mAnimateChange = true;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800252 float mAodFrontScrimAlpha;
Lyn Hanbde48202019-05-29 19:18:29 -0700253 float mFrontAlpha;
254 float mBehindAlpha;
255 float mBubbleAlpha;
256
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800257 float mScrimBehindAlphaKeyguard;
258 ScrimView mScrimInFront;
259 ScrimView mScrimBehind;
Lyn Hanbde48202019-05-29 19:18:29 -0700260 ScrimView mScrimForBubble;
261
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800262 DozeParameters mDozeParameters;
Jerry Chang50c5da42019-10-16 17:21:07 +0800263 DockManager mDockManager;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800264 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700265 boolean mWallpaperSupportsAmbientMode;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700266 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700267 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700268 boolean mWakeLockScreenSensorActive;
Selim Cinek72cd9a72019-08-09 17:19:57 -0700269 boolean mKeyguardFadingAway;
270 long mKeyguardFadingAwayDuration;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800271
Lyn Hanbde48202019-05-29 19:18:29 -0700272 public void init(ScrimView scrimInFront, ScrimView scrimBehind, ScrimView scrimForBubble,
Jerry Chang50c5da42019-10-16 17:21:07 +0800273 DozeParameters dozeParameters, DockManager dockManager) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800274 mScrimInFront = scrimInFront;
275 mScrimBehind = scrimBehind;
Lyn Hanbde48202019-05-29 19:18:29 -0700276 mScrimForBubble = scrimForBubble;
277
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800278 mDozeParameters = dozeParameters;
Jerry Chang50c5da42019-10-16 17:21:07 +0800279 mDockManager = dockManager;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800280 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800281 }
282
Lyn Hanbde48202019-05-29 19:18:29 -0700283 /** Prepare state for transition. */
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800284 public void prepare(ScrimState previousState) {
285 }
286
287 public float getFrontAlpha() {
Lyn Hanbde48202019-05-29 19:18:29 -0700288 return mFrontAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800289 }
290
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800291 public float getBehindAlpha() {
Lyn Hanbde48202019-05-29 19:18:29 -0700292 return mBehindAlpha;
293 }
294
295 public float getBubbleAlpha() {
296 return mBubbleAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800297 }
298
299 public int getFrontTint() {
Lyn Hanbde48202019-05-29 19:18:29 -0700300 return mFrontTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800301 }
302
303 public int getBehindTint() {
Lyn Hanbde48202019-05-29 19:18:29 -0700304 return mBehindTint;
305 }
306
307 public int getBubbleTint() {
308 return mBubbleTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800309 }
310
311 public long getAnimationDuration() {
312 return mAnimationDuration;
313 }
314
315 public boolean getBlanksScreen() {
316 return mBlankScreen;
317 }
318
319 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
320 Trace.traceCounter(Trace.TRACE_TAG_APP,
321 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
322 (int) (alpha * 255));
323
324 Trace.traceCounter(Trace.TRACE_TAG_APP,
325 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
326 Color.alpha(tint));
327
328 scrim.setTint(tint);
329 scrim.setViewAlpha(alpha);
330 }
331
332 public boolean getAnimateChange() {
333 return mAnimateChange;
334 }
335
336 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
337 mAodFrontScrimAlpha = aodFrontScrimAlpha;
338 }
339
340 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
341 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
342 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700343
344 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
345 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
346 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700347
Lucas Dupin193677c2018-06-11 19:16:03 -0700348 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
349 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
350 }
351
Lucas Dupin38962d72018-03-14 12:41:39 -0700352 public boolean isLowPowerState() {
353 return false;
354 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700355
356 public void setHasBackdrop(boolean hasBackdrop) {
357 mHasBackdrop = hasBackdrop;
358 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700359
360 public void setWakeLockScreenSensorActive(boolean active) {
361 mWakeLockScreenSensorActive = active;
362 }
Selim Cinek84b2acc2019-07-07 00:40:38 -0700363
Selim Cinek72cd9a72019-08-09 17:19:57 -0700364 public void setKeyguardFadingAway(boolean fadingAway, long duration) {
365 mKeyguardFadingAway = fadingAway;
366 mKeyguardFadingAwayDuration = duration;
Selim Cinek84b2acc2019-07-07 00:40:38 -0700367 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800368}