blob: a5716f2c2c09ec6a74d6f6a435579d807b74e172 [file] [log] [blame]
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001/*
2 * Copyright (C) 2014 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
Adrian Roos7b54b072018-03-08 12:52:22 +010019import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
20
Eliot Courtneye77edea2017-11-15 14:25:21 +090021import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
22
Sudheer Shankadc589ac2016-11-10 15:30:17 -080023import android.app.ActivityManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020024import android.app.IActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010025import android.content.Context;
26import android.content.pm.ActivityInfo;
27import android.content.res.Resources;
28import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080029import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020030import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010031import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020032import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010033import android.view.Gravity;
34import android.view.View;
35import android.view.ViewGroup;
36import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020037import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010038
39import com.android.keyguard.R;
Jason Monk421a9412017-02-06 09:15:21 -080040import com.android.systemui.Dumpable;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010041import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roosd28ccd72016-01-06 15:23:14 +010042import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020043import com.android.systemui.statusbar.StatusBarState;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010044
Selim Cinek7025f262015-07-13 16:22:48 -070045import java.io.FileDescriptor;
46import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020047import java.lang.reflect.Field;
48
Jorim Jaggi5cf17872014-03-26 18:31:48 +010049/**
50 * Encapsulates all logic for the status bar window state management.
51 */
Jason Monk421a9412017-02-06 09:15:21 -080052public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010053
Jorim Jaggif6782ee2016-07-22 11:40:00 +020054 private static final String TAG = "StatusBarWindowManager";
55
Jorim Jaggi5cf17872014-03-26 18:31:48 +010056 private final Context mContext;
57 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020058 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070059 private final DozeParameters mDozeParameters;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010060 private View mStatusBarView;
61 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010062 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020063 private boolean mHasTopUi;
64 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010065 private int mBarHeight;
66 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020067 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080069 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010070
71 public StatusBarWindowManager(Context context) {
72 mContext = context;
73 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080074 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010075 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupin16cfe452018-02-08 13:14:50 -080076 mDozeParameters = DozeParameters.getInstance(mContext);
Lucas Dupin7517b5d2017-08-22 12:51:25 -070077 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078 }
79
80 private boolean shouldEnableKeyguardScreenRotation() {
81 Resources res = mContext.getResources();
82 return SystemProperties.getBoolean("lockscreen.rot_override", false)
83 || res.getBoolean(R.bool.config_enableLockScreenRotation);
84 }
85
86 /**
87 * Adds the status bar view to the window manager.
88 *
89 * @param statusBarView The view to add.
90 * @param barHeight The height of the status bar in collapsed state.
91 */
92 public void add(View statusBarView, int barHeight) {
93
94 // Now that the status bar window encompasses the sliding panel and its
95 // translucent backdrop, the entire thing is made TRANSLUCENT and is
96 // hardware-accelerated.
97 mLp = new WindowManager.LayoutParams(
98 ViewGroup.LayoutParams.MATCH_PARENT,
99 barHeight,
100 WindowManager.LayoutParams.TYPE_STATUS_BAR,
101 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
102 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
103 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
104 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200105 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100106 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800107 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200108 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100109 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100110 mLp.setTitle("StatusBar");
111 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100112 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100113 mStatusBarView = statusBarView;
114 mBarHeight = barHeight;
115 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100116 mLpChanged = new WindowManager.LayoutParams();
117 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100118 }
119
Adrian Roos3e23eb52017-07-07 15:58:57 +0200120 public void setDozeScreenBrightness(int value) {
121 mScreenBrightnessDoze = value / 255f;
122 }
123
Lucas Dupin987f1932017-05-13 21:02:52 -0700124 public void setKeyguardDark(boolean dark) {
125 int vis = mStatusBarView.getSystemUiVisibility();
126 if (dark) {
127 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
128 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
129 } else {
130 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
131 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
132 }
133 mStatusBarView.setSystemUiVisibility(vis);
134 }
135
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100136 private void applyKeyguardFlags(State state) {
137 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100138 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100139 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100140 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100141 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800142
Lucas Dupin16cfe452018-02-08 13:14:50 -0800143 final boolean scrimsOccludingWallpaper =
144 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800145 final boolean keyguardOrAod = state.keyguardShowing
146 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000147 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800148 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
149 } else {
150 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
151 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100152 }
153
154 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200155 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200156 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100157 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200158 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100159 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200160 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100161 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100162 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100163 }
164 }
165
166 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700167 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800168 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900169 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100170 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
171 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700172 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100173 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
174 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100175 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100176 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
177 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100178 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100179
Adrian Roos5153d4a2016-03-22 10:01:56 -0700180 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100181 }
182
Tiger Huanga90dea42018-08-03 17:20:17 +0800183 private void applyForceShowNavigationFlag(State state) {
184 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800185 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800186 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800187 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800188 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800189 }
190 }
191
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100192 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200193 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800194 if (state.forcePluginOpen) {
195 mListener.setWouldOtherwiseCollapse(expanded);
196 expanded = true;
197 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100198 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100199 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100200 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100201 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100202 }
203 }
204
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200205 private boolean isExpanded(State state) {
206 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
207 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800208 || state.headsUpShowing
209 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200210 }
211
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200212 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700213 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
214 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
215 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
216 mStatusBarView.requestApplyInsets();
217 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200218 }
219
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100220 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200221 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200222 && state.statusBarState == StatusBarState.KEYGUARD
223 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100224 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100225 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100226 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100227 }
228 }
229
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200230 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200231 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200232 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800233 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100234 mLpChanged.inputFeatures |=
235 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200236 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100237 mLpChanged.inputFeatures &=
238 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200239 }
240 }
241
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100242 private void apply(State state) {
243 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700244 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100245 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800246 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100247 adjustScreenOrientation(state);
248 applyHeight(state);
249 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200250 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200251 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700252 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700253 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200254 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200255 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100256 if (mLp.copyFrom(mLpChanged) != 0) {
257 mWindowManager.updateViewLayout(mStatusBarView, mLp);
258 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200259 if (mHasTopUi != mHasTopUiChanged) {
260 try {
261 mActivityManager.setHasTopUi(mHasTopUiChanged);
262 } catch (RemoteException e) {
263 Log.e(TAG, "Failed to call setHasTopUi", e);
264 }
265 mHasTopUi = mHasTopUiChanged;
266 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100267 }
268
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700269 private void applyForceStatusBarVisibleFlag(State state) {
270 if (state.forceStatusBarVisible) {
271 mLpChanged.privateFlags |= WindowManager
272 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
273 } else {
274 mLpChanged.privateFlags &= ~WindowManager
275 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
276 }
277 }
278
Selim Cineka59ecc32015-04-07 10:51:49 -0700279 private void applyModalFlag(State state) {
280 if (state.headsUpShowing) {
281 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
282 } else {
283 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
284 }
285 }
286
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700287 private void applyBrightness(State state) {
288 if (state.forceDozeBrightness) {
289 mLpChanged.screenBrightness = mScreenBrightnessDoze;
290 } else {
291 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
292 }
293 }
294
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200295 private void applyHasTopUi(State state) {
296 mHasTopUiChanged = isExpanded(state);
297 }
298
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200299 private void applySleepToken(State state) {
300 if (state.dozing) {
301 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
302 } else {
303 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
304 }
305 }
306
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100307 public void setKeyguardShowing(boolean showing) {
308 mCurrentState.keyguardShowing = showing;
309 apply(mCurrentState);
310 }
311
312 public void setKeyguardOccluded(boolean occluded) {
313 mCurrentState.keyguardOccluded = occluded;
314 apply(mCurrentState);
315 }
316
317 public void setKeyguardNeedsInput(boolean needsInput) {
318 mCurrentState.keyguardNeedsInput = needsInput;
319 apply(mCurrentState);
320 }
321
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700322 public void setPanelVisible(boolean visible) {
323 mCurrentState.panelVisible = visible;
324 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100325 apply(mCurrentState);
326 }
327
328 public void setStatusBarFocusable(boolean focusable) {
329 mCurrentState.statusBarFocusable = focusable;
330 apply(mCurrentState);
331 }
332
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200333 public void setBouncerShowing(boolean showing) {
334 mCurrentState.bouncerShowing = showing;
335 apply(mCurrentState);
336 }
337
Adrian Roosd5c2db62016-03-08 16:11:31 -0800338 public void setBackdropShowing(boolean showing) {
339 mCurrentState.backdropShowing = showing;
340 apply(mCurrentState);
341 }
342
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200343 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
344 mCurrentState.keyguardFadingAway = keyguardFadingAway;
345 apply(mCurrentState);
346 }
347
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200348 public void setQsExpanded(boolean expanded) {
349 mCurrentState.qsExpanded = expanded;
350 apply(mCurrentState);
351 }
352
Vadim Tryshev6069c402016-03-09 14:24:29 -0800353 public void setForceUserActivity(boolean forceUserActivity) {
354 mCurrentState.forceUserActivity = forceUserActivity;
355 apply(mCurrentState);
356 }
357
Lucas Dupin82aa1632017-12-13 00:13:57 -0800358 public void setScrimsVisibility(int scrimsVisibility) {
359 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200360 apply(mCurrentState);
361 }
362
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700363 public void setHeadsUpShowing(boolean showing) {
364 mCurrentState.headsUpShowing = showing;
365 apply(mCurrentState);
366 }
367
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700368 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
369 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
370 apply(mCurrentState);
371 }
372
Jorim Jaggiecbab362014-04-23 16:13:15 +0200373 /**
374 * @param state The {@link StatusBarState} of the status bar.
375 */
376 public void setStatusBarState(int state) {
377 mCurrentState.statusBarState = state;
378 apply(mCurrentState);
379 }
380
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700381 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
382 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
383 apply(mCurrentState);
384 }
385
Selim Cinek737bff32015-05-08 16:08:35 -0700386 /**
387 * Force the window to be collapsed, even if it should theoretically be expanded.
388 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
389 * be computed.
390 */
391 public void setForceWindowCollapsed(boolean force) {
392 mCurrentState.forceCollapsed = force;
393 apply(mCurrentState);
394 }
395
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700396 public void setPanelExpanded(boolean isExpanded) {
397 mCurrentState.panelExpanded = isExpanded;
398 apply(mCurrentState);
399 }
400
Adrian Roosd28ccd72016-01-06 15:23:14 +0100401 @Override
402 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700403 mCurrentState.remoteInputActive = remoteInputActive;
404 apply(mCurrentState);
405 }
406
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700407 /**
408 * Set whether the screen brightness is forced to the value we use for doze mode by the status
409 * bar window.
410 */
411 public void setForceDozeBrightness(boolean forceDozeBrightness) {
412 mCurrentState.forceDozeBrightness = forceDozeBrightness;
413 apply(mCurrentState);
414 }
415
Adrian Roos67cca742017-04-13 16:52:51 -0700416 public void setDozing(boolean dozing) {
417 mCurrentState.dozing = dozing;
418 apply(mCurrentState);
419 }
420
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700421 public void setBarHeight(int barHeight) {
422 mBarHeight = barHeight;
423 apply(mCurrentState);
424 }
425
Jason Monk421a9412017-02-06 09:15:21 -0800426 public void setForcePluginOpen(boolean forcePluginOpen) {
427 mCurrentState.forcePluginOpen = forcePluginOpen;
428 apply(mCurrentState);
429 }
430
431 public void setStateListener(OtherwisedCollapsedListener listener) {
432 mListener = listener;
433 }
434
Selim Cinek7025f262015-07-13 16:22:48 -0700435 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
436 pw.println("StatusBarWindowManager state:");
437 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200438 }
439
Adrian Roosd5c2db62016-03-08 16:11:31 -0800440 public boolean isShowingWallpaper() {
441 return !mCurrentState.backdropShowing;
442 }
443
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100444 private static class State {
445 boolean keyguardShowing;
446 boolean keyguardOccluded;
447 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700448 boolean panelVisible;
449 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100450 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200451 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200452 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200453 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700454 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700455 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700456 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700457 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800458 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800459 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700460 boolean wallpaperSupportsAmbientMode;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100461
Jorim Jaggiecbab362014-04-23 16:13:15 +0200462 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500463 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200464 */
465 int statusBarState;
466
Adrian Roos1c0ca502015-10-07 12:20:42 -0700467 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800468 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700469 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800470 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700471
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100472 private boolean isKeyguardShowingAndNotOccluded() {
473 return keyguardShowing && !keyguardOccluded;
474 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200475
476 @Override
477 public String toString() {
478 StringBuilder result = new StringBuilder();
479 String newLine = "\n";
480 result.append("Window State {");
481 result.append(newLine);
482
483 Field[] fields = this.getClass().getDeclaredFields();
484
485 // Print field names paired with their values
486 for (Field field : fields) {
487 result.append(" ");
488 try {
489 result.append(field.getName());
490 result.append(": ");
491 //requires access to private field:
492 result.append(field.get(this));
493 } catch (IllegalAccessException ex) {
494 }
495 result.append(newLine);
496 }
497 result.append("}");
498
499 return result.toString();
500 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100501 }
Jason Monk421a9412017-02-06 09:15:21 -0800502
503 /**
504 * Custom listener to pipe data back to plugins about whether or not the status bar would be
505 * collapsed if not for the plugin.
506 * TODO: Find cleaner way to do this.
507 */
508 public interface OtherwisedCollapsedListener {
509 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
510 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100511}