blob: ccf5e4eb0ac4af32d083eb14324c43c98486107e [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 }
Lucas Dupin1113fdf2019-03-07 17:32:00 -080057 mCurrentInFrontTint = Color.BLACK;
58 mCurrentBehindTint = Color.BLACK;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080059 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
60 mCurrentInFrontAlpha = 0;
61 }
Lucas Dupin55c6e802018-09-27 18:07:36 -070062 },
63
64 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080065 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080066 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080067 BOUNCER(1) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080068 @Override
69 public void prepare(ScrimState previousState) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080070 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
71 mCurrentInFrontAlpha = 0f;
72 }
73 },
74
75 /**
76 * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
77 */
Lucas Dupin05726cd2018-03-13 14:00:24 -070078 BOUNCER_SCRIMMED(2) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080079 @Override
80 public void prepare(ScrimState previousState) {
81 mCurrentBehindAlpha = 0;
82 mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080083 }
84 },
85
86 /**
87 * Changing screen brightness from quick settings.
88 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080089 BRIGHTNESS_MIRROR(3) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080090 @Override
91 public void prepare(ScrimState previousState) {
92 mCurrentBehindAlpha = 0;
93 mCurrentInFrontAlpha = 0;
94 }
95 },
96
97 /**
98 * Always on display or screen off.
99 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800100 AOD(4) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800101 @Override
102 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800103 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800104 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800105 mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
106 mCurrentInFrontTint = Color.BLACK;
107 mCurrentBehindTint = Color.BLACK;
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700108 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700109 // DisplayPowerManager may blank the screen for us,
110 // in this case we just need to set our state.
111 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800112 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700113
114 @Override
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800115 public float getBehindAlpha() {
Lucas Dupin9bee5822018-07-09 14:32:53 -0700116 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
117 }
118
119 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700120 public boolean isLowPowerState() {
121 return true;
122 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800123 },
124
125 /**
126 * When phone wakes up because you received a notification.
127 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800128 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800129 @Override
130 public void prepare(ScrimState previousState) {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800131 mCurrentInFrontAlpha = 0f;
132 if (mPulseReason == DozeLog.PULSE_REASON_NOTIFICATION
Lucas Dupin023d7272019-01-28 14:31:40 -0800133 || mPulseReason == DozeLog.PULSE_REASON_DOCKING
134 || mPulseReason == DozeLog.PULSE_REASON_INTENT) {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800135 mCurrentBehindAlpha = previousState.getBehindAlpha();
136 mCurrentBehindTint = Color.BLACK;
137 } else {
138 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
139 mCurrentBehindTint = Color.TRANSPARENT;
140 }
Lucas Dupin43d0d732017-11-16 11:23:49 -0800141 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800142 }
143 },
144
145 /**
146 * Unlocked on top of an app (launcher or any other activity.)
147 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800148 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800149 @Override
150 public void prepare(ScrimState previousState) {
151 mCurrentBehindAlpha = 0;
152 mCurrentInFrontAlpha = 0;
153 mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION;
Lucas Dupin193677c2018-06-11 19:16:03 -0700154 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800155
Lucas Dupind35502f2018-06-27 13:35:52 -0700156 if (previousState == ScrimState.AOD) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800157 // Fade from black to transparent when coming directly from AOD
158 updateScrimColor(mScrimInFront, 1, Color.BLACK);
159 updateScrimColor(mScrimBehind, 1, Color.BLACK);
160 // Scrims should still be black at the end of the transition.
161 mCurrentInFrontTint = Color.BLACK;
162 mCurrentBehindTint = Color.BLACK;
163 mBlankScreen = true;
164 } else {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800165 mCurrentInFrontTint = Color.TRANSPARENT;
166 mCurrentBehindTint = Color.TRANSPARENT;
167 mBlankScreen = false;
168 }
169 }
Mady Mellor0c333772018-11-06 18:05:54 -0800170 },
171
172 /**
173 * Unlocked with a bubble expanded.
174 */
175 BUBBLE_EXPANDED(7) {
176 @Override
177 public void prepare(ScrimState previousState) {
178 mCurrentInFrontTint = Color.TRANSPARENT;
179 mCurrentBehindTint = Color.TRANSPARENT;
180 mAnimationDuration = ScrimController.ANIMATION_DURATION;
181 mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
182 mBlankScreen = false;
183 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800184 };
185
186 boolean mBlankScreen = false;
187 long mAnimationDuration = ScrimController.ANIMATION_DURATION;
188 int mCurrentInFrontTint = Color.TRANSPARENT;
189 int mCurrentBehindTint = Color.TRANSPARENT;
190 boolean mAnimateChange = true;
191 float mCurrentInFrontAlpha;
192 float mCurrentBehindAlpha;
193 float mAodFrontScrimAlpha;
194 float mScrimBehindAlphaKeyguard;
195 ScrimView mScrimInFront;
196 ScrimView mScrimBehind;
197 DozeParameters mDozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800198 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700199 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800200 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700201 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700202 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin00be88f2019-01-03 17:50:52 -0800203 int mPulseReason;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800204
205 ScrimState(int index) {
206 mIndex = index;
207 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800208
209 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
210 mScrimInFront = scrimInFront;
211 mScrimBehind = scrimBehind;
212 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800213 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800214 }
215
216 public void prepare(ScrimState previousState) {
217 }
218
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800219 public int getIndex() {
220 return mIndex;
221 }
222
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800223 public float getFrontAlpha() {
224 return mCurrentInFrontAlpha;
225 }
226
Lucas Dupin3d36dd82019-01-02 14:38:35 -0800227 public float getBehindAlpha() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800228 return mCurrentBehindAlpha;
229 }
230
231 public int getFrontTint() {
232 return mCurrentInFrontTint;
233 }
234
235 public int getBehindTint() {
236 return mCurrentBehindTint;
237 }
238
239 public long getAnimationDuration() {
240 return mAnimationDuration;
241 }
242
243 public boolean getBlanksScreen() {
244 return mBlankScreen;
245 }
246
247 public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
248 Trace.traceCounter(Trace.TRACE_TAG_APP,
249 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
250 (int) (alpha * 255));
251
252 Trace.traceCounter(Trace.TRACE_TAG_APP,
253 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
254 Color.alpha(tint));
255
256 scrim.setTint(tint);
257 scrim.setViewAlpha(alpha);
258 }
259
260 public boolean getAnimateChange() {
261 return mAnimateChange;
262 }
263
264 public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
265 mAodFrontScrimAlpha = aodFrontScrimAlpha;
266 }
267
Lucas Dupin00be88f2019-01-03 17:50:52 -0800268 public void setPulseReason(int pulseReason) {
269 mPulseReason = pulseReason;
270 }
271
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800272 public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
273 mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
274 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700275
276 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
277 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
278 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700279
Lucas Dupin193677c2018-06-11 19:16:03 -0700280 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
281 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
282 }
283
Lucas Dupin38962d72018-03-14 12:41:39 -0700284 public boolean isLowPowerState() {
285 return false;
286 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700287
288 public void setHasBackdrop(boolean hasBackdrop) {
289 mHasBackdrop = hasBackdrop;
290 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800291}