blob: 0d37b550d4e0aa968924790659e46c981bf8204a [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();
Evan Laird91d0f102018-09-18 17:39:55 -040096 Dependency.get(StatusBarStateController.class).addListener(
97 mStateListener, StatusBarStateController.RANK_STATUS_BAR_WINDOW_CONTROLLER);
Jason Monke59dc402018-08-16 12:05:01 -040098 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +010099 }
100
101 private boolean shouldEnableKeyguardScreenRotation() {
102 Resources res = mContext.getResources();
103 return SystemProperties.getBoolean("lockscreen.rot_override", false)
104 || res.getBoolean(R.bool.config_enableLockScreenRotation);
105 }
106
107 /**
108 * Adds the status bar view to the window manager.
109 *
110 * @param statusBarView The view to add.
111 * @param barHeight The height of the status bar in collapsed state.
112 */
113 public void add(View statusBarView, int barHeight) {
114
115 // Now that the status bar window encompasses the sliding panel and its
116 // translucent backdrop, the entire thing is made TRANSLUCENT and is
117 // hardware-accelerated.
118 mLp = new WindowManager.LayoutParams(
119 ViewGroup.LayoutParams.MATCH_PARENT,
120 barHeight,
121 WindowManager.LayoutParams.TYPE_STATUS_BAR,
122 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
123 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
124 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
125 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200126 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100127 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800128 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200129 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100130 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100131 mLp.setTitle("StatusBar");
132 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100133 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100134 mStatusBarView = statusBarView;
135 mBarHeight = barHeight;
136 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100137 mLpChanged = new WindowManager.LayoutParams();
138 mLpChanged.copyFrom(mLp);
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700139 onThemeChanged();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100140 }
141
Adrian Roos3e23eb52017-07-07 15:58:57 +0200142 public void setDozeScreenBrightness(int value) {
143 mScreenBrightnessDoze = value / 255f;
144 }
145
Jason Monke59dc402018-08-16 12:05:01 -0400146 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700147 int vis = mStatusBarView.getSystemUiVisibility();
148 if (dark) {
149 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
150 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
151 } else {
152 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
153 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
154 }
155 mStatusBarView.setSystemUiVisibility(vis);
156 }
157
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100158 private void applyKeyguardFlags(State state) {
159 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100160 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100161 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100162 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100163 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800164
Lucas Dupin16cfe452018-02-08 13:14:50 -0800165 final boolean scrimsOccludingWallpaper =
166 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800167 final boolean keyguardOrAod = state.keyguardShowing
168 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000169 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800170 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
171 } else {
172 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
173 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700174
175 if (state.dozing) {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700176 mLpChanged.privateFlags |= LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700177 } else {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700178 mLpChanged.privateFlags &= ~LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700179 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100180 }
181
182 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200183 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200184 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100185 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200186 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100187 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200188 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100189 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100190 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100191 }
192 }
193
194 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700195 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800196 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900197 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100198 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
199 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700200 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100201 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
202 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100203 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100204 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
205 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100206 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100207
Adrian Roos5153d4a2016-03-22 10:01:56 -0700208 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100209 }
210
Tiger Huanga90dea42018-08-03 17:20:17 +0800211 private void applyForceShowNavigationFlag(State state) {
212 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800213 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
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 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800216 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800217 }
218 }
219
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100220 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200221 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800222 if (state.forcePluginOpen) {
223 mListener.setWouldOtherwiseCollapse(expanded);
224 expanded = true;
225 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100226 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100227 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100228 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100229 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100230 }
231 }
232
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200233 private boolean isExpanded(State state) {
234 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
235 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800236 || state.headsUpShowing
237 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200238 }
239
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200240 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700241 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
242 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
243 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
244 mStatusBarView.requestApplyInsets();
245 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200246 }
247
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100248 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200249 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200250 && state.statusBarState == StatusBarState.KEYGUARD
251 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100252 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100253 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100254 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100255 }
256 }
257
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200258 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200259 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200260 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800261 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100262 mLpChanged.inputFeatures |=
263 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200264 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100265 mLpChanged.inputFeatures &=
266 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200267 }
268 }
269
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100270 private void apply(State state) {
271 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700272 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100273 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800274 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100275 adjustScreenOrientation(state);
276 applyHeight(state);
277 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200278 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200279 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700280 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700281 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200282 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200283 applySleepToken(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700284 applyNotTouchable(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100285 if (mLp.copyFrom(mLpChanged) != 0) {
286 mWindowManager.updateViewLayout(mStatusBarView, mLp);
287 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200288 if (mHasTopUi != mHasTopUiChanged) {
289 try {
290 mActivityManager.setHasTopUi(mHasTopUiChanged);
291 } catch (RemoteException e) {
292 Log.e(TAG, "Failed to call setHasTopUi", e);
293 }
294 mHasTopUi = mHasTopUiChanged;
295 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100296 }
297
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700298 private void applyForceStatusBarVisibleFlag(State state) {
299 if (state.forceStatusBarVisible) {
300 mLpChanged.privateFlags |= WindowManager
301 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
302 } else {
303 mLpChanged.privateFlags &= ~WindowManager
304 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
305 }
306 }
307
Selim Cineka59ecc32015-04-07 10:51:49 -0700308 private void applyModalFlag(State state) {
309 if (state.headsUpShowing) {
310 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
311 } else {
312 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
313 }
314 }
315
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700316 private void applyBrightness(State state) {
317 if (state.forceDozeBrightness) {
318 mLpChanged.screenBrightness = mScreenBrightnessDoze;
319 } else {
320 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
321 }
322 }
323
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200324 private void applyHasTopUi(State state) {
325 mHasTopUiChanged = isExpanded(state);
326 }
327
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200328 private void applySleepToken(State state) {
329 if (state.dozing) {
330 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
331 } else {
332 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
333 }
334 }
335
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700336 private void applyNotTouchable(State state) {
337 if (state.notTouchable) {
338 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
339 } else {
340 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
341 }
342 }
343
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100344 public void setKeyguardShowing(boolean showing) {
345 mCurrentState.keyguardShowing = showing;
346 apply(mCurrentState);
347 }
348
349 public void setKeyguardOccluded(boolean occluded) {
350 mCurrentState.keyguardOccluded = occluded;
351 apply(mCurrentState);
352 }
353
354 public void setKeyguardNeedsInput(boolean needsInput) {
355 mCurrentState.keyguardNeedsInput = needsInput;
356 apply(mCurrentState);
357 }
358
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700359 public void setPanelVisible(boolean visible) {
360 mCurrentState.panelVisible = visible;
361 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100362 apply(mCurrentState);
363 }
364
365 public void setStatusBarFocusable(boolean focusable) {
366 mCurrentState.statusBarFocusable = focusable;
367 apply(mCurrentState);
368 }
369
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200370 public void setBouncerShowing(boolean showing) {
371 mCurrentState.bouncerShowing = showing;
372 apply(mCurrentState);
373 }
374
Adrian Roosd5c2db62016-03-08 16:11:31 -0800375 public void setBackdropShowing(boolean showing) {
376 mCurrentState.backdropShowing = showing;
377 apply(mCurrentState);
378 }
379
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200380 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
381 mCurrentState.keyguardFadingAway = keyguardFadingAway;
382 apply(mCurrentState);
383 }
384
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200385 public void setQsExpanded(boolean expanded) {
386 mCurrentState.qsExpanded = expanded;
387 apply(mCurrentState);
388 }
389
Vadim Tryshev6069c402016-03-09 14:24:29 -0800390 public void setForceUserActivity(boolean forceUserActivity) {
391 mCurrentState.forceUserActivity = forceUserActivity;
392 apply(mCurrentState);
393 }
394
Lucas Dupin82aa1632017-12-13 00:13:57 -0800395 public void setScrimsVisibility(int scrimsVisibility) {
396 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200397 apply(mCurrentState);
398 }
399
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700400 public void setHeadsUpShowing(boolean showing) {
401 mCurrentState.headsUpShowing = showing;
402 apply(mCurrentState);
403 }
404
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700405 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
406 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
407 apply(mCurrentState);
408 }
409
Jorim Jaggiecbab362014-04-23 16:13:15 +0200410 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400411 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200412 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400413 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200414 mCurrentState.statusBarState = state;
415 apply(mCurrentState);
416 }
417
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700418 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
419 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
420 apply(mCurrentState);
421 }
422
Selim Cinek737bff32015-05-08 16:08:35 -0700423 /**
424 * Force the window to be collapsed, even if it should theoretically be expanded.
425 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
426 * be computed.
427 */
428 public void setForceWindowCollapsed(boolean force) {
429 mCurrentState.forceCollapsed = force;
430 apply(mCurrentState);
431 }
432
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700433 public void setPanelExpanded(boolean isExpanded) {
434 mCurrentState.panelExpanded = isExpanded;
435 apply(mCurrentState);
436 }
437
Adrian Roosd28ccd72016-01-06 15:23:14 +0100438 @Override
439 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700440 mCurrentState.remoteInputActive = remoteInputActive;
441 apply(mCurrentState);
442 }
443
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700444 /**
445 * Set whether the screen brightness is forced to the value we use for doze mode by the status
446 * bar window.
447 */
448 public void setForceDozeBrightness(boolean forceDozeBrightness) {
449 mCurrentState.forceDozeBrightness = forceDozeBrightness;
450 apply(mCurrentState);
451 }
452
Adrian Roos67cca742017-04-13 16:52:51 -0700453 public void setDozing(boolean dozing) {
454 mCurrentState.dozing = dozing;
455 apply(mCurrentState);
456 }
457
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700458 public void setBarHeight(int barHeight) {
459 mBarHeight = barHeight;
460 apply(mCurrentState);
461 }
462
Jason Monk421a9412017-02-06 09:15:21 -0800463 public void setForcePluginOpen(boolean forcePluginOpen) {
464 mCurrentState.forcePluginOpen = forcePluginOpen;
465 apply(mCurrentState);
466 }
467
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700468 public void setNotTouchable(boolean notTouchable) {
469 mCurrentState.notTouchable = notTouchable;
470 apply(mCurrentState);
471 }
472
Jason Monk421a9412017-02-06 09:15:21 -0800473 public void setStateListener(OtherwisedCollapsedListener listener) {
474 mListener = listener;
475 }
476
Selim Cinek7025f262015-07-13 16:22:48 -0700477 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700478 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700479 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200480 }
481
Adrian Roosd5c2db62016-03-08 16:11:31 -0800482 public boolean isShowingWallpaper() {
483 return !mCurrentState.backdropShowing;
484 }
485
Jason Monke59dc402018-08-16 12:05:01 -0400486 @Override
487 public void onThemeChanged() {
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700488 if (mStatusBarView == null) {
489 return;
490 }
491
Jason Monke59dc402018-08-16 12:05:01 -0400492 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
493 int which;
494 if (state.getState() == StatusBarState.KEYGUARD
495 || state.getState() == StatusBarState.SHADE_LOCKED) {
496 which = WallpaperManager.FLAG_LOCK;
497 } else {
498 which = WallpaperManager.FLAG_SYSTEM;
499 }
500 final boolean useDarkText = mColorExtractor.getColors(which,
501 true /* ignoreVisibility */).supportsDarkText();
502
503 // Make sure we have the correct navbar/statusbar colors.
504 setKeyguardDark(useDarkText);
505 }
506
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100507 private static class State {
508 boolean keyguardShowing;
509 boolean keyguardOccluded;
510 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700511 boolean panelVisible;
512 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100513 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200514 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200515 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200516 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700517 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700518 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700519 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700520 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800521 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800522 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700523 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700524 boolean notTouchable;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100525
Jorim Jaggiecbab362014-04-23 16:13:15 +0200526 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500527 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200528 */
529 int statusBarState;
530
Adrian Roos1c0ca502015-10-07 12:20:42 -0700531 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800532 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700533 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800534 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700535
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100536 private boolean isKeyguardShowingAndNotOccluded() {
537 return keyguardShowing && !keyguardOccluded;
538 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200539
540 @Override
541 public String toString() {
542 StringBuilder result = new StringBuilder();
543 String newLine = "\n";
544 result.append("Window State {");
545 result.append(newLine);
546
547 Field[] fields = this.getClass().getDeclaredFields();
548
549 // Print field names paired with their values
550 for (Field field : fields) {
551 result.append(" ");
552 try {
553 result.append(field.getName());
554 result.append(": ");
555 //requires access to private field:
556 result.append(field.get(this));
557 } catch (IllegalAccessException ex) {
558 }
559 result.append(newLine);
560 }
561 result.append("}");
562
563 return result.toString();
564 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100565 }
Jason Monk421a9412017-02-06 09:15:21 -0800566
567 /**
568 * Custom listener to pipe data back to plugins about whether or not the status bar would be
569 * collapsed if not for the plugin.
570 * TODO: Find cleaner way to do this.
571 */
572 public interface OtherwisedCollapsedListener {
573 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
574 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100575}