blob: 836b2ef7e14942568302751293ae6c548045a162 [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;
Adrian Roos3e23eb52017-07-07 15:58:57 +020061 private 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
Adrian Roos3e23eb52017-07-07 15:58:57 +0200114 public void setDozeScreenBrightness(int value) {
115 mScreenBrightnessDoze = value / 255f;
116 }
117
Lucas Dupin987f1932017-05-13 21:02:52 -0700118 public void setKeyguardDark(boolean dark) {
119 int vis = mStatusBarView.getSystemUiVisibility();
120 if (dark) {
121 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
122 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
123 } else {
124 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
125 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
126 }
127 mStatusBarView.setSystemUiVisibility(vis);
128 }
129
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100130 private void applyKeyguardFlags(State state) {
131 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100132 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100134 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800136
Adrian Roos67cca742017-04-13 16:52:51 -0700137 if (state.keyguardShowing && !state.backdropShowing && !state.dozing) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800138 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
139 } else {
140 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
141 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100142 }
143
144 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200145 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200146 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100147 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200148 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100149 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200150 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100151 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100152 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100153 }
154 }
155
156 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700157 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800158 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500159 || StatusBar.ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100160 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
161 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700162 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100163 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
164 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100165 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100166 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
167 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100168 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100169
Adrian Roos5153d4a2016-03-22 10:01:56 -0700170 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100171 }
172
173 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200174 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800175 if (state.forcePluginOpen) {
176 mListener.setWouldOtherwiseCollapse(expanded);
177 expanded = true;
178 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100179 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100180 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100181 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100182 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100183 }
184 }
185
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200186 private boolean isExpanded(State state) {
187 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
188 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
189 || state.headsUpShowing);
190 }
191
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200192 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700193 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
194 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
195 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
196 mStatusBarView.requestApplyInsets();
197 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200198 }
199
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100200 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200201 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200202 && state.statusBarState == StatusBarState.KEYGUARD
203 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100204 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100205 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100206 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100207 }
208 }
209
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200210 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200211 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200212 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800213 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100214 mLpChanged.inputFeatures |=
215 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200216 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100217 mLpChanged.inputFeatures &=
218 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200219 }
220 }
221
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100222 private void apply(State state) {
223 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700224 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100225 applyFocusableFlag(state);
226 adjustScreenOrientation(state);
227 applyHeight(state);
228 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200229 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200230 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700231 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700232 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200233 applyHasTopUi(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100234 if (mLp.copyFrom(mLpChanged) != 0) {
235 mWindowManager.updateViewLayout(mStatusBarView, mLp);
236 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200237 if (mHasTopUi != mHasTopUiChanged) {
238 try {
239 mActivityManager.setHasTopUi(mHasTopUiChanged);
240 } catch (RemoteException e) {
241 Log.e(TAG, "Failed to call setHasTopUi", e);
242 }
243 mHasTopUi = mHasTopUiChanged;
244 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100245 }
246
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700247 private void applyForceStatusBarVisibleFlag(State state) {
248 if (state.forceStatusBarVisible) {
249 mLpChanged.privateFlags |= WindowManager
250 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
251 } else {
252 mLpChanged.privateFlags &= ~WindowManager
253 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
254 }
255 }
256
Selim Cineka59ecc32015-04-07 10:51:49 -0700257 private void applyModalFlag(State state) {
258 if (state.headsUpShowing) {
259 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
260 } else {
261 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
262 }
263 }
264
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700265 private void applyBrightness(State state) {
266 if (state.forceDozeBrightness) {
267 mLpChanged.screenBrightness = mScreenBrightnessDoze;
268 } else {
269 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
270 }
271 }
272
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200273 private void applyHasTopUi(State state) {
274 mHasTopUiChanged = isExpanded(state);
275 }
276
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100277 public void setKeyguardShowing(boolean showing) {
278 mCurrentState.keyguardShowing = showing;
279 apply(mCurrentState);
280 }
281
282 public void setKeyguardOccluded(boolean occluded) {
283 mCurrentState.keyguardOccluded = occluded;
284 apply(mCurrentState);
285 }
286
287 public void setKeyguardNeedsInput(boolean needsInput) {
288 mCurrentState.keyguardNeedsInput = needsInput;
289 apply(mCurrentState);
290 }
291
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700292 public void setPanelVisible(boolean visible) {
293 mCurrentState.panelVisible = visible;
294 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100295 apply(mCurrentState);
296 }
297
298 public void setStatusBarFocusable(boolean focusable) {
299 mCurrentState.statusBarFocusable = focusable;
300 apply(mCurrentState);
301 }
302
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200303 public void setBouncerShowing(boolean showing) {
304 mCurrentState.bouncerShowing = showing;
305 apply(mCurrentState);
306 }
307
Adrian Roosd5c2db62016-03-08 16:11:31 -0800308 public void setBackdropShowing(boolean showing) {
309 mCurrentState.backdropShowing = showing;
310 apply(mCurrentState);
311 }
312
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200313 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
314 mCurrentState.keyguardFadingAway = keyguardFadingAway;
315 apply(mCurrentState);
316 }
317
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200318 public void setQsExpanded(boolean expanded) {
319 mCurrentState.qsExpanded = expanded;
320 apply(mCurrentState);
321 }
322
Vadim Tryshev6069c402016-03-09 14:24:29 -0800323 public void setForceUserActivity(boolean forceUserActivity) {
324 mCurrentState.forceUserActivity = forceUserActivity;
325 apply(mCurrentState);
326 }
327
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700328 public void setHeadsUpShowing(boolean showing) {
329 mCurrentState.headsUpShowing = showing;
330 apply(mCurrentState);
331 }
332
Jorim Jaggiecbab362014-04-23 16:13:15 +0200333 /**
334 * @param state The {@link StatusBarState} of the status bar.
335 */
336 public void setStatusBarState(int state) {
337 mCurrentState.statusBarState = state;
338 apply(mCurrentState);
339 }
340
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700341 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
342 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
343 apply(mCurrentState);
344 }
345
Selim Cinek737bff32015-05-08 16:08:35 -0700346 /**
347 * Force the window to be collapsed, even if it should theoretically be expanded.
348 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
349 * be computed.
350 */
351 public void setForceWindowCollapsed(boolean force) {
352 mCurrentState.forceCollapsed = force;
353 apply(mCurrentState);
354 }
355
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700356 public void setPanelExpanded(boolean isExpanded) {
357 mCurrentState.panelExpanded = isExpanded;
358 apply(mCurrentState);
359 }
360
Adrian Roosd28ccd72016-01-06 15:23:14 +0100361 @Override
362 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700363 mCurrentState.remoteInputActive = remoteInputActive;
364 apply(mCurrentState);
365 }
366
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700367 /**
368 * Set whether the screen brightness is forced to the value we use for doze mode by the status
369 * bar window.
370 */
371 public void setForceDozeBrightness(boolean forceDozeBrightness) {
372 mCurrentState.forceDozeBrightness = forceDozeBrightness;
373 apply(mCurrentState);
374 }
375
Adrian Roos67cca742017-04-13 16:52:51 -0700376 public void setDozing(boolean dozing) {
377 mCurrentState.dozing = dozing;
378 apply(mCurrentState);
379 }
380
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700381 public void setBarHeight(int barHeight) {
382 mBarHeight = barHeight;
383 apply(mCurrentState);
384 }
385
Jason Monk421a9412017-02-06 09:15:21 -0800386 public void setForcePluginOpen(boolean forcePluginOpen) {
387 mCurrentState.forcePluginOpen = forcePluginOpen;
388 apply(mCurrentState);
389 }
390
391 public void setStateListener(OtherwisedCollapsedListener listener) {
392 mListener = listener;
393 }
394
Selim Cinek7025f262015-07-13 16:22:48 -0700395 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
396 pw.println("StatusBarWindowManager state:");
397 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200398 }
399
Adrian Roosd5c2db62016-03-08 16:11:31 -0800400 public boolean isShowingWallpaper() {
401 return !mCurrentState.backdropShowing;
402 }
403
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100404 private static class State {
405 boolean keyguardShowing;
406 boolean keyguardOccluded;
407 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700408 boolean panelVisible;
409 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100410 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200411 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200412 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200413 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700414 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700415 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700416 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700417 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800418 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800419 boolean backdropShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100420
Jorim Jaggiecbab362014-04-23 16:13:15 +0200421 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500422 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200423 */
424 int statusBarState;
425
Adrian Roos1c0ca502015-10-07 12:20:42 -0700426 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800427 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700428 boolean dozing;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700429
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100430 private boolean isKeyguardShowingAndNotOccluded() {
431 return keyguardShowing && !keyguardOccluded;
432 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200433
434 @Override
435 public String toString() {
436 StringBuilder result = new StringBuilder();
437 String newLine = "\n";
438 result.append("Window State {");
439 result.append(newLine);
440
441 Field[] fields = this.getClass().getDeclaredFields();
442
443 // Print field names paired with their values
444 for (Field field : fields) {
445 result.append(" ");
446 try {
447 result.append(field.getName());
448 result.append(": ");
449 //requires access to private field:
450 result.append(field.get(this));
451 } catch (IllegalAccessException ex) {
452 }
453 result.append(newLine);
454 }
455 result.append("}");
456
457 return result.toString();
458 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100459 }
Jason Monk421a9412017-02-06 09:15:21 -0800460
461 /**
462 * Custom listener to pipe data back to plugins about whether or not the status bar would be
463 * collapsed if not for the plugin.
464 * TODO: Find cleaner way to do this.
465 */
466 public interface OtherwisedCollapsedListener {
467 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
468 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100469}