blob: 5fa861c8a2ac2e498e9a67ba7835c942fc583a60 [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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -070039
Lucas Dupin9e3fa102017-11-08 17:16:55 -080040 @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 }
Selim Cinekb4ba5c92019-10-25 17:37:00 -070056 mCurrentInFrontTint = Color.BLACK;
57 mCurrentBehindTint = Color.BLACK;
58 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
59 mCurrentInFrontAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080060 }
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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -070069 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
70 mCurrentInFrontAlpha = 0f;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080071 }
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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -070080 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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -070091 mCurrentBehindAlpha = 0;
92 mCurrentInFrontAlpha = 0;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080093 }
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;
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700104 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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700130 mCurrentInFrontAlpha = mAodFrontScrimAlpha;
131 mCurrentBehindTint = Color.BLACK;
132 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) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700157 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;
Mady Mellor06792002019-08-13 14:33:24 -0700162
Lucas Dupin193677c2018-06-11 19:16:03 -0700163 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800164
Lucas Dupind35502f2018-06-27 13:35:52 -0700165 if (previousState == ScrimState.AOD) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700166 // Fade from black to transparent when coming directly from AOD
167 updateScrimColor(mScrimInFront, 1, Color.BLACK);
168 updateScrimColor(mScrimBehind, 1, Color.BLACK);
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800169 // Scrims should still be black at the end of the transition.
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700170 mCurrentInFrontTint = Color.BLACK;
171 mCurrentBehindTint = Color.BLACK;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800172 mBlankScreen = true;
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700173 } else {
174 mCurrentInFrontTint = Color.TRANSPARENT;
175 mCurrentBehindTint = Color.TRANSPARENT;
176 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800177 }
178 }
Mady Mellor0c333772018-11-06 18:05:54 -0800179 },
180
181 /**
182 * Unlocked with a bubble expanded.
183 */
184 BUBBLE_EXPANDED(7) {
185 @Override
186 public void prepare(ScrimState previousState) {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700187 mCurrentInFrontTint = Color.TRANSPARENT;
188 mCurrentBehindTint = Color.TRANSPARENT;
Mady Mellor0c333772018-11-06 18:05:54 -0800189 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700190 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Mady Mellor0c333772018-11-06 18:05:54 -0800191 mBlankScreen = false;
192 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800193 };
194
195 boolean mBlankScreen = false;
196 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700197 int mCurrentInFrontTint = Color.TRANSPARENT;
198 int mCurrentBehindTint = Color.TRANSPARENT;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800199 boolean mAnimateChange = true;
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700200 float mCurrentInFrontAlpha;
201 float mCurrentBehindAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800202 float mAodFrontScrimAlpha;
203 float mScrimBehindAlphaKeyguard;
204 ScrimView mScrimInFront;
205 ScrimView mScrimBehind;
206 DozeParameters mDozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800207 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700208 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800209 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700210 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700211 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700212 boolean mWakeLockScreenSensorActive;
Selim Cinek72cd9a72019-08-09 17:19:57 -0700213 boolean mKeyguardFadingAway;
214 long mKeyguardFadingAwayDuration;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800215
216 ScrimState(int index) {
217 mIndex = index;
218 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800219
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700220 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800221 mScrimInFront = scrimInFront;
222 mScrimBehind = scrimBehind;
223 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800224 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800225 }
226
227 public void prepare(ScrimState previousState) {
228 }
229
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800230 public int getIndex() {
231 return mIndex;
232 }
233
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800234 public float getFrontAlpha() {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700235 return mCurrentInFrontAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800236 }
237
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800238 public float getBehindAlpha() {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700239 return mCurrentBehindAlpha;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800240 }
241
242 public int getFrontTint() {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700243 return mCurrentInFrontTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800244 }
245
246 public int getBehindTint() {
Selim Cinekb4ba5c92019-10-25 17:37:00 -0700247 return mCurrentBehindTint;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800248 }
249
250 public long getAnimationDuration() {
251 return mAnimationDuration;
252 }
253
254 public boolean getBlanksScreen() {
255 return mBlankScreen;
256 }
257
258 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
259 Trace.traceCounter(Trace.TRACE_TAG_APP,
260 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
261 (int) (alpha * 255));
262
263 Trace.traceCounter(Trace.TRACE_TAG_APP,
264 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
265 Color.alpha(tint));
266
267 scrim.setTint(tint);
268 scrim.setViewAlpha(alpha);
269 }
270
271 public boolean getAnimateChange() {
272 return mAnimateChange;
273 }
274
275 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
276 mAodFrontScrimAlpha = aodFrontScrimAlpha;
277 }
278
279 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
280 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
281 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700282
283 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
284 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
285 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700286
Lucas Dupin193677c2018-06-11 19:16:03 -0700287 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
288 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
289 }
290
Lucas Dupin38962d72018-03-14 12:41:39 -0700291 public boolean isLowPowerState() {
292 return false;
293 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700294
295 public void setHasBackdrop(boolean hasBackdrop) {
296 mHasBackdrop = hasBackdrop;
297 }
Lucas Dupin5f00fa52019-03-27 22:46:53 -0700298
299 public void setWakeLockScreenSensorActive(boolean active) {
300 mWakeLockScreenSensorActive = active;
301 }
Selim Cinek84b2acc2019-07-07 00:40:38 -0700302
Selim Cinek72cd9a72019-08-09 17:19:57 -0700303 public void setKeyguardFadingAway(boolean fadingAway, long duration) {
304 mKeyguardFadingAway = fadingAway;
305 mKeyguardFadingAwayDuration = duration;
Selim Cinek84b2acc2019-07-07 00:40:38 -0700306 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800307}