blob: 46264f9dde1f98ae93e4126d6c12ede074278155 [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;
Jason Monke59dc402018-08-16 12:05:01 -040025import android.app.WallpaperManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010026import android.content.Context;
27import android.content.pm.ActivityInfo;
28import android.content.res.Resources;
29import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080030import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020031import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010032import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020033import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010034import android.view.Gravity;
35import android.view.View;
36import android.view.ViewGroup;
37import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020038import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010039
Lucas Dupina3e36272018-08-21 13:22:33 -070040import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010041import com.android.keyguard.R;
Jason Monk1fd3fc32018-08-14 17:20:09 -040042import com.android.systemui.Dependency;
Jason Monk421a9412017-02-06 09:15:21 -080043import com.android.systemui.Dumpable;
Jason Monke59dc402018-08-16 12:05:01 -040044import com.android.systemui.colorextraction.SysuiColorExtractor;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010045import com.android.systemui.keyguard.KeyguardViewMediator;
Jason Monke59dc402018-08-16 12:05:01 -040046import com.android.systemui.statusbar.RemoteInputController.Callback;
Jorim Jaggiecbab362014-04-23 16:13:15 +020047import com.android.systemui.statusbar.StatusBarState;
Jason Monk1fd3fc32018-08-14 17:20:09 -040048import com.android.systemui.statusbar.StatusBarStateController;
49import com.android.systemui.statusbar.StatusBarStateController.StateListener;
Jason Monke59dc402018-08-16 12:05:01 -040050import com.android.systemui.statusbar.policy.ConfigurationController;
51import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010052
Selim Cinek7025f262015-07-13 16:22:48 -070053import java.io.FileDescriptor;
54import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020055import java.lang.reflect.Field;
56
Jorim Jaggi5cf17872014-03-26 18:31:48 +010057/**
58 * Encapsulates all logic for the status bar window state management.
59 */
Jason Monke59dc402018-08-16 12:05:01 -040060public class StatusBarWindowController implements Callback, Dumpable, ConfigurationListener {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010061
Lucas Dupin1a8588d2018-08-21 12:18:47 -070062 private static final String TAG = "StatusBarWindowController";
Jorim Jaggif6782ee2016-07-22 11:40:00 +020063
Jorim Jaggi5cf17872014-03-26 18:31:48 +010064 private final Context mContext;
65 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020066 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070067 private final DozeParameters mDozeParameters;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068 private View mStatusBarView;
69 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010070 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020071 private boolean mHasTopUi;
72 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073 private int mBarHeight;
74 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020075 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010076 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080077 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078
Jason Monk1fd3fc32018-08-14 17:20:09 -040079 private final StateListener mStateListener = this::setStatusBarState;
Jason Monke59dc402018-08-16 12:05:01 -040080 private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Jason Monk1fd3fc32018-08-14 17:20:09 -040081
Lucas Dupin1a8588d2018-08-21 12:18:47 -070082 public StatusBarWindowController(Context context) {
Lucas Dupina3e36272018-08-21 13:22:33 -070083 this(context, context.getSystemService(WindowManager.class), ActivityManager.getService(),
84 DozeParameters.getInstance(context));
85 }
86
87 @VisibleForTesting
88 StatusBarWindowController(Context context, WindowManager windowManager,
89 IActivityManager activityManager, DozeParameters dozeParameters) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010090 mContext = context;
Lucas Dupina3e36272018-08-21 13:22:33 -070091 mWindowManager = windowManager;
92 mActivityManager = activityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010093 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupina3e36272018-08-21 13:22:33 -070094 mDozeParameters = dozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070095 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Jason Monk1fd3fc32018-08-14 17:20:09 -040096 Dependency.get(StatusBarStateController.class).addListener(mStateListener);
Jason Monke59dc402018-08-16 12:05:01 -040097 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +010098 }
99
100 private boolean shouldEnableKeyguardScreenRotation() {
101 Resources res = mContext.getResources();
102 return SystemProperties.getBoolean("lockscreen.rot_override", false)
103 || res.getBoolean(R.bool.config_enableLockScreenRotation);
104 }
105
106 /**
107 * Adds the status bar view to the window manager.
108 *
109 * @param statusBarView The view to add.
110 * @param barHeight The height of the status bar in collapsed state.
111 */
112 public void add(View statusBarView, int barHeight) {
113
114 // Now that the status bar window encompasses the sliding panel and its
115 // translucent backdrop, the entire thing is made TRANSLUCENT and is
116 // hardware-accelerated.
117 mLp = new WindowManager.LayoutParams(
118 ViewGroup.LayoutParams.MATCH_PARENT,
119 barHeight,
120 WindowManager.LayoutParams.TYPE_STATUS_BAR,
121 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
122 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
123 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
124 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200125 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100126 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800127 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200128 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100129 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100130 mLp.setTitle("StatusBar");
131 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100132 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 mStatusBarView = statusBarView;
134 mBarHeight = barHeight;
135 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100136 mLpChanged = new WindowManager.LayoutParams();
137 mLpChanged.copyFrom(mLp);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138 }
139
Adrian Roos3e23eb52017-07-07 15:58:57 +0200140 public void setDozeScreenBrightness(int value) {
141 mScreenBrightnessDoze = value / 255f;
142 }
143
Jason Monke59dc402018-08-16 12:05:01 -0400144 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700145 int vis = mStatusBarView.getSystemUiVisibility();
146 if (dark) {
147 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
148 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
149 } else {
150 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
151 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
152 }
153 mStatusBarView.setSystemUiVisibility(vis);
154 }
155
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100156 private void applyKeyguardFlags(State state) {
157 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100158 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100159 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100160 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100161 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800162
Lucas Dupin16cfe452018-02-08 13:14:50 -0800163 final boolean scrimsOccludingWallpaper =
164 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800165 final boolean keyguardOrAod = state.keyguardShowing
166 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000167 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800168 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
169 } else {
170 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
171 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700172
173 if (state.dozing) {
174 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
175 } else {
176 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
177 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100178 }
179
180 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200181 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200182 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100183 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200184 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100185 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200186 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100187 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100188 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100189 }
190 }
191
192 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700193 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800194 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900195 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100196 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
197 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700198 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100199 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
200 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100201 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100202 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
203 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100204 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100205
Adrian Roos5153d4a2016-03-22 10:01:56 -0700206 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100207 }
208
Tiger Huanga90dea42018-08-03 17:20:17 +0800209 private void applyForceShowNavigationFlag(State state) {
210 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800211 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800212 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800213 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800214 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800215 }
216 }
217
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100218 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200219 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800220 if (state.forcePluginOpen) {
221 mListener.setWouldOtherwiseCollapse(expanded);
222 expanded = true;
223 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100224 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100225 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100226 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100227 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100228 }
229 }
230
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200231 private boolean isExpanded(State state) {
232 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
233 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800234 || state.headsUpShowing
235 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200236 }
237
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200238 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700239 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
240 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
241 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
242 mStatusBarView.requestApplyInsets();
243 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200244 }
245
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100246 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200247 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200248 && state.statusBarState == StatusBarState.KEYGUARD
249 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100250 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100251 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100252 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100253 }
254 }
255
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200256 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200257 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200258 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800259 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100260 mLpChanged.inputFeatures |=
261 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200262 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100263 mLpChanged.inputFeatures &=
264 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200265 }
266 }
267
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100268 private void apply(State state) {
269 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700270 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100271 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800272 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100273 adjustScreenOrientation(state);
274 applyHeight(state);
275 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200276 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200277 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700278 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700279 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200280 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200281 applySleepToken(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100282 if (mLp.copyFrom(mLpChanged) != 0) {
283 mWindowManager.updateViewLayout(mStatusBarView, mLp);
284 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200285 if (mHasTopUi != mHasTopUiChanged) {
286 try {
287 mActivityManager.setHasTopUi(mHasTopUiChanged);
288 } catch (RemoteException e) {
289 Log.e(TAG, "Failed to call setHasTopUi", e);
290 }
291 mHasTopUi = mHasTopUiChanged;
292 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100293 }
294
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700295 private void applyForceStatusBarVisibleFlag(State state) {
296 if (state.forceStatusBarVisible) {
297 mLpChanged.privateFlags |= WindowManager
298 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
299 } else {
300 mLpChanged.privateFlags &= ~WindowManager
301 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
302 }
303 }
304
Selim Cineka59ecc32015-04-07 10:51:49 -0700305 private void applyModalFlag(State state) {
306 if (state.headsUpShowing) {
307 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
308 } else {
309 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
310 }
311 }
312
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700313 private void applyBrightness(State state) {
314 if (state.forceDozeBrightness) {
315 mLpChanged.screenBrightness = mScreenBrightnessDoze;
316 } else {
317 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
318 }
319 }
320
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200321 private void applyHasTopUi(State state) {
322 mHasTopUiChanged = isExpanded(state);
323 }
324
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200325 private void applySleepToken(State state) {
326 if (state.dozing) {
327 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
328 } else {
329 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
330 }
331 }
332
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100333 public void setKeyguardShowing(boolean showing) {
334 mCurrentState.keyguardShowing = showing;
335 apply(mCurrentState);
336 }
337
338 public void setKeyguardOccluded(boolean occluded) {
339 mCurrentState.keyguardOccluded = occluded;
340 apply(mCurrentState);
341 }
342
343 public void setKeyguardNeedsInput(boolean needsInput) {
344 mCurrentState.keyguardNeedsInput = needsInput;
345 apply(mCurrentState);
346 }
347
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700348 public void setPanelVisible(boolean visible) {
349 mCurrentState.panelVisible = visible;
350 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100351 apply(mCurrentState);
352 }
353
354 public void setStatusBarFocusable(boolean focusable) {
355 mCurrentState.statusBarFocusable = focusable;
356 apply(mCurrentState);
357 }
358
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200359 public void setBouncerShowing(boolean showing) {
360 mCurrentState.bouncerShowing = showing;
361 apply(mCurrentState);
362 }
363
Adrian Roosd5c2db62016-03-08 16:11:31 -0800364 public void setBackdropShowing(boolean showing) {
365 mCurrentState.backdropShowing = showing;
366 apply(mCurrentState);
367 }
368
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200369 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
370 mCurrentState.keyguardFadingAway = keyguardFadingAway;
371 apply(mCurrentState);
372 }
373
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200374 public void setQsExpanded(boolean expanded) {
375 mCurrentState.qsExpanded = expanded;
376 apply(mCurrentState);
377 }
378
Vadim Tryshev6069c402016-03-09 14:24:29 -0800379 public void setForceUserActivity(boolean forceUserActivity) {
380 mCurrentState.forceUserActivity = forceUserActivity;
381 apply(mCurrentState);
382 }
383
Lucas Dupin82aa1632017-12-13 00:13:57 -0800384 public void setScrimsVisibility(int scrimsVisibility) {
385 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200386 apply(mCurrentState);
387 }
388
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700389 public void setHeadsUpShowing(boolean showing) {
390 mCurrentState.headsUpShowing = showing;
391 apply(mCurrentState);
392 }
393
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700394 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
395 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
396 apply(mCurrentState);
397 }
398
Jorim Jaggiecbab362014-04-23 16:13:15 +0200399 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400400 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200401 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400402 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200403 mCurrentState.statusBarState = state;
404 apply(mCurrentState);
405 }
406
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700407 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
408 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
409 apply(mCurrentState);
410 }
411
Selim Cinek737bff32015-05-08 16:08:35 -0700412 /**
413 * Force the window to be collapsed, even if it should theoretically be expanded.
414 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
415 * be computed.
416 */
417 public void setForceWindowCollapsed(boolean force) {
418 mCurrentState.forceCollapsed = force;
419 apply(mCurrentState);
420 }
421
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700422 public void setPanelExpanded(boolean isExpanded) {
423 mCurrentState.panelExpanded = isExpanded;
424 apply(mCurrentState);
425 }
426
Adrian Roosd28ccd72016-01-06 15:23:14 +0100427 @Override
428 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700429 mCurrentState.remoteInputActive = remoteInputActive;
430 apply(mCurrentState);
431 }
432
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700433 /**
434 * Set whether the screen brightness is forced to the value we use for doze mode by the status
435 * bar window.
436 */
437 public void setForceDozeBrightness(boolean forceDozeBrightness) {
438 mCurrentState.forceDozeBrightness = forceDozeBrightness;
439 apply(mCurrentState);
440 }
441
Adrian Roos67cca742017-04-13 16:52:51 -0700442 public void setDozing(boolean dozing) {
443 mCurrentState.dozing = dozing;
444 apply(mCurrentState);
445 }
446
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700447 public void setBarHeight(int barHeight) {
448 mBarHeight = barHeight;
449 apply(mCurrentState);
450 }
451
Jason Monk421a9412017-02-06 09:15:21 -0800452 public void setForcePluginOpen(boolean forcePluginOpen) {
453 mCurrentState.forcePluginOpen = forcePluginOpen;
454 apply(mCurrentState);
455 }
456
457 public void setStateListener(OtherwisedCollapsedListener listener) {
458 mListener = listener;
459 }
460
Selim Cinek7025f262015-07-13 16:22:48 -0700461 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700462 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700463 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200464 }
465
Adrian Roosd5c2db62016-03-08 16:11:31 -0800466 public boolean isShowingWallpaper() {
467 return !mCurrentState.backdropShowing;
468 }
469
Jason Monke59dc402018-08-16 12:05:01 -0400470 @Override
471 public void onThemeChanged() {
472 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
473 int which;
474 if (state.getState() == StatusBarState.KEYGUARD
475 || state.getState() == StatusBarState.SHADE_LOCKED) {
476 which = WallpaperManager.FLAG_LOCK;
477 } else {
478 which = WallpaperManager.FLAG_SYSTEM;
479 }
480 final boolean useDarkText = mColorExtractor.getColors(which,
481 true /* ignoreVisibility */).supportsDarkText();
482
483 // Make sure we have the correct navbar/statusbar colors.
484 setKeyguardDark(useDarkText);
485 }
486
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100487 private static class State {
488 boolean keyguardShowing;
489 boolean keyguardOccluded;
490 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700491 boolean panelVisible;
492 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100493 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200494 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200495 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200496 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700497 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700498 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700499 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700500 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800501 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800502 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700503 boolean wallpaperSupportsAmbientMode;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100504
Jorim Jaggiecbab362014-04-23 16:13:15 +0200505 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500506 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200507 */
508 int statusBarState;
509
Adrian Roos1c0ca502015-10-07 12:20:42 -0700510 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800511 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700512 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800513 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700514
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100515 private boolean isKeyguardShowingAndNotOccluded() {
516 return keyguardShowing && !keyguardOccluded;
517 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200518
519 @Override
520 public String toString() {
521 StringBuilder result = new StringBuilder();
522 String newLine = "\n";
523 result.append("Window State {");
524 result.append(newLine);
525
526 Field[] fields = this.getClass().getDeclaredFields();
527
528 // Print field names paired with their values
529 for (Field field : fields) {
530 result.append(" ");
531 try {
532 result.append(field.getName());
533 result.append(": ");
534 //requires access to private field:
535 result.append(field.get(this));
536 } catch (IllegalAccessException ex) {
537 }
538 result.append(newLine);
539 }
540 result.append("}");
541
542 return result.toString();
543 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100544 }
Jason Monk421a9412017-02-06 09:15:21 -0800545
546 /**
547 * Custom listener to pipe data back to plugins about whether or not the status bar would be
548 * collapsed if not for the plugin.
549 * TODO: Find cleaner way to do this.
550 */
551 public interface OtherwisedCollapsedListener {
552 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
553 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100554}