blob: 93dc6de1059adf435997a43c0aed5324867f00c0 [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
Sudheer Shankadc589ac2016-11-10 15:30:17 -080019import android.app.ActivityManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020020import android.app.IActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010021import android.content.Context;
22import android.content.pm.ActivityInfo;
23import android.content.res.Resources;
24import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080025import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020026import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010027import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020028import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010029import android.view.Gravity;
30import android.view.View;
31import android.view.ViewGroup;
32import android.view.WindowManager;
33
34import com.android.keyguard.R;
Jason Monk421a9412017-02-06 09:15:21 -080035import com.android.systemui.Dumpable;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010036import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roosd28ccd72016-01-06 15:23:14 +010037import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020038import com.android.systemui.statusbar.StatusBarState;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010039
Selim Cinek7025f262015-07-13 16:22:48 -070040import java.io.FileDescriptor;
41import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020042import java.lang.reflect.Field;
43
Jorim Jaggi5cf17872014-03-26 18:31:48 +010044/**
45 * Encapsulates all logic for the status bar window state management.
46 */
Jason Monk421a9412017-02-06 09:15:21 -080047public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010048
Jorim Jaggif6782ee2016-07-22 11:40:00 +020049 private static final String TAG = "StatusBarWindowManager";
50
Jorim Jaggi5cf17872014-03-26 18:31:48 +010051 private final Context mContext;
52 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020053 private final IActivityManager mActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010054 private View mStatusBarView;
55 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010056 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020057 private boolean mHasTopUi;
58 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010059 private int mBarHeight;
60 private final boolean mKeyguardScreenRotation;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070061 private final float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010062 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080063 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010064
65 public StatusBarWindowManager(Context context) {
66 mContext = context;
67 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080068 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010069 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070070 mScreenBrightnessDoze = mContext.getResources().getInteger(
71 com.android.internal.R.integer.config_screenBrightnessDoze) / 255f;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010072 }
73
74 private boolean shouldEnableKeyguardScreenRotation() {
75 Resources res = mContext.getResources();
76 return SystemProperties.getBoolean("lockscreen.rot_override", false)
77 || res.getBoolean(R.bool.config_enableLockScreenRotation);
78 }
79
80 /**
81 * Adds the status bar view to the window manager.
82 *
83 * @param statusBarView The view to add.
84 * @param barHeight The height of the status bar in collapsed state.
85 */
86 public void add(View statusBarView, int barHeight) {
87
88 // Now that the status bar window encompasses the sliding panel and its
89 // translucent backdrop, the entire thing is made TRANSLUCENT and is
90 // hardware-accelerated.
91 mLp = new WindowManager.LayoutParams(
92 ViewGroup.LayoutParams.MATCH_PARENT,
93 barHeight,
94 WindowManager.LayoutParams.TYPE_STATUS_BAR,
95 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
96 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
97 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
98 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +020099 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100100 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800101 mLp.token = new Binder();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100102 mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200103 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100104 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100105 mLp.setTitle("StatusBar");
106 mLp.packageName = mContext.getPackageName();
107 mStatusBarView = statusBarView;
108 mBarHeight = barHeight;
109 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100110 mLpChanged = new WindowManager.LayoutParams();
111 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100112 }
113
Lucas Dupin987f1932017-05-13 21:02:52 -0700114 public void setKeyguardDark(boolean dark) {
115 int vis = mStatusBarView.getSystemUiVisibility();
116 if (dark) {
117 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
118 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
119 } else {
120 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
121 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
122 }
123 mStatusBarView.setSystemUiVisibility(vis);
124 }
125
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100126 private void applyKeyguardFlags(State state) {
127 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100128 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100129 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100130 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100131 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800132
Adrian Roos67cca742017-04-13 16:52:51 -0700133 if (state.keyguardShowing && !state.backdropShowing && !state.dozing) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800134 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
135 } else {
136 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
137 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138 }
139
140 private void adjustScreenOrientation(State state) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200141 if (state.isKeyguardShowingAndNotOccluded()) {
142 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100143 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200144 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100145 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200146 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100147 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100148 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100149 }
150 }
151
152 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700153 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800154 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500155 || StatusBar.ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100156 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
157 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700158 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100159 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
160 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100161 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100162 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
163 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100164 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100165
Adrian Roos5153d4a2016-03-22 10:01:56 -0700166 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100167 }
168
169 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200170 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800171 if (state.forcePluginOpen) {
172 mListener.setWouldOtherwiseCollapse(expanded);
173 expanded = true;
174 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100175 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100176 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100177 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100178 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100179 }
180 }
181
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200182 private boolean isExpanded(State state) {
183 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
184 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
185 || state.headsUpShowing);
186 }
187
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200188 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700189 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
190 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
191 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
192 mStatusBarView.requestApplyInsets();
193 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200194 }
195
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100196 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200197 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200198 && state.statusBarState == StatusBarState.KEYGUARD
199 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100200 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100201 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100202 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100203 }
204 }
205
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200206 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200207 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200208 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800209 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100210 mLpChanged.inputFeatures |=
211 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200212 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100213 mLpChanged.inputFeatures &=
214 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200215 }
216 }
217
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100218 private void apply(State state) {
219 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700220 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100221 applyFocusableFlag(state);
222 adjustScreenOrientation(state);
223 applyHeight(state);
224 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200225 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200226 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700227 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700228 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200229 applyHasTopUi(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100230 if (mLp.copyFrom(mLpChanged) != 0) {
231 mWindowManager.updateViewLayout(mStatusBarView, mLp);
232 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200233 if (mHasTopUi != mHasTopUiChanged) {
234 try {
235 mActivityManager.setHasTopUi(mHasTopUiChanged);
236 } catch (RemoteException e) {
237 Log.e(TAG, "Failed to call setHasTopUi", e);
238 }
239 mHasTopUi = mHasTopUiChanged;
240 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100241 }
242
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700243 private void applyForceStatusBarVisibleFlag(State state) {
244 if (state.forceStatusBarVisible) {
245 mLpChanged.privateFlags |= WindowManager
246 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
247 } else {
248 mLpChanged.privateFlags &= ~WindowManager
249 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
250 }
251 }
252
Selim Cineka59ecc32015-04-07 10:51:49 -0700253 private void applyModalFlag(State state) {
254 if (state.headsUpShowing) {
255 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
256 } else {
257 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
258 }
259 }
260
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700261 private void applyBrightness(State state) {
262 if (state.forceDozeBrightness) {
263 mLpChanged.screenBrightness = mScreenBrightnessDoze;
264 } else {
265 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
266 }
267 }
268
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200269 private void applyHasTopUi(State state) {
270 mHasTopUiChanged = isExpanded(state);
271 }
272
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100273 public void setKeyguardShowing(boolean showing) {
274 mCurrentState.keyguardShowing = showing;
275 apply(mCurrentState);
276 }
277
278 public void setKeyguardOccluded(boolean occluded) {
279 mCurrentState.keyguardOccluded = occluded;
280 apply(mCurrentState);
281 }
282
283 public void setKeyguardNeedsInput(boolean needsInput) {
284 mCurrentState.keyguardNeedsInput = needsInput;
285 apply(mCurrentState);
286 }
287
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700288 public void setPanelVisible(boolean visible) {
289 mCurrentState.panelVisible = visible;
290 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100291 apply(mCurrentState);
292 }
293
294 public void setStatusBarFocusable(boolean focusable) {
295 mCurrentState.statusBarFocusable = focusable;
296 apply(mCurrentState);
297 }
298
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200299 public void setBouncerShowing(boolean showing) {
300 mCurrentState.bouncerShowing = showing;
301 apply(mCurrentState);
302 }
303
Adrian Roosd5c2db62016-03-08 16:11:31 -0800304 public void setBackdropShowing(boolean showing) {
305 mCurrentState.backdropShowing = showing;
306 apply(mCurrentState);
307 }
308
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200309 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
310 mCurrentState.keyguardFadingAway = keyguardFadingAway;
311 apply(mCurrentState);
312 }
313
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200314 public void setQsExpanded(boolean expanded) {
315 mCurrentState.qsExpanded = expanded;
316 apply(mCurrentState);
317 }
318
Vadim Tryshev6069c402016-03-09 14:24:29 -0800319 public void setForceUserActivity(boolean forceUserActivity) {
320 mCurrentState.forceUserActivity = forceUserActivity;
321 apply(mCurrentState);
322 }
323
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700324 public void setHeadsUpShowing(boolean showing) {
325 mCurrentState.headsUpShowing = showing;
326 apply(mCurrentState);
327 }
328
Jorim Jaggiecbab362014-04-23 16:13:15 +0200329 /**
330 * @param state The {@link StatusBarState} of the status bar.
331 */
332 public void setStatusBarState(int state) {
333 mCurrentState.statusBarState = state;
334 apply(mCurrentState);
335 }
336
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700337 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
338 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
339 apply(mCurrentState);
340 }
341
Selim Cinek737bff32015-05-08 16:08:35 -0700342 /**
343 * Force the window to be collapsed, even if it should theoretically be expanded.
344 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
345 * be computed.
346 */
347 public void setForceWindowCollapsed(boolean force) {
348 mCurrentState.forceCollapsed = force;
349 apply(mCurrentState);
350 }
351
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700352 public void setPanelExpanded(boolean isExpanded) {
353 mCurrentState.panelExpanded = isExpanded;
354 apply(mCurrentState);
355 }
356
Adrian Roosd28ccd72016-01-06 15:23:14 +0100357 @Override
358 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700359 mCurrentState.remoteInputActive = remoteInputActive;
360 apply(mCurrentState);
361 }
362
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700363 /**
364 * Set whether the screen brightness is forced to the value we use for doze mode by the status
365 * bar window.
366 */
367 public void setForceDozeBrightness(boolean forceDozeBrightness) {
368 mCurrentState.forceDozeBrightness = forceDozeBrightness;
369 apply(mCurrentState);
370 }
371
Adrian Roos67cca742017-04-13 16:52:51 -0700372 public void setDozing(boolean dozing) {
373 mCurrentState.dozing = dozing;
374 apply(mCurrentState);
375 }
376
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700377 public void setBarHeight(int barHeight) {
378 mBarHeight = barHeight;
379 apply(mCurrentState);
380 }
381
Jason Monk421a9412017-02-06 09:15:21 -0800382 public void setForcePluginOpen(boolean forcePluginOpen) {
383 mCurrentState.forcePluginOpen = forcePluginOpen;
384 apply(mCurrentState);
385 }
386
387 public void setStateListener(OtherwisedCollapsedListener listener) {
388 mListener = listener;
389 }
390
Selim Cinek7025f262015-07-13 16:22:48 -0700391 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
392 pw.println("StatusBarWindowManager state:");
393 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200394 }
395
Adrian Roosd5c2db62016-03-08 16:11:31 -0800396 public boolean isShowingWallpaper() {
397 return !mCurrentState.backdropShowing;
398 }
399
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100400 private static class State {
401 boolean keyguardShowing;
402 boolean keyguardOccluded;
403 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700404 boolean panelVisible;
405 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100406 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200407 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200408 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200409 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700410 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700411 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700412 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700413 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800414 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800415 boolean backdropShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100416
Jorim Jaggiecbab362014-04-23 16:13:15 +0200417 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500418 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200419 */
420 int statusBarState;
421
Adrian Roos1c0ca502015-10-07 12:20:42 -0700422 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800423 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700424 boolean dozing;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700425
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100426 private boolean isKeyguardShowingAndNotOccluded() {
427 return keyguardShowing && !keyguardOccluded;
428 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200429
430 @Override
431 public String toString() {
432 StringBuilder result = new StringBuilder();
433 String newLine = "\n";
434 result.append("Window State {");
435 result.append(newLine);
436
437 Field[] fields = this.getClass().getDeclaredFields();
438
439 // Print field names paired with their values
440 for (Field field : fields) {
441 result.append(" ");
442 try {
443 result.append(field.getName());
444 result.append(": ");
445 //requires access to private field:
446 result.append(field.get(this));
447 } catch (IllegalAccessException ex) {
448 }
449 result.append(newLine);
450 }
451 result.append("}");
452
453 return result.toString();
454 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100455 }
Jason Monk421a9412017-02-06 09:15:21 -0800456
457 /**
458 * Custom listener to pipe data back to plugins about whether or not the status bar would be
459 * collapsed if not for the plugin.
460 * TODO: Find cleaner way to do this.
461 */
462 public interface OtherwisedCollapsedListener {
463 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
464 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100465}