blob: 200964c760a0c49cb3d5eea7d9d490cb3a582983 [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);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100139 }
140
Adrian Roos3e23eb52017-07-07 15:58:57 +0200141 public void setDozeScreenBrightness(int value) {
142 mScreenBrightnessDoze = value / 255f;
143 }
144
Jason Monke59dc402018-08-16 12:05:01 -0400145 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700146 int vis = mStatusBarView.getSystemUiVisibility();
147 if (dark) {
148 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
149 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
150 } else {
151 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
152 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
153 }
154 mStatusBarView.setSystemUiVisibility(vis);
155 }
156
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100157 private void applyKeyguardFlags(State state) {
158 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100159 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100160 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100161 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100162 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800163
Lucas Dupin16cfe452018-02-08 13:14:50 -0800164 final boolean scrimsOccludingWallpaper =
165 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800166 final boolean keyguardOrAod = state.keyguardShowing
167 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000168 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800169 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
170 } else {
171 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
172 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700173
174 if (state.dozing) {
175 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
176 } else {
177 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
178 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100179 }
180
181 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200182 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200183 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100184 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200185 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100186 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200187 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100188 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100189 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100190 }
191 }
192
193 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700194 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800195 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900196 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100197 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
198 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700199 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100200 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
201 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100202 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100203 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
204 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100205 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100206
Adrian Roos5153d4a2016-03-22 10:01:56 -0700207 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100208 }
209
Tiger Huanga90dea42018-08-03 17:20:17 +0800210 private void applyForceShowNavigationFlag(State state) {
211 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800212 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800213 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800214 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800215 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800216 }
217 }
218
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100219 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200220 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800221 if (state.forcePluginOpen) {
222 mListener.setWouldOtherwiseCollapse(expanded);
223 expanded = true;
224 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100225 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100226 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100227 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100228 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100229 }
230 }
231
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200232 private boolean isExpanded(State state) {
233 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
234 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800235 || state.headsUpShowing
236 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200237 }
238
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200239 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700240 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
241 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
242 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
243 mStatusBarView.requestApplyInsets();
244 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200245 }
246
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100247 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200248 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200249 && state.statusBarState == StatusBarState.KEYGUARD
250 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100251 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100252 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100253 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100254 }
255 }
256
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200257 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200258 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200259 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800260 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100261 mLpChanged.inputFeatures |=
262 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200263 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100264 mLpChanged.inputFeatures &=
265 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200266 }
267 }
268
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100269 private void apply(State state) {
270 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700271 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100272 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800273 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100274 adjustScreenOrientation(state);
275 applyHeight(state);
276 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200277 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200278 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700279 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700280 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200281 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200282 applySleepToken(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700283 applyNotTouchable(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100284 if (mLp.copyFrom(mLpChanged) != 0) {
285 mWindowManager.updateViewLayout(mStatusBarView, mLp);
286 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200287 if (mHasTopUi != mHasTopUiChanged) {
288 try {
289 mActivityManager.setHasTopUi(mHasTopUiChanged);
290 } catch (RemoteException e) {
291 Log.e(TAG, "Failed to call setHasTopUi", e);
292 }
293 mHasTopUi = mHasTopUiChanged;
294 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100295 }
296
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700297 private void applyForceStatusBarVisibleFlag(State state) {
298 if (state.forceStatusBarVisible) {
299 mLpChanged.privateFlags |= WindowManager
300 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
301 } else {
302 mLpChanged.privateFlags &= ~WindowManager
303 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
304 }
305 }
306
Selim Cineka59ecc32015-04-07 10:51:49 -0700307 private void applyModalFlag(State state) {
308 if (state.headsUpShowing) {
309 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
310 } else {
311 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
312 }
313 }
314
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700315 private void applyBrightness(State state) {
316 if (state.forceDozeBrightness) {
317 mLpChanged.screenBrightness = mScreenBrightnessDoze;
318 } else {
319 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
320 }
321 }
322
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200323 private void applyHasTopUi(State state) {
324 mHasTopUiChanged = isExpanded(state);
325 }
326
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200327 private void applySleepToken(State state) {
328 if (state.dozing) {
329 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
330 } else {
331 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
332 }
333 }
334
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700335 private void applyNotTouchable(State state) {
336 if (state.notTouchable) {
337 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
338 } else {
339 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
340 }
341 }
342
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100343 public void setKeyguardShowing(boolean showing) {
344 mCurrentState.keyguardShowing = showing;
345 apply(mCurrentState);
346 }
347
348 public void setKeyguardOccluded(boolean occluded) {
349 mCurrentState.keyguardOccluded = occluded;
350 apply(mCurrentState);
351 }
352
353 public void setKeyguardNeedsInput(boolean needsInput) {
354 mCurrentState.keyguardNeedsInput = needsInput;
355 apply(mCurrentState);
356 }
357
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700358 public void setPanelVisible(boolean visible) {
359 mCurrentState.panelVisible = visible;
360 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100361 apply(mCurrentState);
362 }
363
364 public void setStatusBarFocusable(boolean focusable) {
365 mCurrentState.statusBarFocusable = focusable;
366 apply(mCurrentState);
367 }
368
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200369 public void setBouncerShowing(boolean showing) {
370 mCurrentState.bouncerShowing = showing;
371 apply(mCurrentState);
372 }
373
Adrian Roosd5c2db62016-03-08 16:11:31 -0800374 public void setBackdropShowing(boolean showing) {
375 mCurrentState.backdropShowing = showing;
376 apply(mCurrentState);
377 }
378
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200379 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
380 mCurrentState.keyguardFadingAway = keyguardFadingAway;
381 apply(mCurrentState);
382 }
383
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200384 public void setQsExpanded(boolean expanded) {
385 mCurrentState.qsExpanded = expanded;
386 apply(mCurrentState);
387 }
388
Vadim Tryshev6069c402016-03-09 14:24:29 -0800389 public void setForceUserActivity(boolean forceUserActivity) {
390 mCurrentState.forceUserActivity = forceUserActivity;
391 apply(mCurrentState);
392 }
393
Lucas Dupin82aa1632017-12-13 00:13:57 -0800394 public void setScrimsVisibility(int scrimsVisibility) {
395 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200396 apply(mCurrentState);
397 }
398
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700399 public void setHeadsUpShowing(boolean showing) {
400 mCurrentState.headsUpShowing = showing;
401 apply(mCurrentState);
402 }
403
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700404 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
405 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
406 apply(mCurrentState);
407 }
408
Jorim Jaggiecbab362014-04-23 16:13:15 +0200409 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400410 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200411 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400412 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200413 mCurrentState.statusBarState = state;
414 apply(mCurrentState);
415 }
416
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700417 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
418 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
419 apply(mCurrentState);
420 }
421
Selim Cinek737bff32015-05-08 16:08:35 -0700422 /**
423 * Force the window to be collapsed, even if it should theoretically be expanded.
424 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
425 * be computed.
426 */
427 public void setForceWindowCollapsed(boolean force) {
428 mCurrentState.forceCollapsed = force;
429 apply(mCurrentState);
430 }
431
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700432 public void setPanelExpanded(boolean isExpanded) {
433 mCurrentState.panelExpanded = isExpanded;
434 apply(mCurrentState);
435 }
436
Adrian Roosd28ccd72016-01-06 15:23:14 +0100437 @Override
438 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700439 mCurrentState.remoteInputActive = remoteInputActive;
440 apply(mCurrentState);
441 }
442
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700443 /**
444 * Set whether the screen brightness is forced to the value we use for doze mode by the status
445 * bar window.
446 */
447 public void setForceDozeBrightness(boolean forceDozeBrightness) {
448 mCurrentState.forceDozeBrightness = forceDozeBrightness;
449 apply(mCurrentState);
450 }
451
Adrian Roos67cca742017-04-13 16:52:51 -0700452 public void setDozing(boolean dozing) {
453 mCurrentState.dozing = dozing;
454 apply(mCurrentState);
455 }
456
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700457 public void setBarHeight(int barHeight) {
458 mBarHeight = barHeight;
459 apply(mCurrentState);
460 }
461
Jason Monk421a9412017-02-06 09:15:21 -0800462 public void setForcePluginOpen(boolean forcePluginOpen) {
463 mCurrentState.forcePluginOpen = forcePluginOpen;
464 apply(mCurrentState);
465 }
466
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700467 public void setNotTouchable(boolean notTouchable) {
468 mCurrentState.notTouchable = notTouchable;
469 apply(mCurrentState);
470 }
471
Jason Monk421a9412017-02-06 09:15:21 -0800472 public void setStateListener(OtherwisedCollapsedListener listener) {
473 mListener = listener;
474 }
475
Selim Cinek7025f262015-07-13 16:22:48 -0700476 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700477 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700478 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200479 }
480
Adrian Roosd5c2db62016-03-08 16:11:31 -0800481 public boolean isShowingWallpaper() {
482 return !mCurrentState.backdropShowing;
483 }
484
Jason Monke59dc402018-08-16 12:05:01 -0400485 @Override
486 public void onThemeChanged() {
487 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
488 int which;
489 if (state.getState() == StatusBarState.KEYGUARD
490 || state.getState() == StatusBarState.SHADE_LOCKED) {
491 which = WallpaperManager.FLAG_LOCK;
492 } else {
493 which = WallpaperManager.FLAG_SYSTEM;
494 }
495 final boolean useDarkText = mColorExtractor.getColors(which,
496 true /* ignoreVisibility */).supportsDarkText();
497
498 // Make sure we have the correct navbar/statusbar colors.
499 setKeyguardDark(useDarkText);
500 }
501
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100502 private static class State {
503 boolean keyguardShowing;
504 boolean keyguardOccluded;
505 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700506 boolean panelVisible;
507 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100508 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200509 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200510 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200511 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700512 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700513 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700514 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700515 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800516 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800517 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700518 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700519 boolean notTouchable;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100520
Jorim Jaggiecbab362014-04-23 16:13:15 +0200521 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500522 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200523 */
524 int statusBarState;
525
Adrian Roos1c0ca502015-10-07 12:20:42 -0700526 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800527 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700528 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800529 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700530
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100531 private boolean isKeyguardShowingAndNotOccluded() {
532 return keyguardShowing && !keyguardOccluded;
533 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200534
535 @Override
536 public String toString() {
537 StringBuilder result = new StringBuilder();
538 String newLine = "\n";
539 result.append("Window State {");
540 result.append(newLine);
541
542 Field[] fields = this.getClass().getDeclaredFields();
543
544 // Print field names paired with their values
545 for (Field field : fields) {
546 result.append(" ");
547 try {
548 result.append(field.getName());
549 result.append(": ");
550 //requires access to private field:
551 result.append(field.get(this));
552 } catch (IllegalAccessException ex) {
553 }
554 result.append(newLine);
555 }
556 result.append("}");
557
558 return result.toString();
559 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100560 }
Jason Monk421a9412017-02-06 09:15:21 -0800561
562 /**
563 * Custom listener to pipe data back to plugins about whether or not the status bar would be
564 * collapsed if not for the plugin.
565 * TODO: Find cleaner way to do this.
566 */
567 public interface OtherwisedCollapsedListener {
568 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
569 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100570}