blob: c30f6339f8da1bd5acb209c37e57f54418f3dacc [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() &&
Lucas Dupin82aa1632017-12-13 00:13:57 -0800141 state.wallpaperSupportsAmbientMode &&
142 state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700143 if (state.keyguardShowing && !state.backdropShowing &&
144 (!state.dozing || showWallpaperOnAod)) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800145 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
146 } else {
147 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
148 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100149 }
150
151 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200152 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200153 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100154 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200155 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100156 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200157 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100158 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100159 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100160 }
161 }
162
163 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700164 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800165 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900166 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100167 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
168 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700169 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100170 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
171 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100172 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100173 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
174 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100175 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100176
Adrian Roos5153d4a2016-03-22 10:01:56 -0700177 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100178 }
179
180 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200181 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800182 if (state.forcePluginOpen) {
183 mListener.setWouldOtherwiseCollapse(expanded);
184 expanded = true;
185 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100186 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100187 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100188 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100189 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100190 }
191 }
192
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200193 private boolean isExpanded(State state) {
194 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
195 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800196 || state.headsUpShowing
197 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200198 }
199
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200200 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700201 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
202 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
203 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
204 mStatusBarView.requestApplyInsets();
205 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200206 }
207
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100208 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200209 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200210 && state.statusBarState == StatusBarState.KEYGUARD
211 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100212 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100213 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100214 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100215 }
216 }
217
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200218 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200219 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200220 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800221 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100222 mLpChanged.inputFeatures |=
223 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200224 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100225 mLpChanged.inputFeatures &=
226 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200227 }
228 }
229
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100230 private void apply(State state) {
231 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700232 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100233 applyFocusableFlag(state);
234 adjustScreenOrientation(state);
235 applyHeight(state);
236 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200237 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200238 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700239 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700240 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200241 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200242 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100243 if (mLp.copyFrom(mLpChanged) != 0) {
244 mWindowManager.updateViewLayout(mStatusBarView, mLp);
245 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200246 if (mHasTopUi != mHasTopUiChanged) {
247 try {
248 mActivityManager.setHasTopUi(mHasTopUiChanged);
249 } catch (RemoteException e) {
250 Log.e(TAG, "Failed to call setHasTopUi", e);
251 }
252 mHasTopUi = mHasTopUiChanged;
253 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100254 }
255
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700256 private void applyForceStatusBarVisibleFlag(State state) {
257 if (state.forceStatusBarVisible) {
258 mLpChanged.privateFlags |= WindowManager
259 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
260 } else {
261 mLpChanged.privateFlags &= ~WindowManager
262 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
263 }
264 }
265
Selim Cineka59ecc32015-04-07 10:51:49 -0700266 private void applyModalFlag(State state) {
267 if (state.headsUpShowing) {
268 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
269 } else {
270 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
271 }
272 }
273
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700274 private void applyBrightness(State state) {
275 if (state.forceDozeBrightness) {
276 mLpChanged.screenBrightness = mScreenBrightnessDoze;
277 } else {
278 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
279 }
280 }
281
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200282 private void applyHasTopUi(State state) {
283 mHasTopUiChanged = isExpanded(state);
284 }
285
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200286 private void applySleepToken(State state) {
287 if (state.dozing) {
288 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
289 } else {
290 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
291 }
292 }
293
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100294 public void setKeyguardShowing(boolean showing) {
295 mCurrentState.keyguardShowing = showing;
296 apply(mCurrentState);
297 }
298
299 public void setKeyguardOccluded(boolean occluded) {
300 mCurrentState.keyguardOccluded = occluded;
301 apply(mCurrentState);
302 }
303
304 public void setKeyguardNeedsInput(boolean needsInput) {
305 mCurrentState.keyguardNeedsInput = needsInput;
306 apply(mCurrentState);
307 }
308
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700309 public void setPanelVisible(boolean visible) {
310 mCurrentState.panelVisible = visible;
311 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100312 apply(mCurrentState);
313 }
314
315 public void setStatusBarFocusable(boolean focusable) {
316 mCurrentState.statusBarFocusable = focusable;
317 apply(mCurrentState);
318 }
319
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200320 public void setBouncerShowing(boolean showing) {
321 mCurrentState.bouncerShowing = showing;
322 apply(mCurrentState);
323 }
324
Adrian Roosd5c2db62016-03-08 16:11:31 -0800325 public void setBackdropShowing(boolean showing) {
326 mCurrentState.backdropShowing = showing;
327 apply(mCurrentState);
328 }
329
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200330 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
331 mCurrentState.keyguardFadingAway = keyguardFadingAway;
332 apply(mCurrentState);
333 }
334
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200335 public void setQsExpanded(boolean expanded) {
336 mCurrentState.qsExpanded = expanded;
337 apply(mCurrentState);
338 }
339
Vadim Tryshev6069c402016-03-09 14:24:29 -0800340 public void setForceUserActivity(boolean forceUserActivity) {
341 mCurrentState.forceUserActivity = forceUserActivity;
342 apply(mCurrentState);
343 }
344
Lucas Dupin82aa1632017-12-13 00:13:57 -0800345 public void setScrimsVisibility(int scrimsVisibility) {
346 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200347 apply(mCurrentState);
348 }
349
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700350 public void setHeadsUpShowing(boolean showing) {
351 mCurrentState.headsUpShowing = showing;
352 apply(mCurrentState);
353 }
354
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700355 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
356 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
357 apply(mCurrentState);
358 }
359
Jorim Jaggiecbab362014-04-23 16:13:15 +0200360 /**
361 * @param state The {@link StatusBarState} of the status bar.
362 */
363 public void setStatusBarState(int state) {
364 mCurrentState.statusBarState = state;
365 apply(mCurrentState);
366 }
367
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700368 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
369 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
370 apply(mCurrentState);
371 }
372
Selim Cinek737bff32015-05-08 16:08:35 -0700373 /**
374 * Force the window to be collapsed, even if it should theoretically be expanded.
375 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
376 * be computed.
377 */
378 public void setForceWindowCollapsed(boolean force) {
379 mCurrentState.forceCollapsed = force;
380 apply(mCurrentState);
381 }
382
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700383 public void setPanelExpanded(boolean isExpanded) {
384 mCurrentState.panelExpanded = isExpanded;
385 apply(mCurrentState);
386 }
387
Adrian Roosd28ccd72016-01-06 15:23:14 +0100388 @Override
389 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700390 mCurrentState.remoteInputActive = remoteInputActive;
391 apply(mCurrentState);
392 }
393
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700394 /**
395 * Set whether the screen brightness is forced to the value we use for doze mode by the status
396 * bar window.
397 */
398 public void setForceDozeBrightness(boolean forceDozeBrightness) {
399 mCurrentState.forceDozeBrightness = forceDozeBrightness;
400 apply(mCurrentState);
401 }
402
Adrian Roos67cca742017-04-13 16:52:51 -0700403 public void setDozing(boolean dozing) {
404 mCurrentState.dozing = dozing;
405 apply(mCurrentState);
406 }
407
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700408 public void setBarHeight(int barHeight) {
409 mBarHeight = barHeight;
410 apply(mCurrentState);
411 }
412
Jason Monk421a9412017-02-06 09:15:21 -0800413 public void setForcePluginOpen(boolean forcePluginOpen) {
414 mCurrentState.forcePluginOpen = forcePluginOpen;
415 apply(mCurrentState);
416 }
417
418 public void setStateListener(OtherwisedCollapsedListener listener) {
419 mListener = listener;
420 }
421
Selim Cinek7025f262015-07-13 16:22:48 -0700422 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
423 pw.println("StatusBarWindowManager state:");
424 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200425 }
426
Adrian Roosd5c2db62016-03-08 16:11:31 -0800427 public boolean isShowingWallpaper() {
428 return !mCurrentState.backdropShowing;
429 }
430
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100431 private static class State {
432 boolean keyguardShowing;
433 boolean keyguardOccluded;
434 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700435 boolean panelVisible;
436 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100437 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200438 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200439 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200440 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700441 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700442 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700443 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700444 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800445 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800446 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700447 boolean wallpaperSupportsAmbientMode;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100448
Jorim Jaggiecbab362014-04-23 16:13:15 +0200449 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500450 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200451 */
452 int statusBarState;
453
Adrian Roos1c0ca502015-10-07 12:20:42 -0700454 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800455 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700456 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800457 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700458
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100459 private boolean isKeyguardShowingAndNotOccluded() {
460 return keyguardShowing && !keyguardOccluded;
461 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200462
463 @Override
464 public String toString() {
465 StringBuilder result = new StringBuilder();
466 String newLine = "\n";
467 result.append("Window State {");
468 result.append(newLine);
469
470 Field[] fields = this.getClass().getDeclaredFields();
471
472 // Print field names paired with their values
473 for (Field field : fields) {
474 result.append(" ");
475 try {
476 result.append(field.getName());
477 result.append(": ");
478 //requires access to private field:
479 result.append(field.get(this));
480 } catch (IllegalAccessException ex) {
481 }
482 result.append(newLine);
483 }
484 result.append("}");
485
486 return result.toString();
487 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100488 }
Jason Monk421a9412017-02-06 09:15:21 -0800489
490 /**
491 * Custom listener to pipe data back to plugins about whether or not the status bar would be
492 * collapsed if not for the plugin.
493 * TODO: Find cleaner way to do this.
494 */
495 public interface OtherwisedCollapsedListener {
496 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
497 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100498}