blob: b0b5b8ec1e09a0c44cf1ab624716125547f2e0ee [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;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010057 private View mStatusBarView;
58 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010059 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020060 private boolean mHasTopUi;
61 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010062 private int mBarHeight;
63 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020064 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010065 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080066 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010067
68 public StatusBarWindowManager(Context context) {
69 mContext = context;
70 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080071 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010072 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070073 mScreenBrightnessDoze = mContext.getResources().getInteger(
74 com.android.internal.R.integer.config_screenBrightnessDoze) / 255f;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010075 }
76
77 private boolean shouldEnableKeyguardScreenRotation() {
78 Resources res = mContext.getResources();
79 return SystemProperties.getBoolean("lockscreen.rot_override", false)
80 || res.getBoolean(R.bool.config_enableLockScreenRotation);
81 }
82
83 /**
84 * Adds the status bar view to the window manager.
85 *
86 * @param statusBarView The view to add.
87 * @param barHeight The height of the status bar in collapsed state.
88 */
89 public void add(View statusBarView, int barHeight) {
90
91 // Now that the status bar window encompasses the sliding panel and its
92 // translucent backdrop, the entire thing is made TRANSLUCENT and is
93 // hardware-accelerated.
94 mLp = new WindowManager.LayoutParams(
95 ViewGroup.LayoutParams.MATCH_PARENT,
96 barHeight,
97 WindowManager.LayoutParams.TYPE_STATUS_BAR,
98 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
99 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
100 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
101 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200102 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100103 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800104 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200105 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100106 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100107 mLp.setTitle("StatusBar");
108 mLp.packageName = mContext.getPackageName();
109 mStatusBarView = statusBarView;
110 mBarHeight = barHeight;
111 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100112 mLpChanged = new WindowManager.LayoutParams();
113 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100114 }
115
Adrian Roos3e23eb52017-07-07 15:58:57 +0200116 public void setDozeScreenBrightness(int value) {
117 mScreenBrightnessDoze = value / 255f;
118 }
119
Lucas Dupin987f1932017-05-13 21:02:52 -0700120 public void setKeyguardDark(boolean dark) {
121 int vis = mStatusBarView.getSystemUiVisibility();
122 if (dark) {
123 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
124 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
125 } else {
126 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
127 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
128 }
129 mStatusBarView.setSystemUiVisibility(vis);
130 }
131
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100132 private void applyKeyguardFlags(State state) {
133 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100134 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100136 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100137 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800138
Adrian Roos67cca742017-04-13 16:52:51 -0700139 if (state.keyguardShowing && !state.backdropShowing && !state.dozing) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800140 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
141 } else {
142 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
143 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100144 }
145
146 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200147 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200148 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100149 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200150 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100151 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200152 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100153 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100154 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100155 }
156 }
157
158 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700159 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800160 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900161 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100162 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
163 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700164 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100165 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
166 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100167 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100168 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
169 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100170 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100171
Adrian Roos5153d4a2016-03-22 10:01:56 -0700172 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100173 }
174
175 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200176 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800177 if (state.forcePluginOpen) {
178 mListener.setWouldOtherwiseCollapse(expanded);
179 expanded = true;
180 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100181 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100182 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100183 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100184 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100185 }
186 }
187
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200188 private boolean isExpanded(State state) {
189 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
190 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Adrian Roosa5c63222017-07-27 16:33:39 +0200191 || state.headsUpShowing || state.scrimsVisible);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200192 }
193
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200194 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700195 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
196 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
197 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
198 mStatusBarView.requestApplyInsets();
199 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200200 }
201
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100202 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200203 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200204 && state.statusBarState == StatusBarState.KEYGUARD
205 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100206 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100207 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100208 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100209 }
210 }
211
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200212 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200213 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200214 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800215 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100216 mLpChanged.inputFeatures |=
217 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200218 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100219 mLpChanged.inputFeatures &=
220 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200221 }
222 }
223
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100224 private void apply(State state) {
225 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700226 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100227 applyFocusableFlag(state);
228 adjustScreenOrientation(state);
229 applyHeight(state);
230 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200231 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200232 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700233 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700234 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200235 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200236 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100237 if (mLp.copyFrom(mLpChanged) != 0) {
238 mWindowManager.updateViewLayout(mStatusBarView, mLp);
239 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200240 if (mHasTopUi != mHasTopUiChanged) {
241 try {
242 mActivityManager.setHasTopUi(mHasTopUiChanged);
243 } catch (RemoteException e) {
244 Log.e(TAG, "Failed to call setHasTopUi", e);
245 }
246 mHasTopUi = mHasTopUiChanged;
247 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100248 }
249
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700250 private void applyForceStatusBarVisibleFlag(State state) {
251 if (state.forceStatusBarVisible) {
252 mLpChanged.privateFlags |= WindowManager
253 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
254 } else {
255 mLpChanged.privateFlags &= ~WindowManager
256 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
257 }
258 }
259
Selim Cineka59ecc32015-04-07 10:51:49 -0700260 private void applyModalFlag(State state) {
261 if (state.headsUpShowing) {
262 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
263 } else {
264 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
265 }
266 }
267
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700268 private void applyBrightness(State state) {
269 if (state.forceDozeBrightness) {
270 mLpChanged.screenBrightness = mScreenBrightnessDoze;
271 } else {
272 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
273 }
274 }
275
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200276 private void applyHasTopUi(State state) {
277 mHasTopUiChanged = isExpanded(state);
278 }
279
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200280 private void applySleepToken(State state) {
281 if (state.dozing) {
282 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
283 } else {
284 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
285 }
286 }
287
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100288 public void setKeyguardShowing(boolean showing) {
289 mCurrentState.keyguardShowing = showing;
290 apply(mCurrentState);
291 }
292
293 public void setKeyguardOccluded(boolean occluded) {
294 mCurrentState.keyguardOccluded = occluded;
295 apply(mCurrentState);
296 }
297
298 public void setKeyguardNeedsInput(boolean needsInput) {
299 mCurrentState.keyguardNeedsInput = needsInput;
300 apply(mCurrentState);
301 }
302
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700303 public void setPanelVisible(boolean visible) {
304 mCurrentState.panelVisible = visible;
305 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100306 apply(mCurrentState);
307 }
308
309 public void setStatusBarFocusable(boolean focusable) {
310 mCurrentState.statusBarFocusable = focusable;
311 apply(mCurrentState);
312 }
313
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200314 public void setBouncerShowing(boolean showing) {
315 mCurrentState.bouncerShowing = showing;
316 apply(mCurrentState);
317 }
318
Adrian Roosd5c2db62016-03-08 16:11:31 -0800319 public void setBackdropShowing(boolean showing) {
320 mCurrentState.backdropShowing = showing;
321 apply(mCurrentState);
322 }
323
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200324 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
325 mCurrentState.keyguardFadingAway = keyguardFadingAway;
326 apply(mCurrentState);
327 }
328
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200329 public void setQsExpanded(boolean expanded) {
330 mCurrentState.qsExpanded = expanded;
331 apply(mCurrentState);
332 }
333
Vadim Tryshev6069c402016-03-09 14:24:29 -0800334 public void setForceUserActivity(boolean forceUserActivity) {
335 mCurrentState.forceUserActivity = forceUserActivity;
336 apply(mCurrentState);
337 }
338
Adrian Roosa5c63222017-07-27 16:33:39 +0200339 public void setScrimsVisible(boolean scrimsVisible) {
340 mCurrentState.scrimsVisible = scrimsVisible;
341 apply(mCurrentState);
342 }
343
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700344 public void setHeadsUpShowing(boolean showing) {
345 mCurrentState.headsUpShowing = showing;
346 apply(mCurrentState);
347 }
348
Jorim Jaggiecbab362014-04-23 16:13:15 +0200349 /**
350 * @param state The {@link StatusBarState} of the status bar.
351 */
352 public void setStatusBarState(int state) {
353 mCurrentState.statusBarState = state;
354 apply(mCurrentState);
355 }
356
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700357 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
358 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
359 apply(mCurrentState);
360 }
361
Selim Cinek737bff32015-05-08 16:08:35 -0700362 /**
363 * Force the window to be collapsed, even if it should theoretically be expanded.
364 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
365 * be computed.
366 */
367 public void setForceWindowCollapsed(boolean force) {
368 mCurrentState.forceCollapsed = force;
369 apply(mCurrentState);
370 }
371
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700372 public void setPanelExpanded(boolean isExpanded) {
373 mCurrentState.panelExpanded = isExpanded;
374 apply(mCurrentState);
375 }
376
Adrian Roosd28ccd72016-01-06 15:23:14 +0100377 @Override
378 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700379 mCurrentState.remoteInputActive = remoteInputActive;
380 apply(mCurrentState);
381 }
382
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700383 /**
384 * Set whether the screen brightness is forced to the value we use for doze mode by the status
385 * bar window.
386 */
387 public void setForceDozeBrightness(boolean forceDozeBrightness) {
388 mCurrentState.forceDozeBrightness = forceDozeBrightness;
389 apply(mCurrentState);
390 }
391
Adrian Roos67cca742017-04-13 16:52:51 -0700392 public void setDozing(boolean dozing) {
393 mCurrentState.dozing = dozing;
394 apply(mCurrentState);
395 }
396
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700397 public void setBarHeight(int barHeight) {
398 mBarHeight = barHeight;
399 apply(mCurrentState);
400 }
401
Jason Monk421a9412017-02-06 09:15:21 -0800402 public void setForcePluginOpen(boolean forcePluginOpen) {
403 mCurrentState.forcePluginOpen = forcePluginOpen;
404 apply(mCurrentState);
405 }
406
407 public void setStateListener(OtherwisedCollapsedListener listener) {
408 mListener = listener;
409 }
410
Selim Cinek7025f262015-07-13 16:22:48 -0700411 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
412 pw.println("StatusBarWindowManager state:");
413 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200414 }
415
Adrian Roosd5c2db62016-03-08 16:11:31 -0800416 public boolean isShowingWallpaper() {
417 return !mCurrentState.backdropShowing;
418 }
419
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100420 private static class State {
421 boolean keyguardShowing;
422 boolean keyguardOccluded;
423 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700424 boolean panelVisible;
425 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100426 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200427 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200428 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200429 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700430 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700431 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700432 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700433 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800434 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800435 boolean backdropShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100436
Jorim Jaggiecbab362014-04-23 16:13:15 +0200437 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500438 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200439 */
440 int statusBarState;
441
Adrian Roos1c0ca502015-10-07 12:20:42 -0700442 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800443 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700444 boolean dozing;
Adrian Roosa5c63222017-07-27 16:33:39 +0200445 boolean scrimsVisible;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700446
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100447 private boolean isKeyguardShowingAndNotOccluded() {
448 return keyguardShowing && !keyguardOccluded;
449 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200450
451 @Override
452 public String toString() {
453 StringBuilder result = new StringBuilder();
454 String newLine = "\n";
455 result.append("Window State {");
456 result.append(newLine);
457
458 Field[] fields = this.getClass().getDeclaredFields();
459
460 // Print field names paired with their values
461 for (Field field : fields) {
462 result.append(" ");
463 try {
464 result.append(field.getName());
465 result.append(": ");
466 //requires access to private field:
467 result.append(field.get(this));
468 } catch (IllegalAccessException ex) {
469 }
470 result.append(newLine);
471 }
472 result.append("}");
473
474 return result.toString();
475 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100476 }
Jason Monk421a9412017-02-06 09:15:21 -0800477
478 /**
479 * Custom listener to pipe data back to plugins about whether or not the status bar would be
480 * collapsed if not for the plugin.
481 * TODO: Find cleaner way to do this.
482 */
483 public interface OtherwisedCollapsedListener {
484 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
485 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100486}