blob: 4ddd0e9962ad879e28aba90ee3b2c707aa0d26d0 [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 Chungdc0eca62019-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 Chungdc0eca62019-06-13 22:37:31 -070056import java.lang.ref.WeakReference;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020057import java.lang.reflect.Field;
58
Winson Chungdc0eca62019-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;
Lucas Dupine90fead2019-06-12 16:22:41 -070077 private final long mLockScreenDisplayTimeout;
Mady Mellord1c78b262018-11-06 18:04:40 -080078 private ViewGroup mStatusBarView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010079 private WindowManager.LayoutParams mLp;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020080 private boolean mHasTopUi;
81 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010082 private int mBarHeight;
Adrian Roos3e23eb52017-07-07 15:58:57 +020083 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010084 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080085 private OtherwisedCollapsedListener mListener;
Beverly4ec838b2019-05-29 11:34:45 -040086 private ForcePluginOpenListener mForcePluginOpenListener;
Winson Chungdc0eca62019-06-13 22:37:31 -070087 private final ArrayList<WeakReference<StatusBarWindowCallback>>
88 mCallbacks = Lists.newArrayList();
Jorim Jaggi5cf17872014-03-26 18:31:48 +010089
Jason Monke59dc402018-08-16 12:05:01 -040090 private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Jason Monk1fd3fc32018-08-14 17:20:09 -040091
Jason Monk196d6392018-12-20 13:25:34 -050092 @Inject
Lucas Dupin1a8588d2018-08-21 12:18:47 -070093 public StatusBarWindowController(Context context) {
Lucas Dupina3e36272018-08-21 13:22:33 -070094 this(context, context.getSystemService(WindowManager.class), ActivityManager.getService(),
95 DozeParameters.getInstance(context));
96 }
97
98 @VisibleForTesting
Mady Mellorebdbbb92018-11-15 14:36:48 -080099 public StatusBarWindowController(Context context, WindowManager windowManager,
Lucas Dupina3e36272018-08-21 13:22:33 -0700100 IActivityManager activityManager, DozeParameters dozeParameters) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100101 mContext = context;
Lucas Dupina3e36272018-08-21 13:22:33 -0700102 mWindowManager = windowManager;
103 mActivityManager = activityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100104 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupina3e36272018-08-21 13:22:33 -0700105 mDozeParameters = dozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700106 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800107 mLpChanged = new WindowManager.LayoutParams();
Lucas Dupine90fead2019-06-12 16:22:41 -0700108 mLockScreenDisplayTimeout = context.getResources()
109 .getInteger(R.integer.config_lockScreenDisplayTimeout);
Beverly8fdb5332019-02-04 14:29:49 -0500110 ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class))
111 .addCallback(mStateListener,
112 SysuiStatusBarStateController.RANK_STATUS_BAR_WINDOW_CONTROLLER);
Jason Monke59dc402018-08-16 12:05:01 -0400113 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100114 }
115
Winson Chungdc0eca62019-06-13 22:37:31 -0700116 /**
117 * Register to receive notifications about status bar window state changes.
118 */
119 public void registerCallback(StatusBarWindowCallback callback) {
120 // Prevent adding duplicate callbacks
121 for (int i = 0; i < mCallbacks.size(); i++) {
122 if (mCallbacks.get(i).get() == callback) {
123 return;
124 }
125 }
126 mCallbacks.add(new WeakReference<StatusBarWindowCallback>(callback));
127 }
128
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100129 private boolean shouldEnableKeyguardScreenRotation() {
130 Resources res = mContext.getResources();
131 return SystemProperties.getBoolean("lockscreen.rot_override", false)
132 || res.getBoolean(R.bool.config_enableLockScreenRotation);
133 }
134
135 /**
136 * Adds the status bar view to the window manager.
137 *
138 * @param statusBarView The view to add.
139 * @param barHeight The height of the status bar in collapsed state.
140 */
Mady Mellord1c78b262018-11-06 18:04:40 -0800141 public void add(ViewGroup statusBarView, int barHeight) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100142
143 // Now that the status bar window encompasses the sliding panel and its
144 // translucent backdrop, the entire thing is made TRANSLUCENT and is
145 // hardware-accelerated.
146 mLp = new WindowManager.LayoutParams(
147 ViewGroup.LayoutParams.MATCH_PARENT,
148 barHeight,
149 WindowManager.LayoutParams.TYPE_STATUS_BAR,
150 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
151 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
152 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
153 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200154 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100155 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800156 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200157 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100158 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100159 mLp.setTitle("StatusBar");
160 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100161 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100162 mStatusBarView = statusBarView;
163 mBarHeight = barHeight;
164 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100165 mLpChanged.copyFrom(mLp);
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700166 onThemeChanged();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100167 }
168
Mady Mellord1c78b262018-11-06 18:04:40 -0800169 public ViewGroup getStatusBarView() {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800170 return mStatusBarView;
171 }
172
Adrian Roos3e23eb52017-07-07 15:58:57 +0200173 public void setDozeScreenBrightness(int value) {
174 mScreenBrightnessDoze = value / 255f;
175 }
176
Jason Monke59dc402018-08-16 12:05:01 -0400177 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700178 int vis = mStatusBarView.getSystemUiVisibility();
179 if (dark) {
180 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
181 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
182 } else {
183 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
184 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
185 }
186 mStatusBarView.setSystemUiVisibility(vis);
187 }
188
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100189 private void applyKeyguardFlags(State state) {
190 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100191 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100192 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100193 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100194 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800195
Lucas Dupin16cfe452018-02-08 13:14:50 -0800196 final boolean scrimsOccludingWallpaper =
197 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800198 final boolean keyguardOrAod = state.keyguardShowing
199 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000200 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800201 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
202 } else {
203 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
204 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700205
206 if (state.dozing) {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700207 mLpChanged.privateFlags |= LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700208 } else {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700209 mLpChanged.privateFlags &= ~LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700210 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100211 }
212
213 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200214 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200215 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100216 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200217 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100218 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200219 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100220 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100221 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100222 }
223 }
224
225 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700226 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800227 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100228 || ENABLE_REMOTE_INPUT && state.remoteInputActive
229 || state.bubbleExpanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100230 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
231 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Matt Caseya0966b52019-05-15 18:49:37 -0400232 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100233 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
234 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100235 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100236 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
237 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100238 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100239
Adrian Roos5153d4a2016-03-22 10:01:56 -0700240 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100241 }
242
Tiger Huanga90dea42018-08-03 17:20:17 +0800243 private void applyForceShowNavigationFlag(State state) {
244 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800245 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800246 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800247 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800248 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800249 }
250 }
251
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100252 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200253 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800254 if (state.forcePluginOpen) {
Lucas Dupin42ebe542019-01-22 09:45:09 -0800255 if (mListener != null) {
256 mListener.setWouldOtherwiseCollapse(expanded);
257 }
Jason Monk421a9412017-02-06 09:15:21 -0800258 expanded = true;
259 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100260 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100261 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100262 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100263 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100264 }
265 }
266
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200267 private boolean isExpanded(State state) {
268 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
269 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Matt Caseya0966b52019-05-15 18:49:37 -0400270 || state.headsUpShowing || state.bubblesShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800271 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200272 }
273
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200274 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700275 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
Lucas Dupin42ebe542019-01-22 09:45:09 -0800276 if (mStatusBarView != null && mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700277 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
278 mStatusBarView.requestApplyInsets();
279 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200280 }
281
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100282 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200283 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200284 && state.statusBarState == StatusBarState.KEYGUARD
285 && !state.qsExpanded) {
Lucas Dupine90fead2019-06-12 16:22:41 -0700286 mLpChanged.userActivityTimeout = state.bouncerShowing
287 ? KeyguardViewMediator.AWAKE_INTERVAL_BOUNCER_MS : mLockScreenDisplayTimeout;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100288 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100289 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100290 }
291 }
292
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200293 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200294 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200295 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800296 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100297 mLpChanged.inputFeatures |=
298 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200299 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100300 mLpChanged.inputFeatures &=
301 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200302 }
303 }
304
Peiyong Lin75045382019-03-04 19:22:33 -0800305 private void applyStatusBarColorSpaceAgnosticFlag(State state) {
306 if (!isExpanded(state)) {
307 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
308 } else {
309 mLpChanged.privateFlags &=
310 ~WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
311 }
312 }
313
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100314 private void apply(State state) {
315 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700316 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100317 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800318 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100319 adjustScreenOrientation(state);
320 applyHeight(state);
321 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200322 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200323 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700324 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700325 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200326 applyHasTopUi(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700327 applyNotTouchable(state);
Peiyong Lin75045382019-03-04 19:22:33 -0800328 applyStatusBarColorSpaceAgnosticFlag(state);
Lucas Dupin42ebe542019-01-22 09:45:09 -0800329 if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100330 mWindowManager.updateViewLayout(mStatusBarView, mLp);
331 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200332 if (mHasTopUi != mHasTopUiChanged) {
333 try {
334 mActivityManager.setHasTopUi(mHasTopUiChanged);
335 } catch (RemoteException e) {
336 Log.e(TAG, "Failed to call setHasTopUi", e);
337 }
338 mHasTopUi = mHasTopUiChanged;
339 }
Winson Chungdc0eca62019-06-13 22:37:31 -0700340 notifyStateChangedCallbacks();
Winson Chung7bbeb452019-06-04 10:25:50 -0700341 }
342
Winson Chungdc0eca62019-06-13 22:37:31 -0700343 public void notifyStateChangedCallbacks() {
344 for (int i = 0; i < mCallbacks.size(); i++) {
345 StatusBarWindowCallback cb = mCallbacks.get(i).get();
346 if (cb != null) {
347 cb.onStateChanged(mCurrentState.keyguardShowing,
348 mCurrentState.keyguardOccluded,
349 mCurrentState.bouncerShowing);
350 }
351 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100352 }
353
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700354 private void applyForceStatusBarVisibleFlag(State state) {
355 if (state.forceStatusBarVisible) {
356 mLpChanged.privateFlags |= WindowManager
357 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
358 } else {
359 mLpChanged.privateFlags &= ~WindowManager
360 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
361 }
362 }
363
Selim Cineka59ecc32015-04-07 10:51:49 -0700364 private void applyModalFlag(State state) {
365 if (state.headsUpShowing) {
366 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
367 } else {
368 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
369 }
370 }
371
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700372 private void applyBrightness(State state) {
373 if (state.forceDozeBrightness) {
374 mLpChanged.screenBrightness = mScreenBrightnessDoze;
375 } else {
376 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
377 }
378 }
379
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200380 private void applyHasTopUi(State state) {
381 mHasTopUiChanged = isExpanded(state);
382 }
383
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700384 private void applyNotTouchable(State state) {
385 if (state.notTouchable) {
386 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
387 } else {
388 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
389 }
390 }
391
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100392 public void setKeyguardShowing(boolean showing) {
393 mCurrentState.keyguardShowing = showing;
394 apply(mCurrentState);
395 }
396
397 public void setKeyguardOccluded(boolean occluded) {
398 mCurrentState.keyguardOccluded = occluded;
399 apply(mCurrentState);
400 }
401
402 public void setKeyguardNeedsInput(boolean needsInput) {
403 mCurrentState.keyguardNeedsInput = needsInput;
404 apply(mCurrentState);
405 }
406
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700407 public void setPanelVisible(boolean visible) {
408 mCurrentState.panelVisible = visible;
409 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100410 apply(mCurrentState);
411 }
412
413 public void setStatusBarFocusable(boolean focusable) {
414 mCurrentState.statusBarFocusable = focusable;
415 apply(mCurrentState);
416 }
417
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200418 public void setBouncerShowing(boolean showing) {
419 mCurrentState.bouncerShowing = showing;
420 apply(mCurrentState);
421 }
422
Adrian Roosd5c2db62016-03-08 16:11:31 -0800423 public void setBackdropShowing(boolean showing) {
424 mCurrentState.backdropShowing = showing;
425 apply(mCurrentState);
426 }
427
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200428 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
429 mCurrentState.keyguardFadingAway = keyguardFadingAway;
430 apply(mCurrentState);
431 }
432
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200433 public void setQsExpanded(boolean expanded) {
434 mCurrentState.qsExpanded = expanded;
435 apply(mCurrentState);
436 }
437
Vadim Tryshev6069c402016-03-09 14:24:29 -0800438 public void setForceUserActivity(boolean forceUserActivity) {
439 mCurrentState.forceUserActivity = forceUserActivity;
440 apply(mCurrentState);
441 }
442
Lucas Dupin82aa1632017-12-13 00:13:57 -0800443 public void setScrimsVisibility(int scrimsVisibility) {
444 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200445 apply(mCurrentState);
446 }
447
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700448 public void setHeadsUpShowing(boolean showing) {
449 mCurrentState.headsUpShowing = showing;
450 apply(mCurrentState);
451 }
452
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700453 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
454 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
455 apply(mCurrentState);
456 }
457
Jorim Jaggiecbab362014-04-23 16:13:15 +0200458 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400459 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200460 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400461 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200462 mCurrentState.statusBarState = state;
463 apply(mCurrentState);
464 }
465
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700466 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
467 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
468 apply(mCurrentState);
469 }
470
Selim Cinek737bff32015-05-08 16:08:35 -0700471 /**
472 * Force the window to be collapsed, even if it should theoretically be expanded.
473 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
474 * be computed.
475 */
476 public void setForceWindowCollapsed(boolean force) {
477 mCurrentState.forceCollapsed = force;
478 apply(mCurrentState);
479 }
480
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700481 public void setPanelExpanded(boolean isExpanded) {
482 mCurrentState.panelExpanded = isExpanded;
483 apply(mCurrentState);
484 }
485
Adrian Roosd28ccd72016-01-06 15:23:14 +0100486 @Override
487 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700488 mCurrentState.remoteInputActive = remoteInputActive;
489 apply(mCurrentState);
490 }
491
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700492 /**
493 * Set whether the screen brightness is forced to the value we use for doze mode by the status
494 * bar window.
495 */
496 public void setForceDozeBrightness(boolean forceDozeBrightness) {
497 mCurrentState.forceDozeBrightness = forceDozeBrightness;
498 apply(mCurrentState);
499 }
500
Adrian Roos67cca742017-04-13 16:52:51 -0700501 public void setDozing(boolean dozing) {
502 mCurrentState.dozing = dozing;
503 apply(mCurrentState);
504 }
505
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700506 public void setBarHeight(int barHeight) {
507 mBarHeight = barHeight;
508 apply(mCurrentState);
509 }
510
Jason Monk421a9412017-02-06 09:15:21 -0800511 public void setForcePluginOpen(boolean forcePluginOpen) {
512 mCurrentState.forcePluginOpen = forcePluginOpen;
513 apply(mCurrentState);
Beverly4ec838b2019-05-29 11:34:45 -0400514 if (mForcePluginOpenListener != null) {
515 mForcePluginOpenListener.onChange(forcePluginOpen);
516 }
517 }
518
519 /**
520 * The forcePluginOpen state for the status bar.
521 */
522 public boolean getForcePluginOpen() {
523 return mCurrentState.forcePluginOpen;
Jason Monk421a9412017-02-06 09:15:21 -0800524 }
525
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700526 public void setNotTouchable(boolean notTouchable) {
527 mCurrentState.notTouchable = notTouchable;
528 apply(mCurrentState);
529 }
530
Mady Mellord1c78b262018-11-06 18:04:40 -0800531 /**
532 * Sets whether there are bubbles showing on the screen.
533 */
534 public void setBubblesShowing(boolean bubblesShowing) {
535 mCurrentState.bubblesShowing = bubblesShowing;
536 apply(mCurrentState);
537 }
538
539 /**
540 * The bubbles showing state for the status bar.
541 */
542 public boolean getBubblesShowing() {
543 return mCurrentState.bubblesShowing;
544 }
545
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100546 /**
547 * Sets if there is a bubble being expanded on the screen.
548 */
549 public void setBubbleExpanded(boolean bubbleExpanded) {
550 mCurrentState.bubbleExpanded = bubbleExpanded;
551 apply(mCurrentState);
552 }
553
554 /**
Mady Mellor390bff42019-04-05 15:09:01 -0700555 * Whether the bubble is shown in expanded state for the status bar.
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100556 */
557 public boolean getBubbleExpanded() {
558 return mCurrentState.bubbleExpanded;
559 }
560
Mady Mellor390bff42019-04-05 15:09:01 -0700561 /**
562 * Whether the status bar panel is expanded or not.
563 */
564 public boolean getPanelExpanded() {
565 return mCurrentState.panelExpanded;
566 }
567
Jason Monk421a9412017-02-06 09:15:21 -0800568 public void setStateListener(OtherwisedCollapsedListener listener) {
569 mListener = listener;
570 }
571
Beverly4ec838b2019-05-29 11:34:45 -0400572 public void setForcePluginOpenListener(ForcePluginOpenListener listener) {
573 mForcePluginOpenListener = listener;
574 }
575
Selim Cinek7025f262015-07-13 16:22:48 -0700576 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700577 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700578 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200579 }
580
Adrian Roosd5c2db62016-03-08 16:11:31 -0800581 public boolean isShowingWallpaper() {
582 return !mCurrentState.backdropShowing;
583 }
584
Jason Monke59dc402018-08-16 12:05:01 -0400585 @Override
586 public void onThemeChanged() {
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700587 if (mStatusBarView == null) {
588 return;
589 }
590
Lucas Dupin89233c42019-06-10 18:00:22 -0700591 final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText();
Jason Monke59dc402018-08-16 12:05:01 -0400592 // Make sure we have the correct navbar/statusbar colors.
593 setKeyguardDark(useDarkText);
594 }
595
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100596 private static class State {
597 boolean keyguardShowing;
598 boolean keyguardOccluded;
599 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700600 boolean panelVisible;
601 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100602 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200603 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200604 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200605 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700606 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700607 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700608 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700609 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800610 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800611 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700612 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700613 boolean notTouchable;
Mady Mellord1c78b262018-11-06 18:04:40 -0800614 boolean bubblesShowing;
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100615 boolean bubbleExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100616
Jorim Jaggiecbab362014-04-23 16:13:15 +0200617 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500618 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200619 */
620 int statusBarState;
621
Adrian Roos1c0ca502015-10-07 12:20:42 -0700622 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800623 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700624 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800625 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700626
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100627 private boolean isKeyguardShowingAndNotOccluded() {
628 return keyguardShowing && !keyguardOccluded;
629 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200630
631 @Override
632 public String toString() {
633 StringBuilder result = new StringBuilder();
634 String newLine = "\n";
635 result.append("Window State {");
636 result.append(newLine);
637
638 Field[] fields = this.getClass().getDeclaredFields();
639
640 // Print field names paired with their values
641 for (Field field : fields) {
642 result.append(" ");
643 try {
644 result.append(field.getName());
645 result.append(": ");
646 //requires access to private field:
647 result.append(field.get(this));
648 } catch (IllegalAccessException ex) {
649 }
650 result.append(newLine);
651 }
652 result.append("}");
653
654 return result.toString();
655 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100656 }
Jason Monk421a9412017-02-06 09:15:21 -0800657
Evan Laird878c8532018-10-15 15:54:29 -0400658 private final StateListener mStateListener = new StateListener() {
659 @Override
660 public void onStateChanged(int newState) {
661 setStatusBarState(newState);
662 }
663
664 @Override
665 public void onDozingChanged(boolean isDozing) {
666 setDozing(isDozing);
667 }
668 };
669
Jason Monk421a9412017-02-06 09:15:21 -0800670 /**
671 * Custom listener to pipe data back to plugins about whether or not the status bar would be
672 * collapsed if not for the plugin.
673 * TODO: Find cleaner way to do this.
674 */
675 public interface OtherwisedCollapsedListener {
676 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
677 }
Beverly4ec838b2019-05-29 11:34:45 -0400678
679 /**
680 * Listener to indicate forcePluginOpen has changed
681 */
682 public interface ForcePluginOpenListener {
683 /**
684 * Called when mState.forcePluginOpen is changed
685 */
686 void onChange(boolean forceOpen);
687 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100688}