Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.graphics.Color; |
| 20 | import android.os.Trace; |
| 21 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 22 | import com.android.systemui.doze.DozeLog; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 23 | import com.android.systemui.statusbar.ScrimView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 24 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Possible states of the ScrimController state machine. |
| 28 | */ |
| 29 | public enum ScrimState { |
| 30 | |
| 31 | /** |
| 32 | * Initial state. |
| 33 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 34 | UNINITIALIZED(-1), |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * On the lock screen. |
| 38 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 39 | KEYGUARD(0) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 40 | |
| 41 | @Override |
| 42 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 43 | mBlankScreen = false; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 44 | if (previousState == ScrimState.AOD) { |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 45 | 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 Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 51 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 52 | } else if (previousState == ScrimState.KEYGUARD) { |
| 53 | mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 54 | } else { |
| 55 | mAnimationDuration = ScrimController.ANIMATION_DURATION; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 56 | } |
| 57 | mCurrentBehindAlpha = mScrimBehindAlphaKeyguard; |
| 58 | mCurrentInFrontAlpha = 0; |
| 59 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 60 | }, |
| 61 | |
| 62 | /** |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 63 | * Showing password challenge on the keyguard. |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 64 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 65 | BOUNCER(1) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 66 | @Override |
| 67 | public void prepare(ScrimState previousState) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 68 | 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 Dupin | 05726cd | 2018-03-13 14:00:24 -0700 | [diff] [blame] | 76 | BOUNCER_SCRIMMED(2) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 77 | @Override |
| 78 | public void prepare(ScrimState previousState) { |
| 79 | mCurrentBehindAlpha = 0; |
| 80 | mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 81 | } |
| 82 | }, |
| 83 | |
| 84 | /** |
| 85 | * Changing screen brightness from quick settings. |
| 86 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 87 | BRIGHTNESS_MIRROR(3) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 88 | @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 Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 98 | AOD(4) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 99 | @Override |
| 100 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 101 | final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 102 | mBlankScreen = mDisplayRequiresBlanking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 103 | mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f; |
| 104 | mCurrentInFrontTint = Color.BLACK; |
| 105 | mCurrentBehindTint = Color.BLACK; |
Lucas Dupin | 4749f1b | 2018-04-04 15:09:06 -0700 | [diff] [blame] | 106 | mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG; |
Lucas Dupin | ea0116e | 2018-04-05 10:09:29 -0700 | [diff] [blame] | 107 | // DisplayPowerManager may blank the screen for us, |
| 108 | // in this case we just need to set our state. |
| 109 | mAnimateChange = mDozeParameters.shouldControlScreenOff(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 110 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 111 | |
| 112 | @Override |
Lucas Dupin | 3d36dd8 | 2019-01-02 14:38:35 -0800 | [diff] [blame] | 113 | public float getBehindAlpha() { |
Lucas Dupin | 9bee582 | 2018-07-09 14:32:53 -0700 | [diff] [blame] | 114 | return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f; |
| 115 | } |
| 116 | |
| 117 | @Override |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 118 | public boolean isLowPowerState() { |
| 119 | return true; |
| 120 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 121 | }, |
| 122 | |
| 123 | /** |
| 124 | * When phone wakes up because you received a notification. |
| 125 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 126 | PULSING(5) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 127 | @Override |
| 128 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 129 | mCurrentInFrontAlpha = 0f; |
| 130 | if (mPulseReason == DozeLog.PULSE_REASON_NOTIFICATION |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 131 | || mPulseReason == DozeLog.PULSE_REASON_DOCKING |
| 132 | || mPulseReason == DozeLog.PULSE_REASON_INTENT) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 133 | mCurrentBehindAlpha = previousState.getBehindAlpha(); |
| 134 | mCurrentBehindTint = Color.BLACK; |
| 135 | } else { |
| 136 | mCurrentBehindAlpha = mScrimBehindAlphaKeyguard; |
| 137 | mCurrentBehindTint = Color.TRANSPARENT; |
| 138 | } |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 139 | mBlankScreen = mDisplayRequiresBlanking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 140 | } |
| 141 | }, |
| 142 | |
| 143 | /** |
| 144 | * Unlocked on top of an app (launcher or any other activity.) |
| 145 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 146 | UNLOCKED(6) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 147 | @Override |
| 148 | public void prepare(ScrimState previousState) { |
| 149 | mCurrentBehindAlpha = 0; |
| 150 | mCurrentInFrontAlpha = 0; |
| 151 | mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 152 | mAnimateChange = !mLaunchingAffordanceWithPreview; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 153 | |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 154 | if (previousState == ScrimState.AOD) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 155 | // 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 Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 163 | mCurrentInFrontTint = Color.TRANSPARENT; |
| 164 | mCurrentBehindTint = Color.TRANSPARENT; |
| 165 | mBlankScreen = false; |
| 166 | } |
| 167 | } |
Mady Mellor | 0c33377 | 2018-11-06 18:05:54 -0800 | [diff] [blame] | 168 | }, |
| 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 Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 182 | }; |
| 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 Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 196 | boolean mDisplayRequiresBlanking; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 197 | boolean mWallpaperSupportsAmbientMode; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 198 | int mIndex; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 199 | boolean mHasBackdrop; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 200 | boolean mLaunchingAffordanceWithPreview; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 201 | int mPulseReason; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 202 | |
| 203 | ScrimState(int index) { |
| 204 | mIndex = index; |
| 205 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 206 | |
| 207 | public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) { |
| 208 | mScrimInFront = scrimInFront; |
| 209 | mScrimBehind = scrimBehind; |
| 210 | mDozeParameters = dozeParameters; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 211 | mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | public void prepare(ScrimState previousState) { |
| 215 | } |
| 216 | |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 217 | public int getIndex() { |
| 218 | return mIndex; |
| 219 | } |
| 220 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 221 | public float getFrontAlpha() { |
| 222 | return mCurrentInFrontAlpha; |
| 223 | } |
| 224 | |
Lucas Dupin | 3d36dd8 | 2019-01-02 14:38:35 -0800 | [diff] [blame] | 225 | public float getBehindAlpha() { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 226 | 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 Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 266 | public void setPulseReason(int pulseReason) { |
| 267 | mPulseReason = pulseReason; |
| 268 | } |
| 269 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 270 | public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) { |
| 271 | mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard; |
| 272 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 273 | |
| 274 | public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) { |
| 275 | mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode; |
| 276 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 277 | |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 278 | public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) { |
| 279 | mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview; |
| 280 | } |
| 281 | |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 282 | public boolean isLowPowerState() { |
| 283 | return false; |
| 284 | } |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 285 | |
| 286 | public void setHasBackdrop(boolean hasBackdrop) { |
| 287 | mHasBackdrop = hasBackdrop; |
| 288 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 289 | } |