blob: 47be4d0dd5d866aede1649ff174ddf4d2678abb6 [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
Eliot Courtneye77edea2017-11-15 14:25:21 +090019import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
20
Sudheer Shankadc589ac2016-11-10 15:30:17 -080021import android.app.ActivityManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020022import android.app.IActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010023import android.content.Context;
24import android.content.pm.ActivityInfo;
25import android.content.res.Resources;
26import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080027import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020028import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010029import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020030import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010031import android.view.Gravity;
32import android.view.View;
33import android.view.ViewGroup;
34import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020035import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010036
37import com.android.keyguard.R;
Jason Monk421a9412017-02-06 09:15:21 -080038import com.android.systemui.Dumpable;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010039import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roosd28ccd72016-01-06 15:23:14 +010040import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020041import com.android.systemui.statusbar.StatusBarState;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010042
Selim Cinek7025f262015-07-13 16:22:48 -070043import java.io.FileDescriptor;
44import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020045import java.lang.reflect.Field;
46
Jorim Jaggi5cf17872014-03-26 18:31:48 +010047/**
48 * Encapsulates all logic for the status bar window state management.
49 */
Jason Monk421a9412017-02-06 09:15:21 -080050public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010051
Jorim Jaggif6782ee2016-07-22 11:40:00 +020052 private static final String TAG = "StatusBarWindowManager";
53
Jorim Jaggi5cf17872014-03-26 18:31:48 +010054 private final Context mContext;
55 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020056 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070057 private final DozeParameters mDozeParameters;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010058 private View mStatusBarView;
59 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010060 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020061 private boolean mHasTopUi;
62 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010063 private int mBarHeight;
64 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020065 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010066 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080067 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068
69 public StatusBarWindowManager(Context context) {
70 mContext = context;
71 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080072 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupin7517b5d2017-08-22 12:51:25 -070074 mDozeParameters = new DozeParameters(mContext);
75 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010076 }
77
78 private boolean shouldEnableKeyguardScreenRotation() {
79 Resources res = mContext.getResources();
80 return SystemProperties.getBoolean("lockscreen.rot_override", false)
81 || res.getBoolean(R.bool.config_enableLockScreenRotation);
82 }
83
84 /**
85 * Adds the status bar view to the window manager.
86 *
87 * @param statusBarView The view to add.
88 * @param barHeight The height of the status bar in collapsed state.
89 */
90 public void add(View statusBarView, int barHeight) {
91
92 // Now that the status bar window encompasses the sliding panel and its
93 // translucent backdrop, the entire thing is made TRANSLUCENT and is
94 // hardware-accelerated.
95 mLp = new WindowManager.LayoutParams(
96 ViewGroup.LayoutParams.MATCH_PARENT,
97 barHeight,
98 WindowManager.LayoutParams.TYPE_STATUS_BAR,
99 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
100 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
101 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
102 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200103 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100104 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800105 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200106 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100107 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100108 mLp.setTitle("StatusBar");
109 mLp.packageName = mContext.getPackageName();
110 mStatusBarView = statusBarView;
111 mBarHeight = barHeight;
112 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100113 mLpChanged = new WindowManager.LayoutParams();
114 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100115 }
116
Adrian Roos3e23eb52017-07-07 15:58:57 +0200117 public void setDozeScreenBrightness(int value) {
118 mScreenBrightnessDoze = value / 255f;
119 }
120
Lucas Dupin987f1932017-05-13 21:02:52 -0700121 public void setKeyguardDark(boolean dark) {
122 int vis = mStatusBarView.getSystemUiVisibility();
123 if (dark) {
124 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
125 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
126 } else {
127 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
128 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
129 }
130 mStatusBarView.setSystemUiVisibility(vis);
131 }
132
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 private void applyKeyguardFlags(State state) {
134 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100135 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100136 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100137 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800139
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700140 final boolean showWallpaperOnAod = mDozeParameters.getAlwaysOn() &&
141 state.wallpaperSupportsAmbientMode;
142 if (state.keyguardShowing && !state.backdropShowing &&
143 (!state.dozing || showWallpaperOnAod)) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800144 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
145 } else {
146 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
147 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100148 }
149
150 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200151 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200152 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100153 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200154 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100155 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200156 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100157 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100158 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100159 }
160 }
161
162 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700163 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800164 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900165 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100166 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
167 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700168 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100169 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
170 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100171 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100172 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
173 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100174 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100175
Adrian Roos5153d4a2016-03-22 10:01:56 -0700176 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100177 }
178
179 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200180 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800181 if (state.forcePluginOpen) {
182 mListener.setWouldOtherwiseCollapse(expanded);
183 expanded = true;
184 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100185 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100186 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100187 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100188 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100189 }
190 }
191
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200192 private boolean isExpanded(State state) {
193 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
194 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Adrian Roosa5c63222017-07-27 16:33:39 +0200195 || state.headsUpShowing || state.scrimsVisible);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200196 }
197
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200198 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700199 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
200 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
201 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
202 mStatusBarView.requestApplyInsets();
203 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200204 }
205
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100206 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200207 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200208 && state.statusBarState == StatusBarState.KEYGUARD
209 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100210 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100211 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100212 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100213 }
214 }
215
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200216 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200217 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200218 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800219 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100220 mLpChanged.inputFeatures |=
221 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200222 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100223 mLpChanged.inputFeatures &=
224 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200225 }
226 }
227
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100228 private void apply(State state) {
229 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700230 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100231 applyFocusableFlag(state);
232 adjustScreenOrientation(state);
233 applyHeight(state);
234 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200235 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200236 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700237 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700238 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200239 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200240 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100241 if (mLp.copyFrom(mLpChanged) != 0) {
242 mWindowManager.updateViewLayout(mStatusBarView, mLp);
243 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200244 if (mHasTopUi != mHasTopUiChanged) {
245 try {
246 mActivityManager.setHasTopUi(mHasTopUiChanged);
247 } catch (RemoteException e) {
248 Log.e(TAG, "Failed to call setHasTopUi", e);
249 }
250 mHasTopUi = mHasTopUiChanged;
251 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100252 }
253
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700254 private void applyForceStatusBarVisibleFlag(State state) {
255 if (state.forceStatusBarVisible) {
256 mLpChanged.privateFlags |= WindowManager
257 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
258 } else {
259 mLpChanged.privateFlags &= ~WindowManager
260 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
261 }
262 }
263
Selim Cineka59ecc32015-04-07 10:51:49 -0700264 private void applyModalFlag(State state) {
265 if (state.headsUpShowing) {
266 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
267 } else {
268 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
269 }
270 }
271
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700272 private void applyBrightness(State state) {
273 if (state.forceDozeBrightness) {
274 mLpChanged.screenBrightness = mScreenBrightnessDoze;
275 } else {
276 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
277 }
278 }
279
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200280 private void applyHasTopUi(State state) {
281 mHasTopUiChanged = isExpanded(state);
282 }
283
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200284 private void applySleepToken(State state) {
285 if (state.dozing) {
286 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
287 } else {
288 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
289 }
290 }
291
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100292 public void setKeyguardShowing(boolean showing) {
293 mCurrentState.keyguardShowing = showing;
294 apply(mCurrentState);
295 }
296
297 public void setKeyguardOccluded(boolean occluded) {
298 mCurrentState.keyguardOccluded = occluded;
299 apply(mCurrentState);
300 }
301
302 public void setKeyguardNeedsInput(boolean needsInput) {
303 mCurrentState.keyguardNeedsInput = needsInput;
304 apply(mCurrentState);
305 }
306
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700307 public void setPanelVisible(boolean visible) {
308 mCurrentState.panelVisible = visible;
309 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100310 apply(mCurrentState);
311 }
312
313 public void setStatusBarFocusable(boolean focusable) {
314 mCurrentState.statusBarFocusable = focusable;
315 apply(mCurrentState);
316 }
317
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200318 public void setBouncerShowing(boolean showing) {
319 mCurrentState.bouncerShowing = showing;
320 apply(mCurrentState);
321 }
322
Adrian Roosd5c2db62016-03-08 16:11:31 -0800323 public void setBackdropShowing(boolean showing) {
324 mCurrentState.backdropShowing = showing;
325 apply(mCurrentState);
326 }
327
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200328 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
329 mCurrentState.keyguardFadingAway = keyguardFadingAway;
330 apply(mCurrentState);
331 }
332
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200333 public void setQsExpanded(boolean expanded) {
334 mCurrentState.qsExpanded = expanded;
335 apply(mCurrentState);
336 }
337
Vadim Tryshev6069c402016-03-09 14:24:29 -0800338 public void setForceUserActivity(boolean forceUserActivity) {
339 mCurrentState.forceUserActivity = forceUserActivity;
340 apply(mCurrentState);
341 }
342
Adrian Roosa5c63222017-07-27 16:33:39 +0200343 public void setScrimsVisible(boolean scrimsVisible) {
344 mCurrentState.scrimsVisible = scrimsVisible;
345 apply(mCurrentState);
346 }
347
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700348 public void setHeadsUpShowing(boolean showing) {
349 mCurrentState.headsUpShowing = showing;
350 apply(mCurrentState);
351 }
352
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700353 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
354 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
355 apply(mCurrentState);
356 }
357
Jorim Jaggiecbab362014-04-23 16:13:15 +0200358 /**
359 * @param state The {@link StatusBarState} of the status bar.
360 */
361 public void setStatusBarState(int state) {
362 mCurrentState.statusBarState = state;
363 apply(mCurrentState);
364 }
365
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700366 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
367 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
368 apply(mCurrentState);
369 }
370
Selim Cinek737bff32015-05-08 16:08:35 -0700371 /**
372 * Force the window to be collapsed, even if it should theoretically be expanded.
373 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
374 * be computed.
375 */
376 public void setForceWindowCollapsed(boolean force) {
377 mCurrentState.forceCollapsed = force;
378 apply(mCurrentState);
379 }
380
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700381 public void setPanelExpanded(boolean isExpanded) {
382 mCurrentState.panelExpanded = isExpanded;
383 apply(mCurrentState);
384 }
385
Adrian Roosd28ccd72016-01-06 15:23:14 +0100386 @Override
387 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700388 mCurrentState.remoteInputActive = remoteInputActive;
389 apply(mCurrentState);
390 }
391
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700392 /**
393 * Set whether the screen brightness is forced to the value we use for doze mode by the status
394 * bar window.
395 */
396 public void setForceDozeBrightness(boolean forceDozeBrightness) {
397 mCurrentState.forceDozeBrightness = forceDozeBrightness;
398 apply(mCurrentState);
399 }
400
Adrian Roos67cca742017-04-13 16:52:51 -0700401 public void setDozing(boolean dozing) {
402 mCurrentState.dozing = dozing;
403 apply(mCurrentState);
404 }
405
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700406 public void setBarHeight(int barHeight) {
407 mBarHeight = barHeight;
408 apply(mCurrentState);
409 }
410
Jason Monk421a9412017-02-06 09:15:21 -0800411 public void setForcePluginOpen(boolean forcePluginOpen) {
412 mCurrentState.forcePluginOpen = forcePluginOpen;
413 apply(mCurrentState);
414 }
415
416 public void setStateListener(OtherwisedCollapsedListener listener) {
417 mListener = listener;
418 }
419
Selim Cinek7025f262015-07-13 16:22:48 -0700420 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
421 pw.println("StatusBarWindowManager state:");
422 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200423 }
424
Adrian Roosd5c2db62016-03-08 16:11:31 -0800425 public boolean isShowingWallpaper() {
426 return !mCurrentState.backdropShowing;
427 }
428
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100429 private static class State {
430 boolean keyguardShowing;
431 boolean keyguardOccluded;
432 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700433 boolean panelVisible;
434 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100435 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200436 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200437 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200438 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700439 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700440 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700441 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700442 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800443 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800444 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700445 boolean wallpaperSupportsAmbientMode;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100446
Jorim Jaggiecbab362014-04-23 16:13:15 +0200447 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500448 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200449 */
450 int statusBarState;
451
Adrian Roos1c0ca502015-10-07 12:20:42 -0700452 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800453 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700454 boolean dozing;
Adrian Roosa5c63222017-07-27 16:33:39 +0200455 boolean scrimsVisible;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700456
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100457 private boolean isKeyguardShowingAndNotOccluded() {
458 return keyguardShowing && !keyguardOccluded;
459 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200460
461 @Override
462 public String toString() {
463 StringBuilder result = new StringBuilder();
464 String newLine = "\n";
465 result.append("Window State {");
466 result.append(newLine);
467
468 Field[] fields = this.getClass().getDeclaredFields();
469
470 // Print field names paired with their values
471 for (Field field : fields) {
472 result.append(" ");
473 try {
474 result.append(field.getName());
475 result.append(": ");
476 //requires access to private field:
477 result.append(field.get(this));
478 } catch (IllegalAccessException ex) {
479 }
480 result.append(newLine);
481 }
482 result.append("}");
483
484 return result.toString();
485 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100486 }
Jason Monk421a9412017-02-06 09:15:21 -0800487
488 /**
489 * Custom listener to pipe data back to plugins about whether or not the status bar would be
490 * collapsed if not for the plugin.
491 * TODO: Find cleaner way to do this.
492 */
493 public interface OtherwisedCollapsedListener {
494 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
495 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100496}