blob: 167bba60b3904f08d55c8acb905c094b3e6db652 [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);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700282 applyNotTouchable(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100283 if (mLp.copyFrom(mLpChanged) != 0) {
284 mWindowManager.updateViewLayout(mStatusBarView, mLp);
285 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200286 if (mHasTopUi != mHasTopUiChanged) {
287 try {
288 mActivityManager.setHasTopUi(mHasTopUiChanged);
289 } catch (RemoteException e) {
290 Log.e(TAG, "Failed to call setHasTopUi", e);
291 }
292 mHasTopUi = mHasTopUiChanged;
293 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100294 }
295
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700296 private void applyForceStatusBarVisibleFlag(State state) {
297 if (state.forceStatusBarVisible) {
298 mLpChanged.privateFlags |= WindowManager
299 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
300 } else {
301 mLpChanged.privateFlags &= ~WindowManager
302 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
303 }
304 }
305
Selim Cineka59ecc32015-04-07 10:51:49 -0700306 private void applyModalFlag(State state) {
307 if (state.headsUpShowing) {
308 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
309 } else {
310 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
311 }
312 }
313
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700314 private void applyBrightness(State state) {
315 if (state.forceDozeBrightness) {
316 mLpChanged.screenBrightness = mScreenBrightnessDoze;
317 } else {
318 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
319 }
320 }
321
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200322 private void applyHasTopUi(State state) {
323 mHasTopUiChanged = isExpanded(state);
324 }
325
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200326 private void applySleepToken(State state) {
327 if (state.dozing) {
328 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
329 } else {
330 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
331 }
332 }
333
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700334 private void applyNotTouchable(State state) {
335 if (state.notTouchable) {
336 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
337 } else {
338 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
339 }
340 }
341
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100342 public void setKeyguardShowing(boolean showing) {
343 mCurrentState.keyguardShowing = showing;
344 apply(mCurrentState);
345 }
346
347 public void setKeyguardOccluded(boolean occluded) {
348 mCurrentState.keyguardOccluded = occluded;
349 apply(mCurrentState);
350 }
351
352 public void setKeyguardNeedsInput(boolean needsInput) {
353 mCurrentState.keyguardNeedsInput = needsInput;
354 apply(mCurrentState);
355 }
356
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700357 public void setPanelVisible(boolean visible) {
358 mCurrentState.panelVisible = visible;
359 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100360 apply(mCurrentState);
361 }
362
363 public void setStatusBarFocusable(boolean focusable) {
364 mCurrentState.statusBarFocusable = focusable;
365 apply(mCurrentState);
366 }
367
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200368 public void setBouncerShowing(boolean showing) {
369 mCurrentState.bouncerShowing = showing;
370 apply(mCurrentState);
371 }
372
Adrian Roosd5c2db62016-03-08 16:11:31 -0800373 public void setBackdropShowing(boolean showing) {
374 mCurrentState.backdropShowing = showing;
375 apply(mCurrentState);
376 }
377
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200378 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
379 mCurrentState.keyguardFadingAway = keyguardFadingAway;
380 apply(mCurrentState);
381 }
382
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200383 public void setQsExpanded(boolean expanded) {
384 mCurrentState.qsExpanded = expanded;
385 apply(mCurrentState);
386 }
387
Vadim Tryshev6069c402016-03-09 14:24:29 -0800388 public void setForceUserActivity(boolean forceUserActivity) {
389 mCurrentState.forceUserActivity = forceUserActivity;
390 apply(mCurrentState);
391 }
392
Lucas Dupin82aa1632017-12-13 00:13:57 -0800393 public void setScrimsVisibility(int scrimsVisibility) {
394 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200395 apply(mCurrentState);
396 }
397
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700398 public void setHeadsUpShowing(boolean showing) {
399 mCurrentState.headsUpShowing = showing;
400 apply(mCurrentState);
401 }
402
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700403 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
404 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
405 apply(mCurrentState);
406 }
407
Jorim Jaggiecbab362014-04-23 16:13:15 +0200408 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400409 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200410 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400411 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200412 mCurrentState.statusBarState = state;
413 apply(mCurrentState);
414 }
415
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700416 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
417 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
418 apply(mCurrentState);
419 }
420
Selim Cinek737bff32015-05-08 16:08:35 -0700421 /**
422 * Force the window to be collapsed, even if it should theoretically be expanded.
423 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
424 * be computed.
425 */
426 public void setForceWindowCollapsed(boolean force) {
427 mCurrentState.forceCollapsed = force;
428 apply(mCurrentState);
429 }
430
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700431 public void setPanelExpanded(boolean isExpanded) {
432 mCurrentState.panelExpanded = isExpanded;
433 apply(mCurrentState);
434 }
435
Adrian Roosd28ccd72016-01-06 15:23:14 +0100436 @Override
437 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700438 mCurrentState.remoteInputActive = remoteInputActive;
439 apply(mCurrentState);
440 }
441
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700442 /**
443 * Set whether the screen brightness is forced to the value we use for doze mode by the status
444 * bar window.
445 */
446 public void setForceDozeBrightness(boolean forceDozeBrightness) {
447 mCurrentState.forceDozeBrightness = forceDozeBrightness;
448 apply(mCurrentState);
449 }
450
Adrian Roos67cca742017-04-13 16:52:51 -0700451 public void setDozing(boolean dozing) {
452 mCurrentState.dozing = dozing;
453 apply(mCurrentState);
454 }
455
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700456 public void setBarHeight(int barHeight) {
457 mBarHeight = barHeight;
458 apply(mCurrentState);
459 }
460
Jason Monk421a9412017-02-06 09:15:21 -0800461 public void setForcePluginOpen(boolean forcePluginOpen) {
462 mCurrentState.forcePluginOpen = forcePluginOpen;
463 apply(mCurrentState);
464 }
465
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700466 public void setNotTouchable(boolean notTouchable) {
467 mCurrentState.notTouchable = notTouchable;
468 apply(mCurrentState);
469 }
470
Jason Monk421a9412017-02-06 09:15:21 -0800471 public void setStateListener(OtherwisedCollapsedListener listener) {
472 mListener = listener;
473 }
474
Selim Cinek7025f262015-07-13 16:22:48 -0700475 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700476 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700477 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200478 }
479
Adrian Roosd5c2db62016-03-08 16:11:31 -0800480 public boolean isShowingWallpaper() {
481 return !mCurrentState.backdropShowing;
482 }
483
Jason Monke59dc402018-08-16 12:05:01 -0400484 @Override
485 public void onThemeChanged() {
486 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
487 int which;
488 if (state.getState() == StatusBarState.KEYGUARD
489 || state.getState() == StatusBarState.SHADE_LOCKED) {
490 which = WallpaperManager.FLAG_LOCK;
491 } else {
492 which = WallpaperManager.FLAG_SYSTEM;
493 }
494 final boolean useDarkText = mColorExtractor.getColors(which,
495 true /* ignoreVisibility */).supportsDarkText();
496
497 // Make sure we have the correct navbar/statusbar colors.
498 setKeyguardDark(useDarkText);
499 }
500
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100501 private static class State {
502 boolean keyguardShowing;
503 boolean keyguardOccluded;
504 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700505 boolean panelVisible;
506 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100507 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200508 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200509 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200510 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700511 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700512 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700513 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700514 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800515 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800516 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700517 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700518 boolean notTouchable;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100519
Jorim Jaggiecbab362014-04-23 16:13:15 +0200520 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500521 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200522 */
523 int statusBarState;
524
Adrian Roos1c0ca502015-10-07 12:20:42 -0700525 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800526 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700527 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800528 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700529
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100530 private boolean isKeyguardShowingAndNotOccluded() {
531 return keyguardShowing && !keyguardOccluded;
532 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200533
534 @Override
535 public String toString() {
536 StringBuilder result = new StringBuilder();
537 String newLine = "\n";
538 result.append("Window State {");
539 result.append(newLine);
540
541 Field[] fields = this.getClass().getDeclaredFields();
542
543 // Print field names paired with their values
544 for (Field field : fields) {
545 result.append(" ");
546 try {
547 result.append(field.getName());
548 result.append(": ");
549 //requires access to private field:
550 result.append(field.get(this));
551 } catch (IllegalAccessException ex) {
552 }
553 result.append(newLine);
554 }
555 result.append("}");
556
557 return result.toString();
558 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100559 }
Jason Monk421a9412017-02-06 09:15:21 -0800560
561 /**
562 * Custom listener to pipe data back to plugins about whether or not the status bar would be
563 * collapsed if not for the plugin.
564 * TODO: Find cleaner way to do this.
565 */
566 public interface OtherwisedCollapsedListener {
567 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
568 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100569}