blob: bbeebd654b4ef3da5eaca359ec871448261e6397 [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
Lucas Dupin00be88f2019-01-03 17:50:52 -080022import com.android.systemui.doze.DozeLog;
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 Dupin5866aaf2018-02-02 14:45:31 -080034 UNINITIALIZED(-1),
Lucas Dupin9e3fa102017-11-08 17:16:55 -080035
36 /**
37 * On the lock screen.
38 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080039 KEYGUARD(0) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080040
41 @Override
42 public void prepare(ScrimState previousState) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080043 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080044 if (previousState == ScrimState.AOD) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080045 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
46 if (mDisplayRequiresBlanking) {
47 // DisplayPowerManager will blank the screen, we'll just
48 // set our scrim to black in this frame to avoid flickering and
49 // fade it out afterwards.
50 mBlankScreen = true;
Lucas Dupin43d0d732017-11-16 11:23:49 -080051 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070052 } else if (previousState == ScrimState.KEYGUARD) {
53 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
Lucas Dupin43d0d732017-11-16 11:23:49 -080054 } else {
55 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080056 }
57 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
58 mCurrentInFrontAlpha = 0;
59 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070060 },
61
62 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080063 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080064 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080065 BOUNCER(1) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080066 @Override
67 public void prepare(ScrimState previousState) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080068 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
69 mCurrentInFrontAlpha = 0f;
70 }
71 },
72
73 /**
74 * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
75 */
Lucas Dupin05726cd2018-03-13 14:00:24 -070076 BOUNCER_SCRIMMED(2) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080077 @Override
78 public void prepare(ScrimState previousState) {
79 mCurrentBehindAlpha = 0;
80 mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080081 }
82 },
83
84 /**
85 * Changing screen brightness from quick settings.
86 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080087 BRIGHTNESS_MIRROR(3) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080088 @Override
89 public void prepare(ScrimState previousState) {
90 mCurrentBehindAlpha = 0;
91 mCurrentInFrontAlpha = 0;
92 }
93 },
94
95 /**
96 * Always on display or screen off.
97 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080098 AOD(4) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080099 @Override
100 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800101 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800102 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800103 mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
104 mCurrentInFrontTint = Color.BLACK;
105 mCurrentBehindTint = Color.BLACK;
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700106 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700107 // DisplayPowerManager may blank the screen for us,
108 // in this case we just need to set our state.
109 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800110 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700111
112 @Override
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800113 public float getBehindAlpha() {
Lucas Dupin9bee5822018-07-09 14:32:53 -0700114 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
115 }
116
117 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700118 public boolean isLowPowerState() {
119 return true;
120 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800121 },
122
123 /**
124 * When phone wakes up because you received a notification.
125 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800126 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800127 @Override
128 public void prepare(ScrimState previousState) {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800129 mCurrentInFrontAlpha = 0f;
130 if (mPulseReason == DozeLog.PULSE_REASON_NOTIFICATION
Lucas Dupin023d7272019-01-28 14:31:40 -0800131 || mPulseReason == DozeLog.PULSE_REASON_DOCKING
132 || mPulseReason == DozeLog.PULSE_REASON_INTENT) {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800133 mCurrentBehindAlpha = previousState.getBehindAlpha();
134 mCurrentBehindTint = Color.BLACK;
135 } else {
136 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
137 mCurrentBehindTint = Color.TRANSPARENT;
138 }
Lucas Dupin43d0d732017-11-16 11:23:49 -0800139 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800140 }
141 },
142
143 /**
144 * Unlocked on top of an app (launcher or any other activity.)
145 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800146 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800147 @Override
148 public void prepare(ScrimState previousState) {
149 mCurrentBehindAlpha = 0;
150 mCurrentInFrontAlpha = 0;
151 mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION;
Lucas Dupin193677c2018-06-11 19:16:03 -0700152 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800153
Lucas Dupind35502f2018-06-27 13:35:52 -0700154 if (previousState == ScrimState.AOD) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800155 // Fade from black to transparent when coming directly from AOD
156 updateScrimColor(mScrimInFront, 1, Color.BLACK);
157 updateScrimColor(mScrimBehind, 1, Color.BLACK);
158 // Scrims should still be black at the end of the transition.
159 mCurrentInFrontTint = Color.BLACK;
160 mCurrentBehindTint = Color.BLACK;
161 mBlankScreen = true;
162 } else {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800163 mCurrentInFrontTint = Color.TRANSPARENT;
164 mCurrentBehindTint = Color.TRANSPARENT;
165 mBlankScreen = false;
166 }
167 }
Mady Mellor0c333772018-11-06 18:05:54 -0800168 },
169
170 /**
171 * Unlocked with a bubble expanded.
172 */
173 BUBBLE_EXPANDED(7) {
174 @Override
175 public void prepare(ScrimState previousState) {
176 mCurrentInFrontTint = Color.TRANSPARENT;
177 mCurrentBehindTint = Color.TRANSPARENT;
178 mAnimationDuration = ScrimController.ANIMATION_DURATION;
179 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
180 mBlankScreen = false;
181 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800182 };
183
184 boolean mBlankScreen = false;
185 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
186 int mCurrentInFrontTint = Color.TRANSPARENT;
187 int mCurrentBehindTint = Color.TRANSPARENT;
188 boolean mAnimateChange = true;
189 float mCurrentInFrontAlpha;
190 float mCurrentBehindAlpha;
191 float mAodFrontScrimAlpha;
192 float mScrimBehindAlphaKeyguard;
193 ScrimView mScrimInFront;
194 ScrimView mScrimBehind;
195 DozeParameters mDozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800196 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700197 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800198 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700199 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700200 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin00be88f2019-01-03 17:50:52 -0800201 int mPulseReason;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800202
203 ScrimState(int index) {
204 mIndex = index;
205 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800206
207 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
208 mScrimInFront = scrimInFront;
209 mScrimBehind = scrimBehind;
210 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800211 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800212 }
213
214 public void prepare(ScrimState previousState) {
215 }
216
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800217 public int getIndex() {
218 return mIndex;
219 }
220
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800221 public float getFrontAlpha() {
222 return mCurrentInFrontAlpha;
223 }
224
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800225 public float getBehindAlpha() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800226 return mCurrentBehindAlpha;
227 }
228
229 public int getFrontTint() {
230 return mCurrentInFrontTint;
231 }
232
233 public int getBehindTint() {
234 return mCurrentBehindTint;
235 }
236
237 public long getAnimationDuration() {
238 return mAnimationDuration;
239 }
240
241 public boolean getBlanksScreen() {
242 return mBlankScreen;
243 }
244
245 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
246 Trace.traceCounter(Trace.TRACE_TAG_APP,
247 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
248 (int) (alpha * 255));
249
250 Trace.traceCounter(Trace.TRACE_TAG_APP,
251 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
252 Color.alpha(tint));
253
254 scrim.setTint(tint);
255 scrim.setViewAlpha(alpha);
256 }
257
258 public boolean getAnimateChange() {
259 return mAnimateChange;
260 }
261
262 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
263 mAodFrontScrimAlpha = aodFrontScrimAlpha;
264 }
265
Lucas Dupin00be88f2019-01-03 17:50:52 -0800266 public void setPulseReason(int pulseReason) {
267 mPulseReason = pulseReason;
268 }
269
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800270 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
271 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
272 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700273
274 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
275 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
276 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700277
Lucas Dupin193677c2018-06-11 19:16:03 -0700278 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
279 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
280 }
281
Lucas Dupin38962d72018-03-14 12:41:39 -0700282 public boolean isLowPowerState() {
283 return false;
284 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700285
286 public void setHasBackdrop(boolean hasBackdrop) {
287 mHasBackdrop = hasBackdrop;
288 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800289}