blob: 8621b729371162952400dd51c855c91aa7a07be3 [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;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010025import android.content.Context;
26import android.content.pm.ActivityInfo;
27import android.content.res.Resources;
28import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080029import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020030import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010031import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020032import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010033import android.view.Gravity;
34import android.view.View;
35import android.view.ViewGroup;
36import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020037import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010038
Lucas Dupina3e36272018-08-21 13:22:33 -070039import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010040import com.android.keyguard.R;
Jason Monk1fd3fc32018-08-14 17:20:09 -040041import com.android.systemui.Dependency;
Jason Monk421a9412017-02-06 09:15:21 -080042import com.android.systemui.Dumpable;
Jason Monke59dc402018-08-16 12:05:01 -040043import com.android.systemui.colorextraction.SysuiColorExtractor;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010044import com.android.systemui.keyguard.KeyguardViewMediator;
Beverly8fdb5332019-02-04 14:29:49 -050045import com.android.systemui.plugins.statusbar.StatusBarStateController;
46import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
Jason Monke59dc402018-08-16 12:05:01 -040047import com.android.systemui.statusbar.RemoteInputController.Callback;
Jorim Jaggiecbab362014-04-23 16:13:15 +020048import com.android.systemui.statusbar.StatusBarState;
Beverly8fdb5332019-02-04 14:29:49 -050049import com.android.systemui.statusbar.SysuiStatusBarStateController;
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
Winson Chung60887932019-06-13 22:37:31 -070053import com.google.android.collect.Lists;
Selim Cinek7025f262015-07-13 16:22:48 -070054import java.io.FileDescriptor;
55import java.io.PrintWriter;
Winson Chung60887932019-06-13 22:37:31 -070056import java.lang.ref.WeakReference;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020057import java.lang.reflect.Field;
58
Winson Chung60887932019-06-13 22:37:31 -070059import java.util.ArrayList;
Jason Monk196d6392018-12-20 13:25:34 -050060import javax.inject.Inject;
61import javax.inject.Singleton;
62
Jorim Jaggi5cf17872014-03-26 18:31:48 +010063/**
64 * Encapsulates all logic for the status bar window state management.
65 */
Jason Monk196d6392018-12-20 13:25:34 -050066@Singleton
Jason Monke59dc402018-08-16 12:05:01 -040067public class StatusBarWindowController implements Callback, Dumpable, ConfigurationListener {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068
Lucas Dupin1a8588d2018-08-21 12:18:47 -070069 private static final String TAG = "StatusBarWindowController";
Jorim Jaggif6782ee2016-07-22 11:40:00 +020070
Jorim Jaggi5cf17872014-03-26 18:31:48 +010071 private final Context mContext;
72 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020073 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070074 private final DozeParameters mDozeParameters;
Lucas Dupin42ebe542019-01-22 09:45:09 -080075 private final WindowManager.LayoutParams mLpChanged;
76 private final boolean mKeyguardScreenRotation;
Mady Mellord1c78b262018-11-06 18:04:40 -080077 private ViewGroup mStatusBarView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078 private WindowManager.LayoutParams mLp;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020079 private boolean mHasTopUi;
80 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010081 private int mBarHeight;
Adrian Roos3e23eb52017-07-07 15:58:57 +020082 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010083 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080084 private OtherwisedCollapsedListener mListener;
Winson Chung60887932019-06-13 22:37:31 -070085 private final ArrayList<WeakReference<StatusBarWindowCallback>>
86 mCallbacks = Lists.newArrayList();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010087
Jason Monke59dc402018-08-16 12:05:01 -040088 private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Jason Monk1fd3fc32018-08-14 17:20:09 -040089
Jason Monk196d6392018-12-20 13:25:34 -050090 @Inject
Lucas Dupin1a8588d2018-08-21 12:18:47 -070091 public StatusBarWindowController(Context context) {
Lucas Dupina3e36272018-08-21 13:22:33 -070092 this(context, context.getSystemService(WindowManager.class), ActivityManager.getService(),
93 DozeParameters.getInstance(context));
94 }
95
96 @VisibleForTesting
Mady Mellorebdbbb92018-11-15 14:36:48 -080097 public StatusBarWindowController(Context context, WindowManager windowManager,
Lucas Dupina3e36272018-08-21 13:22:33 -070098 IActivityManager activityManager, DozeParameters dozeParameters) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010099 mContext = context;
Lucas Dupina3e36272018-08-21 13:22:33 -0700100 mWindowManager = windowManager;
101 mActivityManager = activityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100102 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupina3e36272018-08-21 13:22:33 -0700103 mDozeParameters = dozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700104 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800105 mLpChanged = new WindowManager.LayoutParams();
Beverly8fdb5332019-02-04 14:29:49 -0500106 ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class))
107 .addCallback(mStateListener,
108 SysuiStatusBarStateController.RANK_STATUS_BAR_WINDOW_CONTROLLER);
Jason Monke59dc402018-08-16 12:05:01 -0400109 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100110 }
111
Winson Chung60887932019-06-13 22:37:31 -0700112 /**
113 * Register to receive notifications about status bar window state changes.
114 */
115 public void registerCallback(StatusBarWindowCallback callback) {
116 // Prevent adding duplicate callbacks
117 for (int i = 0; i < mCallbacks.size(); i++) {
118 if (mCallbacks.get(i).get() == callback) {
119 return;
120 }
121 }
122 mCallbacks.add(new WeakReference<StatusBarWindowCallback>(callback));
123 }
124
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100125 private boolean shouldEnableKeyguardScreenRotation() {
126 Resources res = mContext.getResources();
127 return SystemProperties.getBoolean("lockscreen.rot_override", false)
128 || res.getBoolean(R.bool.config_enableLockScreenRotation);
129 }
130
131 /**
132 * Adds the status bar view to the window manager.
133 *
134 * @param statusBarView The view to add.
135 * @param barHeight The height of the status bar in collapsed state.
136 */
Mady Mellord1c78b262018-11-06 18:04:40 -0800137 public void add(ViewGroup statusBarView, int barHeight) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138
139 // Now that the status bar window encompasses the sliding panel and its
140 // translucent backdrop, the entire thing is made TRANSLUCENT and is
141 // hardware-accelerated.
142 mLp = new WindowManager.LayoutParams(
143 ViewGroup.LayoutParams.MATCH_PARENT,
144 barHeight,
145 WindowManager.LayoutParams.TYPE_STATUS_BAR,
146 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
147 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
148 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
149 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200150 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100151 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800152 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200153 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100154 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100155 mLp.setTitle("StatusBar");
156 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100157 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100158 mStatusBarView = statusBarView;
159 mBarHeight = barHeight;
160 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100161 mLpChanged.copyFrom(mLp);
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700162 onThemeChanged();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100163 }
164
Mady Mellord1c78b262018-11-06 18:04:40 -0800165 public ViewGroup getStatusBarView() {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800166 return mStatusBarView;
167 }
168
Adrian Roos3e23eb52017-07-07 15:58:57 +0200169 public void setDozeScreenBrightness(int value) {
170 mScreenBrightnessDoze = value / 255f;
171 }
172
Jason Monke59dc402018-08-16 12:05:01 -0400173 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700174 int vis = mStatusBarView.getSystemUiVisibility();
175 if (dark) {
176 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
177 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
178 } else {
179 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
180 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
181 }
182 mStatusBarView.setSystemUiVisibility(vis);
183 }
184
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100185 private void applyKeyguardFlags(State state) {
186 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100187 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100188 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100189 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100190 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800191
Lucas Dupin16cfe452018-02-08 13:14:50 -0800192 final boolean scrimsOccludingWallpaper =
193 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800194 final boolean keyguardOrAod = state.keyguardShowing
195 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000196 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800197 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
198 } else {
199 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
200 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700201
202 if (state.dozing) {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700203 mLpChanged.privateFlags |= LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700204 } else {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700205 mLpChanged.privateFlags &= ~LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700206 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100207 }
208
209 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200210 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200211 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100212 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200213 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100214 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200215 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100216 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100217 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100218 }
219 }
220
221 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700222 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800223 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100224 || ENABLE_REMOTE_INPUT && state.remoteInputActive
225 || state.bubbleExpanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100226 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
227 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Matt Caseya0966b52019-05-15 18:49:37 -0400228 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100229 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
230 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100231 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100232 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
233 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100234 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100235
Adrian Roos5153d4a2016-03-22 10:01:56 -0700236 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100237 }
238
Tiger Huanga90dea42018-08-03 17:20:17 +0800239 private void applyForceShowNavigationFlag(State state) {
240 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800241 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800242 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800243 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800244 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800245 }
246 }
247
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100248 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200249 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800250 if (state.forcePluginOpen) {
Lucas Dupin42ebe542019-01-22 09:45:09 -0800251 if (mListener != null) {
252 mListener.setWouldOtherwiseCollapse(expanded);
253 }
Jason Monk421a9412017-02-06 09:15:21 -0800254 expanded = true;
255 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100256 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100257 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100258 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100259 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100260 }
261 }
262
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200263 private boolean isExpanded(State state) {
264 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
265 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Matt Caseya0966b52019-05-15 18:49:37 -0400266 || state.headsUpShowing || state.bubblesShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800267 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200268 }
269
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200270 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700271 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800272 if (mStatusBarView != null && mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700273 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
274 mStatusBarView.requestApplyInsets();
275 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200276 }
277
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100278 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200279 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200280 && state.statusBarState == StatusBarState.KEYGUARD
281 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100282 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100283 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100284 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100285 }
286 }
287
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200288 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200289 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200290 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800291 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100292 mLpChanged.inputFeatures |=
293 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200294 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100295 mLpChanged.inputFeatures &=
296 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200297 }
298 }
299
Peiyong Lin75045382019-03-04 19:22:33 -0800300 private void applyStatusBarColorSpaceAgnosticFlag(State state) {
301 if (!isExpanded(state)) {
302 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
303 } else {
304 mLpChanged.privateFlags &=
305 ~WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
306 }
307 }
308
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100309 private void apply(State state) {
310 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700311 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100312 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800313 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100314 adjustScreenOrientation(state);
315 applyHeight(state);
316 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200317 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200318 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700319 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700320 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200321 applyHasTopUi(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700322 applyNotTouchable(state);
Peiyong Lin75045382019-03-04 19:22:33 -0800323 applyStatusBarColorSpaceAgnosticFlag(state);
Lucas Dupin42ebe542019-01-22 09:45:09 -0800324 if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100325 mWindowManager.updateViewLayout(mStatusBarView, mLp);
326 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200327 if (mHasTopUi != mHasTopUiChanged) {
328 try {
329 mActivityManager.setHasTopUi(mHasTopUiChanged);
330 } catch (RemoteException e) {
331 Log.e(TAG, "Failed to call setHasTopUi", e);
332 }
333 mHasTopUi = mHasTopUiChanged;
334 }
Winson Chung60887932019-06-13 22:37:31 -0700335 notifyStateChangedCallbacks();
Winson Chung7bbeb452019-06-04 10:25:50 -0700336 }
337
Winson Chung60887932019-06-13 22:37:31 -0700338 public void notifyStateChangedCallbacks() {
339 for (int i = 0; i < mCallbacks.size(); i++) {
340 StatusBarWindowCallback cb = mCallbacks.get(i).get();
341 if (cb != null) {
342 cb.onStateChanged(mCurrentState.keyguardShowing,
343 mCurrentState.keyguardOccluded,
344 mCurrentState.bouncerShowing);
345 }
346 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100347 }
348
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700349 private void applyForceStatusBarVisibleFlag(State state) {
350 if (state.forceStatusBarVisible) {
351 mLpChanged.privateFlags |= WindowManager
352 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
353 } else {
354 mLpChanged.privateFlags &= ~WindowManager
355 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
356 }
357 }
358
Selim Cineka59ecc32015-04-07 10:51:49 -0700359 private void applyModalFlag(State state) {
360 if (state.headsUpShowing) {
361 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
362 } else {
363 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
364 }
365 }
366
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700367 private void applyBrightness(State state) {
368 if (state.forceDozeBrightness) {
369 mLpChanged.screenBrightness = mScreenBrightnessDoze;
370 } else {
371 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
372 }
373 }
374
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200375 private void applyHasTopUi(State state) {
376 mHasTopUiChanged = isExpanded(state);
377 }
378
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700379 private void applyNotTouchable(State state) {
380 if (state.notTouchable) {
381 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
382 } else {
383 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
384 }
385 }
386
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100387 public void setKeyguardShowing(boolean showing) {
388 mCurrentState.keyguardShowing = showing;
389 apply(mCurrentState);
390 }
391
392 public void setKeyguardOccluded(boolean occluded) {
393 mCurrentState.keyguardOccluded = occluded;
394 apply(mCurrentState);
395 }
396
397 public void setKeyguardNeedsInput(boolean needsInput) {
398 mCurrentState.keyguardNeedsInput = needsInput;
399 apply(mCurrentState);
400 }
401
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700402 public void setPanelVisible(boolean visible) {
403 mCurrentState.panelVisible = visible;
404 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100405 apply(mCurrentState);
406 }
407
408 public void setStatusBarFocusable(boolean focusable) {
409 mCurrentState.statusBarFocusable = focusable;
410 apply(mCurrentState);
411 }
412
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200413 public void setBouncerShowing(boolean showing) {
414 mCurrentState.bouncerShowing = showing;
415 apply(mCurrentState);
416 }
417
Adrian Roosd5c2db62016-03-08 16:11:31 -0800418 public void setBackdropShowing(boolean showing) {
419 mCurrentState.backdropShowing = showing;
420 apply(mCurrentState);
421 }
422
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200423 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
424 mCurrentState.keyguardFadingAway = keyguardFadingAway;
425 apply(mCurrentState);
426 }
427
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200428 public void setQsExpanded(boolean expanded) {
429 mCurrentState.qsExpanded = expanded;
430 apply(mCurrentState);
431 }
432
Vadim Tryshev6069c402016-03-09 14:24:29 -0800433 public void setForceUserActivity(boolean forceUserActivity) {
434 mCurrentState.forceUserActivity = forceUserActivity;
435 apply(mCurrentState);
436 }
437
Lucas Dupin82aa1632017-12-13 00:13:57 -0800438 public void setScrimsVisibility(int scrimsVisibility) {
439 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200440 apply(mCurrentState);
441 }
442
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700443 public void setHeadsUpShowing(boolean showing) {
444 mCurrentState.headsUpShowing = showing;
445 apply(mCurrentState);
446 }
447
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700448 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
449 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
450 apply(mCurrentState);
451 }
452
Jorim Jaggiecbab362014-04-23 16:13:15 +0200453 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400454 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200455 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400456 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200457 mCurrentState.statusBarState = state;
458 apply(mCurrentState);
459 }
460
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700461 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
462 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
463 apply(mCurrentState);
464 }
465
Selim Cinek737bff32015-05-08 16:08:35 -0700466 /**
467 * Force the window to be collapsed, even if it should theoretically be expanded.
468 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
469 * be computed.
470 */
471 public void setForceWindowCollapsed(boolean force) {
472 mCurrentState.forceCollapsed = force;
473 apply(mCurrentState);
474 }
475
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700476 public void setPanelExpanded(boolean isExpanded) {
477 mCurrentState.panelExpanded = isExpanded;
478 apply(mCurrentState);
479 }
480
Adrian Roosd28ccd72016-01-06 15:23:14 +0100481 @Override
482 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700483 mCurrentState.remoteInputActive = remoteInputActive;
484 apply(mCurrentState);
485 }
486
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700487 /**
488 * Set whether the screen brightness is forced to the value we use for doze mode by the status
489 * bar window.
490 */
491 public void setForceDozeBrightness(boolean forceDozeBrightness) {
492 mCurrentState.forceDozeBrightness = forceDozeBrightness;
493 apply(mCurrentState);
494 }
495
Adrian Roos67cca742017-04-13 16:52:51 -0700496 public void setDozing(boolean dozing) {
497 mCurrentState.dozing = dozing;
498 apply(mCurrentState);
499 }
500
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700501 public void setBarHeight(int barHeight) {
502 mBarHeight = barHeight;
503 apply(mCurrentState);
504 }
505
Jason Monk421a9412017-02-06 09:15:21 -0800506 public void setForcePluginOpen(boolean forcePluginOpen) {
507 mCurrentState.forcePluginOpen = forcePluginOpen;
508 apply(mCurrentState);
509 }
510
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700511 public void setNotTouchable(boolean notTouchable) {
512 mCurrentState.notTouchable = notTouchable;
513 apply(mCurrentState);
514 }
515
Mady Mellord1c78b262018-11-06 18:04:40 -0800516 /**
517 * Sets whether there are bubbles showing on the screen.
518 */
519 public void setBubblesShowing(boolean bubblesShowing) {
520 mCurrentState.bubblesShowing = bubblesShowing;
521 apply(mCurrentState);
522 }
523
524 /**
525 * The bubbles showing state for the status bar.
526 */
527 public boolean getBubblesShowing() {
528 return mCurrentState.bubblesShowing;
529 }
530
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100531 /**
532 * Sets if there is a bubble being expanded on the screen.
533 */
534 public void setBubbleExpanded(boolean bubbleExpanded) {
535 mCurrentState.bubbleExpanded = bubbleExpanded;
536 apply(mCurrentState);
537 }
538
539 /**
Mady Mellor390bff42019-04-05 15:09:01 -0700540 * Whether the bubble is shown in expanded state for the status bar.
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100541 */
542 public boolean getBubbleExpanded() {
543 return mCurrentState.bubbleExpanded;
544 }
545
Mady Mellor390bff42019-04-05 15:09:01 -0700546 /**
547 * Whether the status bar panel is expanded or not.
548 */
549 public boolean getPanelExpanded() {
550 return mCurrentState.panelExpanded;
551 }
552
Jason Monk421a9412017-02-06 09:15:21 -0800553 public void setStateListener(OtherwisedCollapsedListener listener) {
554 mListener = listener;
555 }
556
Selim Cinek7025f262015-07-13 16:22:48 -0700557 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700558 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700559 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200560 }
561
Adrian Roosd5c2db62016-03-08 16:11:31 -0800562 public boolean isShowingWallpaper() {
563 return !mCurrentState.backdropShowing;
564 }
565
Jason Monke59dc402018-08-16 12:05:01 -0400566 @Override
567 public void onThemeChanged() {
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700568 if (mStatusBarView == null) {
569 return;
570 }
571
Lucas Dupina476c792019-06-10 18:00:22 -0700572 final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText();
Jason Monke59dc402018-08-16 12:05:01 -0400573 // Make sure we have the correct navbar/statusbar colors.
574 setKeyguardDark(useDarkText);
575 }
576
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100577 private static class State {
578 boolean keyguardShowing;
579 boolean keyguardOccluded;
580 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700581 boolean panelVisible;
582 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100583 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200584 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200585 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200586 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700587 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700588 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700589 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700590 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800591 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800592 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700593 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700594 boolean notTouchable;
Mady Mellord1c78b262018-11-06 18:04:40 -0800595 boolean bubblesShowing;
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100596 boolean bubbleExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100597
Jorim Jaggiecbab362014-04-23 16:13:15 +0200598 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500599 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200600 */
601 int statusBarState;
602
Adrian Roos1c0ca502015-10-07 12:20:42 -0700603 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800604 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700605 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800606 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700607
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100608 private boolean isKeyguardShowingAndNotOccluded() {
609 return keyguardShowing && !keyguardOccluded;
610 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200611
612 @Override
613 public String toString() {
614 StringBuilder result = new StringBuilder();
615 String newLine = "\n";
616 result.append("Window State {");
617 result.append(newLine);
618
619 Field[] fields = this.getClass().getDeclaredFields();
620
621 // Print field names paired with their values
622 for (Field field : fields) {
623 result.append(" ");
624 try {
625 result.append(field.getName());
626 result.append(": ");
627 //requires access to private field:
628 result.append(field.get(this));
629 } catch (IllegalAccessException ex) {
630 }
631 result.append(newLine);
632 }
633 result.append("}");
634
635 return result.toString();
636 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100637 }
Jason Monk421a9412017-02-06 09:15:21 -0800638
Evan Laird878c8532018-10-15 15:54:29 -0400639 private final StateListener mStateListener = new StateListener() {
640 @Override
641 public void onStateChanged(int newState) {
642 setStatusBarState(newState);
643 }
644
645 @Override
646 public void onDozingChanged(boolean isDozing) {
647 setDozing(isDozing);
648 }
649 };
650
Jason Monk421a9412017-02-06 09:15:21 -0800651 /**
652 * Custom listener to pipe data back to plugins about whether or not the status bar would be
653 * collapsed if not for the plugin.
654 * TODO: Find cleaner way to do this.
655 */
656 public interface OtherwisedCollapsedListener {
657 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
658 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100659}