blob: ed96b41158885a53469328fc00517fe821d3b7ad [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;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020033import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010034
35import com.android.keyguard.R;
Jason Monk421a9412017-02-06 09:15:21 -080036import com.android.systemui.Dumpable;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010037import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roosd28ccd72016-01-06 15:23:14 +010038import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020039import com.android.systemui.statusbar.StatusBarState;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010040
Selim Cinek7025f262015-07-13 16:22:48 -070041import java.io.FileDescriptor;
42import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020043import java.lang.reflect.Field;
44
Jorim Jaggi5cf17872014-03-26 18:31:48 +010045/**
46 * Encapsulates all logic for the status bar window state management.
47 */
Jason Monk421a9412017-02-06 09:15:21 -080048public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010049
Jorim Jaggif6782ee2016-07-22 11:40:00 +020050 private static final String TAG = "StatusBarWindowManager";
51
Jorim Jaggi5cf17872014-03-26 18:31:48 +010052 private final Context mContext;
53 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020054 private final IActivityManager mActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010055 private View mStatusBarView;
56 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010057 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020058 private boolean mHasTopUi;
59 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010060 private int mBarHeight;
61 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020062 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010063 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080064 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010065
66 public StatusBarWindowManager(Context context) {
67 mContext = context;
68 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080069 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010070 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070071 mScreenBrightnessDoze = mContext.getResources().getInteger(
72 com.android.internal.R.integer.config_screenBrightnessDoze) / 255f;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073 }
74
75 private boolean shouldEnableKeyguardScreenRotation() {
76 Resources res = mContext.getResources();
77 return SystemProperties.getBoolean("lockscreen.rot_override", false)
78 || res.getBoolean(R.bool.config_enableLockScreenRotation);
79 }
80
81 /**
82 * Adds the status bar view to the window manager.
83 *
84 * @param statusBarView The view to add.
85 * @param barHeight The height of the status bar in collapsed state.
86 */
87 public void add(View statusBarView, int barHeight) {
88
89 // Now that the status bar window encompasses the sliding panel and its
90 // translucent backdrop, the entire thing is made TRANSLUCENT and is
91 // hardware-accelerated.
92 mLp = new WindowManager.LayoutParams(
93 ViewGroup.LayoutParams.MATCH_PARENT,
94 barHeight,
95 WindowManager.LayoutParams.TYPE_STATUS_BAR,
96 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
97 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
98 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
99 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200100 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100101 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800102 mLp.token = new Binder();
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
Adrian Roosa5c63222017-07-27 16:33:39 +0200189 || state.headsUpShowing || state.scrimsVisible);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200190 }
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 Jaggif12ec0f2017-08-23 16:14:10 +0200234 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100235 if (mLp.copyFrom(mLpChanged) != 0) {
236 mWindowManager.updateViewLayout(mStatusBarView, mLp);
237 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200238 if (mHasTopUi != mHasTopUiChanged) {
239 try {
240 mActivityManager.setHasTopUi(mHasTopUiChanged);
241 } catch (RemoteException e) {
242 Log.e(TAG, "Failed to call setHasTopUi", e);
243 }
244 mHasTopUi = mHasTopUiChanged;
245 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100246 }
247
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700248 private void applyForceStatusBarVisibleFlag(State state) {
249 if (state.forceStatusBarVisible) {
250 mLpChanged.privateFlags |= WindowManager
251 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
252 } else {
253 mLpChanged.privateFlags &= ~WindowManager
254 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
255 }
256 }
257
Selim Cineka59ecc32015-04-07 10:51:49 -0700258 private void applyModalFlag(State state) {
259 if (state.headsUpShowing) {
260 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
261 } else {
262 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
263 }
264 }
265
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700266 private void applyBrightness(State state) {
267 if (state.forceDozeBrightness) {
268 mLpChanged.screenBrightness = mScreenBrightnessDoze;
269 } else {
270 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
271 }
272 }
273
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200274 private void applyHasTopUi(State state) {
275 mHasTopUiChanged = isExpanded(state);
276 }
277
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200278 private void applySleepToken(State state) {
279 if (state.dozing) {
280 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
281 } else {
282 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
283 }
284 }
285
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100286 public void setKeyguardShowing(boolean showing) {
287 mCurrentState.keyguardShowing = showing;
288 apply(mCurrentState);
289 }
290
291 public void setKeyguardOccluded(boolean occluded) {
292 mCurrentState.keyguardOccluded = occluded;
293 apply(mCurrentState);
294 }
295
296 public void setKeyguardNeedsInput(boolean needsInput) {
297 mCurrentState.keyguardNeedsInput = needsInput;
298 apply(mCurrentState);
299 }
300
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700301 public void setPanelVisible(boolean visible) {
302 mCurrentState.panelVisible = visible;
303 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100304 apply(mCurrentState);
305 }
306
307 public void setStatusBarFocusable(boolean focusable) {
308 mCurrentState.statusBarFocusable = focusable;
309 apply(mCurrentState);
310 }
311
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200312 public void setBouncerShowing(boolean showing) {
313 mCurrentState.bouncerShowing = showing;
314 apply(mCurrentState);
315 }
316
Adrian Roosd5c2db62016-03-08 16:11:31 -0800317 public void setBackdropShowing(boolean showing) {
318 mCurrentState.backdropShowing = showing;
319 apply(mCurrentState);
320 }
321
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200322 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
323 mCurrentState.keyguardFadingAway = keyguardFadingAway;
324 apply(mCurrentState);
325 }
326
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200327 public void setQsExpanded(boolean expanded) {
328 mCurrentState.qsExpanded = expanded;
329 apply(mCurrentState);
330 }
331
Vadim Tryshev6069c402016-03-09 14:24:29 -0800332 public void setForceUserActivity(boolean forceUserActivity) {
333 mCurrentState.forceUserActivity = forceUserActivity;
334 apply(mCurrentState);
335 }
336
Adrian Roosa5c63222017-07-27 16:33:39 +0200337 public void setScrimsVisible(boolean scrimsVisible) {
338 mCurrentState.scrimsVisible = scrimsVisible;
339 apply(mCurrentState);
340 }
341
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700342 public void setHeadsUpShowing(boolean showing) {
343 mCurrentState.headsUpShowing = showing;
344 apply(mCurrentState);
345 }
346
Jorim Jaggiecbab362014-04-23 16:13:15 +0200347 /**
348 * @param state The {@link StatusBarState} of the status bar.
349 */
350 public void setStatusBarState(int state) {
351 mCurrentState.statusBarState = state;
352 apply(mCurrentState);
353 }
354
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700355 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
356 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
357 apply(mCurrentState);
358 }
359
Selim Cinek737bff32015-05-08 16:08:35 -0700360 /**
361 * Force the window to be collapsed, even if it should theoretically be expanded.
362 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
363 * be computed.
364 */
365 public void setForceWindowCollapsed(boolean force) {
366 mCurrentState.forceCollapsed = force;
367 apply(mCurrentState);
368 }
369
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700370 public void setPanelExpanded(boolean isExpanded) {
371 mCurrentState.panelExpanded = isExpanded;
372 apply(mCurrentState);
373 }
374
Adrian Roosd28ccd72016-01-06 15:23:14 +0100375 @Override
376 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700377 mCurrentState.remoteInputActive = remoteInputActive;
378 apply(mCurrentState);
379 }
380
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700381 /**
382 * Set whether the screen brightness is forced to the value we use for doze mode by the status
383 * bar window.
384 */
385 public void setForceDozeBrightness(boolean forceDozeBrightness) {
386 mCurrentState.forceDozeBrightness = forceDozeBrightness;
387 apply(mCurrentState);
388 }
389
Adrian Roos67cca742017-04-13 16:52:51 -0700390 public void setDozing(boolean dozing) {
391 mCurrentState.dozing = dozing;
392 apply(mCurrentState);
393 }
394
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700395 public void setBarHeight(int barHeight) {
396 mBarHeight = barHeight;
397 apply(mCurrentState);
398 }
399
Jason Monk421a9412017-02-06 09:15:21 -0800400 public void setForcePluginOpen(boolean forcePluginOpen) {
401 mCurrentState.forcePluginOpen = forcePluginOpen;
402 apply(mCurrentState);
403 }
404
405 public void setStateListener(OtherwisedCollapsedListener listener) {
406 mListener = listener;
407 }
408
Selim Cinek7025f262015-07-13 16:22:48 -0700409 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
410 pw.println("StatusBarWindowManager state:");
411 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200412 }
413
Adrian Roosd5c2db62016-03-08 16:11:31 -0800414 public boolean isShowingWallpaper() {
415 return !mCurrentState.backdropShowing;
416 }
417
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100418 private static class State {
419 boolean keyguardShowing;
420 boolean keyguardOccluded;
421 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700422 boolean panelVisible;
423 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100424 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200425 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200426 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200427 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700428 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700429 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700430 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700431 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800432 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800433 boolean backdropShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100434
Jorim Jaggiecbab362014-04-23 16:13:15 +0200435 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500436 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200437 */
438 int statusBarState;
439
Adrian Roos1c0ca502015-10-07 12:20:42 -0700440 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800441 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700442 boolean dozing;
Adrian Roosa5c63222017-07-27 16:33:39 +0200443 boolean scrimsVisible;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700444
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100445 private boolean isKeyguardShowingAndNotOccluded() {
446 return keyguardShowing && !keyguardOccluded;
447 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200448
449 @Override
450 public String toString() {
451 StringBuilder result = new StringBuilder();
452 String newLine = "\n";
453 result.append("Window State {");
454 result.append(newLine);
455
456 Field[] fields = this.getClass().getDeclaredFields();
457
458 // Print field names paired with their values
459 for (Field field : fields) {
460 result.append(" ");
461 try {
462 result.append(field.getName());
463 result.append(": ");
464 //requires access to private field:
465 result.append(field.get(this));
466 } catch (IllegalAccessException ex) {
467 }
468 result.append(newLine);
469 }
470 result.append("}");
471
472 return result.toString();
473 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100474 }
Jason Monk421a9412017-02-06 09:15:21 -0800475
476 /**
477 * Custom listener to pipe data back to plugins about whether or not the status bar would be
478 * collapsed if not for the plugin.
479 * TODO: Find cleaner way to do this.
480 */
481 public interface OtherwisedCollapsedListener {
482 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
483 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100484}