blob: defb46ce27b2aa02f5ae15e68bc1eee8beb2b43c [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
Adrian Roos7b54b072018-03-08 12:52:22 +010019import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
20
Eliot Courtneye77edea2017-11-15 14:25:21 +090021import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
22
Sudheer Shankadc589ac2016-11-10 15:30:17 -080023import android.app.ActivityManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020024import android.app.IActivityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010025import android.content.Context;
26import android.content.pm.ActivityInfo;
27import android.content.res.Resources;
28import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080029import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020030import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010031import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020032import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010033import android.view.Gravity;
34import android.view.View;
35import android.view.ViewGroup;
36import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020037import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010038
39import com.android.keyguard.R;
Jason Monk421a9412017-02-06 09:15:21 -080040import com.android.systemui.Dumpable;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010041import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roosd28ccd72016-01-06 15:23:14 +010042import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020043import com.android.systemui.statusbar.StatusBarState;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010044
Selim Cinek7025f262015-07-13 16:22:48 -070045import java.io.FileDescriptor;
46import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020047import java.lang.reflect.Field;
48
Jorim Jaggi5cf17872014-03-26 18:31:48 +010049/**
50 * Encapsulates all logic for the status bar window state management.
51 */
Jason Monk421a9412017-02-06 09:15:21 -080052public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010053
Jorim Jaggif6782ee2016-07-22 11:40:00 +020054 private static final String TAG = "StatusBarWindowManager";
55
Jorim Jaggi5cf17872014-03-26 18:31:48 +010056 private final Context mContext;
57 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020058 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070059 private final DozeParameters mDozeParameters;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010060 private View mStatusBarView;
61 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010062 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020063 private boolean mHasTopUi;
64 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010065 private int mBarHeight;
66 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020067 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080069 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010070
71 public StatusBarWindowManager(Context context) {
72 mContext = context;
73 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Sudheer Shankadc589ac2016-11-10 15:30:17 -080074 mActivityManager = ActivityManager.getService();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010075 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupin7517b5d2017-08-22 12:51:25 -070076 mDozeParameters = new DozeParameters(mContext);
77 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078 }
79
80 private boolean shouldEnableKeyguardScreenRotation() {
81 Resources res = mContext.getResources();
82 return SystemProperties.getBoolean("lockscreen.rot_override", false)
83 || res.getBoolean(R.bool.config_enableLockScreenRotation);
84 }
85
86 /**
87 * Adds the status bar view to the window manager.
88 *
89 * @param statusBarView The view to add.
90 * @param barHeight The height of the status bar in collapsed state.
91 */
92 public void add(View statusBarView, int barHeight) {
93
94 // Now that the status bar window encompasses the sliding panel and its
95 // translucent backdrop, the entire thing is made TRANSLUCENT and is
96 // hardware-accelerated.
97 mLp = new WindowManager.LayoutParams(
98 ViewGroup.LayoutParams.MATCH_PARENT,
99 barHeight,
100 WindowManager.LayoutParams.TYPE_STATUS_BAR,
101 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
102 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
103 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
104 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200105 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100106 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800107 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200108 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100109 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100110 mLp.setTitle("StatusBar");
Phil Weaver8583ae82018-02-13 11:01:24 -0800111 mLp.accessibilityTitle = mContext.getString(R.string.status_bar);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100112 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100113 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100114 mStatusBarView = statusBarView;
115 mBarHeight = barHeight;
116 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100117 mLpChanged = new WindowManager.LayoutParams();
118 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100119 }
120
Adrian Roos3e23eb52017-07-07 15:58:57 +0200121 public void setDozeScreenBrightness(int value) {
122 mScreenBrightnessDoze = value / 255f;
123 }
124
Lucas Dupin987f1932017-05-13 21:02:52 -0700125 public void setKeyguardDark(boolean dark) {
126 int vis = mStatusBarView.getSystemUiVisibility();
127 if (dark) {
128 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
129 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
130 } else {
131 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
132 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
133 }
134 mStatusBarView.setSystemUiVisibility(vis);
135 }
136
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100137 private void applyKeyguardFlags(State state) {
138 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100139 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100140 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100141 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100142 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800143
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700144 final boolean showWallpaperOnAod = mDozeParameters.getAlwaysOn() &&
Lucas Dupin82aa1632017-12-13 00:13:57 -0800145 state.wallpaperSupportsAmbientMode &&
146 state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700147 if (state.keyguardShowing && !state.backdropShowing &&
148 (!state.dozing || showWallpaperOnAod)) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800149 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
150 } else {
151 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
152 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100153 }
154
155 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200156 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200157 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100158 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200159 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100160 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200161 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100162 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100163 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100164 }
165 }
166
167 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700168 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800169 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900170 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100171 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
172 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700173 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100174 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
175 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100176 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100177 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
178 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100179 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100180
Adrian Roos5153d4a2016-03-22 10:01:56 -0700181 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100182 }
183
184 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200185 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800186 if (state.forcePluginOpen) {
187 mListener.setWouldOtherwiseCollapse(expanded);
188 expanded = true;
189 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100190 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100191 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100192 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100193 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100194 }
195 }
196
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200197 private boolean isExpanded(State state) {
198 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
199 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800200 || state.headsUpShowing
201 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200202 }
203
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200204 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700205 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
206 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
207 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
208 mStatusBarView.requestApplyInsets();
209 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200210 }
211
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100212 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200213 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200214 && state.statusBarState == StatusBarState.KEYGUARD
215 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100216 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100217 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100218 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100219 }
220 }
221
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200222 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200223 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200224 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800225 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100226 mLpChanged.inputFeatures |=
227 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200228 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100229 mLpChanged.inputFeatures &=
230 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200231 }
232 }
233
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100234 private void apply(State state) {
235 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700236 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100237 applyFocusableFlag(state);
238 adjustScreenOrientation(state);
239 applyHeight(state);
240 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200241 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200242 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700243 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700244 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200245 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200246 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100247 if (mLp.copyFrom(mLpChanged) != 0) {
248 mWindowManager.updateViewLayout(mStatusBarView, mLp);
249 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200250 if (mHasTopUi != mHasTopUiChanged) {
251 try {
252 mActivityManager.setHasTopUi(mHasTopUiChanged);
253 } catch (RemoteException e) {
254 Log.e(TAG, "Failed to call setHasTopUi", e);
255 }
256 mHasTopUi = mHasTopUiChanged;
257 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100258 }
259
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700260 private void applyForceStatusBarVisibleFlag(State state) {
261 if (state.forceStatusBarVisible) {
262 mLpChanged.privateFlags |= WindowManager
263 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
264 } else {
265 mLpChanged.privateFlags &= ~WindowManager
266 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
267 }
268 }
269
Selim Cineka59ecc32015-04-07 10:51:49 -0700270 private void applyModalFlag(State state) {
271 if (state.headsUpShowing) {
272 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
273 } else {
274 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
275 }
276 }
277
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700278 private void applyBrightness(State state) {
279 if (state.forceDozeBrightness) {
280 mLpChanged.screenBrightness = mScreenBrightnessDoze;
281 } else {
282 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
283 }
284 }
285
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200286 private void applyHasTopUi(State state) {
287 mHasTopUiChanged = isExpanded(state);
288 }
289
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200290 private void applySleepToken(State state) {
291 if (state.dozing) {
292 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
293 } else {
294 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
295 }
296 }
297
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100298 public void setKeyguardShowing(boolean showing) {
299 mCurrentState.keyguardShowing = showing;
300 apply(mCurrentState);
301 }
302
303 public void setKeyguardOccluded(boolean occluded) {
304 mCurrentState.keyguardOccluded = occluded;
305 apply(mCurrentState);
306 }
307
308 public void setKeyguardNeedsInput(boolean needsInput) {
309 mCurrentState.keyguardNeedsInput = needsInput;
310 apply(mCurrentState);
311 }
312
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700313 public void setPanelVisible(boolean visible) {
314 mCurrentState.panelVisible = visible;
315 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100316 apply(mCurrentState);
317 }
318
319 public void setStatusBarFocusable(boolean focusable) {
320 mCurrentState.statusBarFocusable = focusable;
321 apply(mCurrentState);
322 }
323
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200324 public void setBouncerShowing(boolean showing) {
325 mCurrentState.bouncerShowing = showing;
326 apply(mCurrentState);
327 }
328
Adrian Roosd5c2db62016-03-08 16:11:31 -0800329 public void setBackdropShowing(boolean showing) {
330 mCurrentState.backdropShowing = showing;
331 apply(mCurrentState);
332 }
333
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200334 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
335 mCurrentState.keyguardFadingAway = keyguardFadingAway;
336 apply(mCurrentState);
337 }
338
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200339 public void setQsExpanded(boolean expanded) {
340 mCurrentState.qsExpanded = expanded;
341 apply(mCurrentState);
342 }
343
Vadim Tryshev6069c402016-03-09 14:24:29 -0800344 public void setForceUserActivity(boolean forceUserActivity) {
345 mCurrentState.forceUserActivity = forceUserActivity;
346 apply(mCurrentState);
347 }
348
Lucas Dupin82aa1632017-12-13 00:13:57 -0800349 public void setScrimsVisibility(int scrimsVisibility) {
350 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200351 apply(mCurrentState);
352 }
353
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700354 public void setHeadsUpShowing(boolean showing) {
355 mCurrentState.headsUpShowing = showing;
356 apply(mCurrentState);
357 }
358
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700359 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
360 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
361 apply(mCurrentState);
362 }
363
Jorim Jaggiecbab362014-04-23 16:13:15 +0200364 /**
365 * @param state The {@link StatusBarState} of the status bar.
366 */
367 public void setStatusBarState(int state) {
368 mCurrentState.statusBarState = state;
369 apply(mCurrentState);
370 }
371
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700372 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
373 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
374 apply(mCurrentState);
375 }
376
Selim Cinek737bff32015-05-08 16:08:35 -0700377 /**
378 * Force the window to be collapsed, even if it should theoretically be expanded.
379 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
380 * be computed.
381 */
382 public void setForceWindowCollapsed(boolean force) {
383 mCurrentState.forceCollapsed = force;
384 apply(mCurrentState);
385 }
386
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700387 public void setPanelExpanded(boolean isExpanded) {
388 mCurrentState.panelExpanded = isExpanded;
389 apply(mCurrentState);
390 }
391
Adrian Roosd28ccd72016-01-06 15:23:14 +0100392 @Override
393 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700394 mCurrentState.remoteInputActive = remoteInputActive;
395 apply(mCurrentState);
396 }
397
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700398 /**
399 * Set whether the screen brightness is forced to the value we use for doze mode by the status
400 * bar window.
401 */
402 public void setForceDozeBrightness(boolean forceDozeBrightness) {
403 mCurrentState.forceDozeBrightness = forceDozeBrightness;
404 apply(mCurrentState);
405 }
406
Adrian Roos67cca742017-04-13 16:52:51 -0700407 public void setDozing(boolean dozing) {
408 mCurrentState.dozing = dozing;
409 apply(mCurrentState);
410 }
411
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700412 public void setBarHeight(int barHeight) {
413 mBarHeight = barHeight;
414 apply(mCurrentState);
415 }
416
Jason Monk421a9412017-02-06 09:15:21 -0800417 public void setForcePluginOpen(boolean forcePluginOpen) {
418 mCurrentState.forcePluginOpen = forcePluginOpen;
419 apply(mCurrentState);
420 }
421
422 public void setStateListener(OtherwisedCollapsedListener listener) {
423 mListener = listener;
424 }
425
Selim Cinek7025f262015-07-13 16:22:48 -0700426 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
427 pw.println("StatusBarWindowManager state:");
428 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200429 }
430
Adrian Roosd5c2db62016-03-08 16:11:31 -0800431 public boolean isShowingWallpaper() {
432 return !mCurrentState.backdropShowing;
433 }
434
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100435 private static class State {
436 boolean keyguardShowing;
437 boolean keyguardOccluded;
438 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700439 boolean panelVisible;
440 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100441 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200442 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200443 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200444 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700445 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700446 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700447 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700448 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800449 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800450 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700451 boolean wallpaperSupportsAmbientMode;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100452
Jorim Jaggiecbab362014-04-23 16:13:15 +0200453 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500454 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200455 */
456 int statusBarState;
457
Adrian Roos1c0ca502015-10-07 12:20:42 -0700458 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800459 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700460 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800461 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700462
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100463 private boolean isKeyguardShowingAndNotOccluded() {
464 return keyguardShowing && !keyguardOccluded;
465 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200466
467 @Override
468 public String toString() {
469 StringBuilder result = new StringBuilder();
470 String newLine = "\n";
471 result.append("Window State {");
472 result.append(newLine);
473
474 Field[] fields = this.getClass().getDeclaredFields();
475
476 // Print field names paired with their values
477 for (Field field : fields) {
478 result.append(" ");
479 try {
480 result.append(field.getName());
481 result.append(": ");
482 //requires access to private field:
483 result.append(field.get(this));
484 } catch (IllegalAccessException ex) {
485 }
486 result.append(newLine);
487 }
488 result.append("}");
489
490 return result.toString();
491 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100492 }
Jason Monk421a9412017-02-06 09:15:21 -0800493
494 /**
495 * Custom listener to pipe data back to plugins about whether or not the status bar would be
496 * collapsed if not for the plugin.
497 * TODO: Find cleaner way to do this.
498 */
499 public interface OtherwisedCollapsedListener {
500 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
501 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100502}