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