• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 import com.android.systemui.statusbar.ScrimView;
23 import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
24 
25 /**
26  * Possible states of the ScrimController state machine.
27  */
28 public enum ScrimState {
29 
30     /**
31      * Initial state.
32      */
33     UNINITIALIZED(-1),
34 
35     /**
36      * On the lock screen.
37      */
38     KEYGUARD(0) {
39 
40         @Override
prepare(ScrimState previousState)41         public void prepare(ScrimState previousState) {
42             mBlankScreen = false;
43             if (previousState == ScrimState.AOD) {
44                 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;
50                 }
51             } else if (previousState == ScrimState.KEYGUARD) {
52                 mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
53             } else {
54                 mAnimationDuration = ScrimController.ANIMATION_DURATION;
55             }
56             mCurrentInFrontTint = Color.BLACK;
57             mCurrentBehindTint = Color.BLACK;
58             mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
59             mCurrentInFrontAlpha = 0;
60         }
61     },
62 
63     /**
64      * Showing password challenge on the keyguard.
65      */
66     BOUNCER(1) {
67         @Override
prepare(ScrimState previousState)68         public void prepare(ScrimState previousState) {
69             mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
70             mCurrentInFrontAlpha = 0f;
71         }
72     },
73 
74     /**
75      * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity.
76      */
77     BOUNCER_SCRIMMED(2) {
78         @Override
prepare(ScrimState previousState)79         public void prepare(ScrimState previousState) {
80             mCurrentBehindAlpha = 0;
81             mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
82         }
83     },
84 
85     /**
86      * Changing screen brightness from quick settings.
87      */
88     BRIGHTNESS_MIRROR(3) {
89         @Override
prepare(ScrimState previousState)90         public void prepare(ScrimState previousState) {
91             mCurrentBehindAlpha = 0;
92             mCurrentInFrontAlpha = 0;
93         }
94     },
95 
96     /**
97      * Always on display or screen off.
98      */
99     AOD(4) {
100         @Override
prepare(ScrimState previousState)101         public void prepare(ScrimState previousState) {
102             final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
103             mBlankScreen = mDisplayRequiresBlanking;
104             mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
105             mCurrentInFrontTint = Color.BLACK;
106             mCurrentBehindTint = Color.BLACK;
107             mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
108             // DisplayPowerManager may blank the screen for us,
109             // in this case we just need to set our state.
110             mAnimateChange = mDozeParameters.shouldControlScreenOff();
111         }
112 
113         @Override
getBehindAlpha()114         public float getBehindAlpha() {
115             return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
116         }
117 
118         @Override
isLowPowerState()119         public boolean isLowPowerState() {
120             return true;
121         }
122     },
123 
124     /**
125      * When phone wakes up because you received a notification.
126      */
127     PULSING(5) {
128         @Override
prepare(ScrimState previousState)129         public void prepare(ScrimState previousState) {
130             mCurrentInFrontAlpha = 0f;
131             mCurrentBehindTint = Color.BLACK;
132             mBlankScreen = mDisplayRequiresBlanking;
133         }
134 
135         @Override
getBehindAlpha()136         public float getBehindAlpha() {
137             return mWakeLockScreenSensorActive ? ScrimController.WAKE_SENSOR_SCRIM_ALPHA
138                     : AOD.getBehindAlpha();
139         }
140     },
141 
142     /**
143      * Unlocked on top of an app (launcher or any other activity.)
144      */
145     UNLOCKED(6) {
146         @Override
prepare(ScrimState previousState)147         public void prepare(ScrimState previousState) {
148             mCurrentBehindAlpha = 0;
149             mCurrentInFrontAlpha = 0;
150             mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION;
151             mAnimateChange = !mLaunchingAffordanceWithPreview;
152 
153             if (previousState == ScrimState.AOD) {
154                 // Fade from black to transparent when coming directly from AOD
155                 updateScrimColor(mScrimInFront, 1, Color.BLACK);
156                 updateScrimColor(mScrimBehind, 1, Color.BLACK);
157                 // Scrims should still be black at the end of the transition.
158                 mCurrentInFrontTint = Color.BLACK;
159                 mCurrentBehindTint = Color.BLACK;
160                 mBlankScreen = true;
161             } else {
162                 mCurrentInFrontTint = Color.TRANSPARENT;
163                 mCurrentBehindTint = Color.TRANSPARENT;
164                 mBlankScreen = false;
165             }
166         }
167     },
168 
169     /**
170      * Unlocked with a bubble expanded.
171      */
172     BUBBLE_EXPANDED(7) {
173         @Override
prepare(ScrimState previousState)174         public void prepare(ScrimState previousState) {
175             mCurrentInFrontTint = Color.TRANSPARENT;
176             mCurrentBehindTint = Color.TRANSPARENT;
177             mAnimationDuration = ScrimController.ANIMATION_DURATION;
178             mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
179             mBlankScreen = false;
180         }
181     };
182 
183     boolean mBlankScreen = false;
184     long mAnimationDuration = ScrimController.ANIMATION_DURATION;
185     int mCurrentInFrontTint = Color.TRANSPARENT;
186     int mCurrentBehindTint = Color.TRANSPARENT;
187     boolean mAnimateChange = true;
188     float mCurrentInFrontAlpha;
189     float mCurrentBehindAlpha;
190     float mAodFrontScrimAlpha;
191     float mScrimBehindAlphaKeyguard;
192     ScrimView mScrimInFront;
193     ScrimView mScrimBehind;
194     DozeParameters mDozeParameters;
195     boolean mDisplayRequiresBlanking;
196     boolean mWallpaperSupportsAmbientMode;
197     int mIndex;
198     boolean mHasBackdrop;
199     boolean mLaunchingAffordanceWithPreview;
200     boolean mWakeLockScreenSensorActive;
201 
ScrimState(int index)202     ScrimState(int index) {
203         mIndex = index;
204     }
205 
init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters)206     public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
207         mScrimInFront = scrimInFront;
208         mScrimBehind = scrimBehind;
209         mDozeParameters = dozeParameters;
210         mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
211     }
212 
prepare(ScrimState previousState)213     public void prepare(ScrimState previousState) {
214     }
215 
getIndex()216     public int getIndex() {
217         return mIndex;
218     }
219 
getFrontAlpha()220     public float getFrontAlpha() {
221         return mCurrentInFrontAlpha;
222     }
223 
getBehindAlpha()224     public float getBehindAlpha() {
225         return mCurrentBehindAlpha;
226     }
227 
getFrontTint()228     public int getFrontTint() {
229         return mCurrentInFrontTint;
230     }
231 
getBehindTint()232     public int getBehindTint() {
233         return mCurrentBehindTint;
234     }
235 
getAnimationDuration()236     public long getAnimationDuration() {
237         return mAnimationDuration;
238     }
239 
getBlanksScreen()240     public boolean getBlanksScreen() {
241         return mBlankScreen;
242     }
243 
updateScrimColor(ScrimView scrim, float alpha, int tint)244     public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
245         Trace.traceCounter(Trace.TRACE_TAG_APP,
246                 scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
247                 (int) (alpha * 255));
248 
249         Trace.traceCounter(Trace.TRACE_TAG_APP,
250                 scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
251                 Color.alpha(tint));
252 
253         scrim.setTint(tint);
254         scrim.setViewAlpha(alpha);
255     }
256 
getAnimateChange()257     public boolean getAnimateChange() {
258         return mAnimateChange;
259     }
260 
setAodFrontScrimAlpha(float aodFrontScrimAlpha)261     public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) {
262         mAodFrontScrimAlpha = aodFrontScrimAlpha;
263     }
264 
setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard)265     public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
266         mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
267     }
268 
setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode)269     public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
270         mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
271     }
272 
setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview)273     public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
274         mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
275     }
276 
isLowPowerState()277     public boolean isLowPowerState() {
278         return false;
279     }
280 
setHasBackdrop(boolean hasBackdrop)281     public void setHasBackdrop(boolean hasBackdrop) {
282         mHasBackdrop = hasBackdrop;
283     }
284 
setWakeLockScreenSensorActive(boolean active)285     public void setWakeLockScreenSensorActive(boolean active) {
286         mWakeLockScreenSensorActive = active;
287     }
288 }