blob: ce69a489737afc98b43aad379d318bf84656e0e4 [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;
Beverly8fdb5332019-02-04 14:29:49 -050046import com.android.systemui.plugins.statusbar.StatusBarStateController;
47import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
Jason Monke59dc402018-08-16 12:05:01 -040048import com.android.systemui.statusbar.RemoteInputController.Callback;
Jorim Jaggiecbab362014-04-23 16:13:15 +020049import com.android.systemui.statusbar.StatusBarState;
Beverly8fdb5332019-02-04 14:29:49 -050050import com.android.systemui.statusbar.SysuiStatusBarStateController;
Jason Monke59dc402018-08-16 12:05:01 -040051import com.android.systemui.statusbar.policy.ConfigurationController;
52import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010053
Selim Cinek7025f262015-07-13 16:22:48 -070054import java.io.FileDescriptor;
55import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020056import java.lang.reflect.Field;
57
Jason Monk196d6392018-12-20 13:25:34 -050058import javax.inject.Inject;
59import javax.inject.Singleton;
60
Jorim Jaggi5cf17872014-03-26 18:31:48 +010061/**
62 * Encapsulates all logic for the status bar window state management.
63 */
Jason Monk196d6392018-12-20 13:25:34 -050064@Singleton
Jason Monke59dc402018-08-16 12:05:01 -040065public class StatusBarWindowController implements Callback, Dumpable, ConfigurationListener {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010066
Lucas Dupin1a8588d2018-08-21 12:18:47 -070067 private static final String TAG = "StatusBarWindowController";
Jorim Jaggif6782ee2016-07-22 11:40:00 +020068
Jorim Jaggi5cf17872014-03-26 18:31:48 +010069 private final Context mContext;
70 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020071 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070072 private final DozeParameters mDozeParameters;
Lucas Dupin42ebe542019-01-22 09:45:09 -080073 private final WindowManager.LayoutParams mLpChanged;
74 private final boolean mKeyguardScreenRotation;
Mady Mellord1c78b262018-11-06 18:04:40 -080075 private ViewGroup mStatusBarView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010076 private WindowManager.LayoutParams mLp;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020077 private boolean mHasTopUi;
78 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010079 private int mBarHeight;
Adrian Roos3e23eb52017-07-07 15:58:57 +020080 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010081 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080082 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010083
Jason Monke59dc402018-08-16 12:05:01 -040084 private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Jason Monk1fd3fc32018-08-14 17:20:09 -040085
Jason Monk196d6392018-12-20 13:25:34 -050086 @Inject
Lucas Dupin1a8588d2018-08-21 12:18:47 -070087 public StatusBarWindowController(Context context) {
Lucas Dupina3e36272018-08-21 13:22:33 -070088 this(context, context.getSystemService(WindowManager.class), ActivityManager.getService(),
89 DozeParameters.getInstance(context));
90 }
91
92 @VisibleForTesting
Mady Mellorebdbbb92018-11-15 14:36:48 -080093 public StatusBarWindowController(Context context, WindowManager windowManager,
Lucas Dupina3e36272018-08-21 13:22:33 -070094 IActivityManager activityManager, DozeParameters dozeParameters) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010095 mContext = context;
Lucas Dupina3e36272018-08-21 13:22:33 -070096 mWindowManager = windowManager;
97 mActivityManager = activityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010098 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupina3e36272018-08-21 13:22:33 -070099 mDozeParameters = dozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700100 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800101 mLpChanged = new WindowManager.LayoutParams();
Beverly8fdb5332019-02-04 14:29:49 -0500102 ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class))
103 .addCallback(mStateListener,
104 SysuiStatusBarStateController.RANK_STATUS_BAR_WINDOW_CONTROLLER);
Jason Monke59dc402018-08-16 12:05:01 -0400105 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100106 }
107
108 private boolean shouldEnableKeyguardScreenRotation() {
109 Resources res = mContext.getResources();
110 return SystemProperties.getBoolean("lockscreen.rot_override", false)
111 || res.getBoolean(R.bool.config_enableLockScreenRotation);
112 }
113
114 /**
115 * Adds the status bar view to the window manager.
116 *
117 * @param statusBarView The view to add.
118 * @param barHeight The height of the status bar in collapsed state.
119 */
Mady Mellord1c78b262018-11-06 18:04:40 -0800120 public void add(ViewGroup statusBarView, int barHeight) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100121
122 // Now that the status bar window encompasses the sliding panel and its
123 // translucent backdrop, the entire thing is made TRANSLUCENT and is
124 // hardware-accelerated.
125 mLp = new WindowManager.LayoutParams(
126 ViewGroup.LayoutParams.MATCH_PARENT,
127 barHeight,
128 WindowManager.LayoutParams.TYPE_STATUS_BAR,
129 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
130 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
131 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
132 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200133 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100134 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800135 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200136 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100137 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138 mLp.setTitle("StatusBar");
139 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100140 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100141 mStatusBarView = statusBarView;
142 mBarHeight = barHeight;
143 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100144 mLpChanged.copyFrom(mLp);
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700145 onThemeChanged();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100146 }
147
Mady Mellord1c78b262018-11-06 18:04:40 -0800148 public ViewGroup getStatusBarView() {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800149 return mStatusBarView;
150 }
151
Adrian Roos3e23eb52017-07-07 15:58:57 +0200152 public void setDozeScreenBrightness(int value) {
153 mScreenBrightnessDoze = value / 255f;
154 }
155
Jason Monke59dc402018-08-16 12:05:01 -0400156 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700157 int vis = mStatusBarView.getSystemUiVisibility();
158 if (dark) {
159 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
160 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
161 } else {
162 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
163 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
164 }
165 mStatusBarView.setSystemUiVisibility(vis);
166 }
167
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100168 private void applyKeyguardFlags(State state) {
169 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100170 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100171 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100172 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100173 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800174
Lucas Dupin16cfe452018-02-08 13:14:50 -0800175 final boolean scrimsOccludingWallpaper =
176 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800177 final boolean keyguardOrAod = state.keyguardShowing
178 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000179 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800180 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
181 } else {
182 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
183 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700184
185 if (state.dozing) {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700186 mLpChanged.privateFlags |= LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700187 } else {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700188 mLpChanged.privateFlags &= ~LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700189 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100190 }
191
192 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200193 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200194 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100195 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200196 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100197 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200198 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100199 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100200 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100201 }
202 }
203
204 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700205 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800206 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100207 || ENABLE_REMOTE_INPUT && state.remoteInputActive
208 || state.bubbleExpanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100209 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
210 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700211 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100212 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
213 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100214 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100215 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
216 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100217 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100218
Adrian Roos5153d4a2016-03-22 10:01:56 -0700219 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100220 }
221
Tiger Huanga90dea42018-08-03 17:20:17 +0800222 private void applyForceShowNavigationFlag(State state) {
223 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800224 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800225 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800226 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800227 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800228 }
229 }
230
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100231 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200232 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800233 if (state.forcePluginOpen) {
Lucas Dupin42ebe542019-01-22 09:45:09 -0800234 if (mListener != null) {
235 mListener.setWouldOtherwiseCollapse(expanded);
236 }
Jason Monk421a9412017-02-06 09:15:21 -0800237 expanded = true;
238 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100239 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100240 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100241 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100242 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100243 }
244 }
245
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200246 private boolean isExpanded(State state) {
247 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
248 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
James O'Leary4855f452019-02-25 12:29:50 -0500249 || state.headsUpShowing || state.bubblesShowing || state.assistShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800250 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200251 }
252
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200253 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700254 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800255 if (mStatusBarView != null && mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700256 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
257 mStatusBarView.requestApplyInsets();
258 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200259 }
260
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100261 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200262 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200263 && state.statusBarState == StatusBarState.KEYGUARD
264 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100265 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100266 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100267 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100268 }
269 }
270
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200271 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200272 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200273 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800274 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100275 mLpChanged.inputFeatures |=
276 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200277 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100278 mLpChanged.inputFeatures &=
279 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200280 }
281 }
282
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100283 private void apply(State state) {
284 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700285 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100286 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800287 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100288 adjustScreenOrientation(state);
289 applyHeight(state);
290 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200291 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200292 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700293 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700294 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200295 applyHasTopUi(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700296 applyNotTouchable(state);
Lucas Dupin42ebe542019-01-22 09:45:09 -0800297 if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100298 mWindowManager.updateViewLayout(mStatusBarView, mLp);
299 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200300 if (mHasTopUi != mHasTopUiChanged) {
301 try {
302 mActivityManager.setHasTopUi(mHasTopUiChanged);
303 } catch (RemoteException e) {
304 Log.e(TAG, "Failed to call setHasTopUi", e);
305 }
306 mHasTopUi = mHasTopUiChanged;
307 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100308 }
309
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700310 private void applyForceStatusBarVisibleFlag(State state) {
311 if (state.forceStatusBarVisible) {
312 mLpChanged.privateFlags |= WindowManager
313 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
314 } else {
315 mLpChanged.privateFlags &= ~WindowManager
316 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
317 }
318 }
319
Selim Cineka59ecc32015-04-07 10:51:49 -0700320 private void applyModalFlag(State state) {
321 if (state.headsUpShowing) {
322 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
323 } else {
324 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
325 }
326 }
327
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700328 private void applyBrightness(State state) {
329 if (state.forceDozeBrightness) {
330 mLpChanged.screenBrightness = mScreenBrightnessDoze;
331 } else {
332 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
333 }
334 }
335
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200336 private void applyHasTopUi(State state) {
337 mHasTopUiChanged = isExpanded(state);
338 }
339
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700340 private void applyNotTouchable(State state) {
341 if (state.notTouchable) {
342 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
343 } else {
344 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
345 }
346 }
347
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100348 public void setKeyguardShowing(boolean showing) {
349 mCurrentState.keyguardShowing = showing;
350 apply(mCurrentState);
351 }
352
353 public void setKeyguardOccluded(boolean occluded) {
354 mCurrentState.keyguardOccluded = occluded;
355 apply(mCurrentState);
356 }
357
358 public void setKeyguardNeedsInput(boolean needsInput) {
359 mCurrentState.keyguardNeedsInput = needsInput;
360 apply(mCurrentState);
361 }
362
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700363 public void setPanelVisible(boolean visible) {
364 mCurrentState.panelVisible = visible;
365 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100366 apply(mCurrentState);
367 }
368
369 public void setStatusBarFocusable(boolean focusable) {
370 mCurrentState.statusBarFocusable = focusable;
371 apply(mCurrentState);
372 }
373
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200374 public void setBouncerShowing(boolean showing) {
375 mCurrentState.bouncerShowing = showing;
376 apply(mCurrentState);
377 }
378
Adrian Roosd5c2db62016-03-08 16:11:31 -0800379 public void setBackdropShowing(boolean showing) {
380 mCurrentState.backdropShowing = showing;
381 apply(mCurrentState);
382 }
383
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200384 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
385 mCurrentState.keyguardFadingAway = keyguardFadingAway;
386 apply(mCurrentState);
387 }
388
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200389 public void setQsExpanded(boolean expanded) {
390 mCurrentState.qsExpanded = expanded;
391 apply(mCurrentState);
392 }
393
Vadim Tryshev6069c402016-03-09 14:24:29 -0800394 public void setForceUserActivity(boolean forceUserActivity) {
395 mCurrentState.forceUserActivity = forceUserActivity;
396 apply(mCurrentState);
397 }
398
Lucas Dupin82aa1632017-12-13 00:13:57 -0800399 public void setScrimsVisibility(int scrimsVisibility) {
400 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200401 apply(mCurrentState);
402 }
403
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700404 public void setHeadsUpShowing(boolean showing) {
405 mCurrentState.headsUpShowing = showing;
406 apply(mCurrentState);
407 }
408
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700409 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
410 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
411 apply(mCurrentState);
412 }
413
Jorim Jaggiecbab362014-04-23 16:13:15 +0200414 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400415 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200416 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400417 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200418 mCurrentState.statusBarState = state;
419 apply(mCurrentState);
420 }
421
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700422 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
423 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
424 apply(mCurrentState);
425 }
426
Selim Cinek737bff32015-05-08 16:08:35 -0700427 /**
428 * Force the window to be collapsed, even if it should theoretically be expanded.
429 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
430 * be computed.
431 */
432 public void setForceWindowCollapsed(boolean force) {
433 mCurrentState.forceCollapsed = force;
434 apply(mCurrentState);
435 }
436
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700437 public void setPanelExpanded(boolean isExpanded) {
438 mCurrentState.panelExpanded = isExpanded;
439 apply(mCurrentState);
440 }
441
Adrian Roosd28ccd72016-01-06 15:23:14 +0100442 @Override
443 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700444 mCurrentState.remoteInputActive = remoteInputActive;
445 apply(mCurrentState);
446 }
447
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700448 /**
449 * Set whether the screen brightness is forced to the value we use for doze mode by the status
450 * bar window.
451 */
452 public void setForceDozeBrightness(boolean forceDozeBrightness) {
453 mCurrentState.forceDozeBrightness = forceDozeBrightness;
454 apply(mCurrentState);
455 }
456
Adrian Roos67cca742017-04-13 16:52:51 -0700457 public void setDozing(boolean dozing) {
458 mCurrentState.dozing = dozing;
459 apply(mCurrentState);
460 }
461
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700462 public void setBarHeight(int barHeight) {
463 mBarHeight = barHeight;
464 apply(mCurrentState);
465 }
466
Jason Monk421a9412017-02-06 09:15:21 -0800467 public void setForcePluginOpen(boolean forcePluginOpen) {
468 mCurrentState.forcePluginOpen = forcePluginOpen;
469 apply(mCurrentState);
470 }
471
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700472 public void setNotTouchable(boolean notTouchable) {
473 mCurrentState.notTouchable = notTouchable;
474 apply(mCurrentState);
475 }
476
Mady Mellord1c78b262018-11-06 18:04:40 -0800477 /**
478 * Sets whether there are bubbles showing on the screen.
479 */
480 public void setBubblesShowing(boolean bubblesShowing) {
481 mCurrentState.bubblesShowing = bubblesShowing;
482 apply(mCurrentState);
483 }
484
485 /**
486 * The bubbles showing state for the status bar.
487 */
488 public boolean getBubblesShowing() {
489 return mCurrentState.bubblesShowing;
490 }
491
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100492 /**
James O'Leary4855f452019-02-25 12:29:50 -0500493 * Sets whether assist UI is showing on the screen.
494 */
495 public void setAssistShowing(boolean assistShowing) {
496 mCurrentState.assistShowing = assistShowing;
497 apply(mCurrentState);
498 }
499
500 /**
501 * The assist UI showing state for the status bar.
502 */
503 public boolean getAssistShowing() {
504 return mCurrentState.assistShowing;
505 }
506
507 /**
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100508 * Sets if there is a bubble being expanded on the screen.
509 */
510 public void setBubbleExpanded(boolean bubbleExpanded) {
511 mCurrentState.bubbleExpanded = bubbleExpanded;
512 apply(mCurrentState);
513 }
514
515 /**
516 * The bubble is shown in expanded state for the status bar.
517 */
518 public boolean getBubbleExpanded() {
519 return mCurrentState.bubbleExpanded;
520 }
521
Jason Monk421a9412017-02-06 09:15:21 -0800522 public void setStateListener(OtherwisedCollapsedListener listener) {
523 mListener = listener;
524 }
525
Selim Cinek7025f262015-07-13 16:22:48 -0700526 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700527 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700528 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200529 }
530
Adrian Roosd5c2db62016-03-08 16:11:31 -0800531 public boolean isShowingWallpaper() {
532 return !mCurrentState.backdropShowing;
533 }
534
Jason Monke59dc402018-08-16 12:05:01 -0400535 @Override
536 public void onThemeChanged() {
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700537 if (mStatusBarView == null) {
538 return;
539 }
540
Jason Monke59dc402018-08-16 12:05:01 -0400541 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
542 int which;
543 if (state.getState() == StatusBarState.KEYGUARD
544 || state.getState() == StatusBarState.SHADE_LOCKED) {
545 which = WallpaperManager.FLAG_LOCK;
546 } else {
547 which = WallpaperManager.FLAG_SYSTEM;
548 }
549 final boolean useDarkText = mColorExtractor.getColors(which,
550 true /* ignoreVisibility */).supportsDarkText();
551
552 // Make sure we have the correct navbar/statusbar colors.
553 setKeyguardDark(useDarkText);
554 }
555
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100556 private static class State {
557 boolean keyguardShowing;
558 boolean keyguardOccluded;
559 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700560 boolean panelVisible;
561 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100562 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200563 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200564 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200565 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700566 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700567 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700568 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700569 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800570 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800571 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700572 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700573 boolean notTouchable;
Mady Mellord1c78b262018-11-06 18:04:40 -0800574 boolean bubblesShowing;
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100575 boolean bubbleExpanded;
James O'Leary4855f452019-02-25 12:29:50 -0500576 boolean assistShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100577
Jorim Jaggiecbab362014-04-23 16:13:15 +0200578 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500579 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200580 */
581 int statusBarState;
582
Adrian Roos1c0ca502015-10-07 12:20:42 -0700583 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800584 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700585 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800586 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700587
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100588 private boolean isKeyguardShowingAndNotOccluded() {
589 return keyguardShowing && !keyguardOccluded;
590 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200591
592 @Override
593 public String toString() {
594 StringBuilder result = new StringBuilder();
595 String newLine = "\n";
596 result.append("Window State {");
597 result.append(newLine);
598
599 Field[] fields = this.getClass().getDeclaredFields();
600
601 // Print field names paired with their values
602 for (Field field : fields) {
603 result.append(" ");
604 try {
605 result.append(field.getName());
606 result.append(": ");
607 //requires access to private field:
608 result.append(field.get(this));
609 } catch (IllegalAccessException ex) {
610 }
611 result.append(newLine);
612 }
613 result.append("}");
614
615 return result.toString();
616 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100617 }
Jason Monk421a9412017-02-06 09:15:21 -0800618
Evan Laird878c8532018-10-15 15:54:29 -0400619 private final StateListener mStateListener = new StateListener() {
620 @Override
621 public void onStateChanged(int newState) {
622 setStatusBarState(newState);
623 }
624
625 @Override
626 public void onDozingChanged(boolean isDozing) {
627 setDozing(isDozing);
628 }
629 };
630
Jason Monk421a9412017-02-06 09:15:21 -0800631 /**
632 * Custom listener to pipe data back to plugins about whether or not the status bar would be
633 * collapsed if not for the plugin.
634 * TODO: Find cleaner way to do this.
635 */
636 public interface OtherwisedCollapsedListener {
637 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
638 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100639}