blob: 62b6d91fc192bb14a44b10ac769489b1cc08f2f1 [file] [log] [blame]
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.statusbar.phone;
18
Adrian Roos7b54b072018-03-08 12:52:22 +010019import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
20
Eliot Courtneye77edea2017-11-15 14:25:21 +090021import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
22
Sudheer Shankadc589ac2016-11-10 15:30:17 -080023import android.app.ActivityManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020024import android.app.IActivityManager;
Jason Monke59dc402018-08-16 12:05:01 -040025import android.app.WallpaperManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010026import android.content.Context;
27import android.content.pm.ActivityInfo;
28import android.content.res.Resources;
29import android.graphics.PixelFormat;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080030import android.os.Binder;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020031import android.os.RemoteException;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010032import android.os.SystemProperties;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020033import android.util.Log;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010034import android.view.Gravity;
35import android.view.View;
36import android.view.ViewGroup;
37import android.view.WindowManager;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020038import android.view.WindowManager.LayoutParams;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010039
Lucas Dupina3e36272018-08-21 13:22:33 -070040import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010041import com.android.keyguard.R;
Jason Monk1fd3fc32018-08-14 17:20:09 -040042import com.android.systemui.Dependency;
Jason Monk421a9412017-02-06 09:15:21 -080043import com.android.systemui.Dumpable;
Jason Monke59dc402018-08-16 12:05:01 -040044import com.android.systemui.colorextraction.SysuiColorExtractor;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010045import com.android.systemui.keyguard.KeyguardViewMediator;
Jason Monke59dc402018-08-16 12:05:01 -040046import com.android.systemui.statusbar.RemoteInputController.Callback;
Jorim Jaggiecbab362014-04-23 16:13:15 +020047import com.android.systemui.statusbar.StatusBarState;
Jason Monk1fd3fc32018-08-14 17:20:09 -040048import com.android.systemui.statusbar.StatusBarStateController;
49import com.android.systemui.statusbar.StatusBarStateController.StateListener;
Jason Monke59dc402018-08-16 12:05:01 -040050import com.android.systemui.statusbar.policy.ConfigurationController;
51import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010052
Selim Cinek7025f262015-07-13 16:22:48 -070053import java.io.FileDescriptor;
54import java.io.PrintWriter;
Selim Cinek6a1bd2b2015-06-02 16:02:41 +020055import java.lang.reflect.Field;
56
Jorim Jaggi5cf17872014-03-26 18:31:48 +010057/**
58 * Encapsulates all logic for the status bar window state management.
59 */
Jason Monke59dc402018-08-16 12:05:01 -040060public class StatusBarWindowController implements Callback, Dumpable, ConfigurationListener {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010061
Lucas Dupin1a8588d2018-08-21 12:18:47 -070062 private static final String TAG = "StatusBarWindowController";
Jorim Jaggif6782ee2016-07-22 11:40:00 +020063
Jorim Jaggi5cf17872014-03-26 18:31:48 +010064 private final Context mContext;
65 private final WindowManager mWindowManager;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020066 private final IActivityManager mActivityManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070067 private final DozeParameters mDozeParameters;
Mady Mellord1c78b262018-11-06 18:04:40 -080068 private ViewGroup mStatusBarView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010069 private WindowManager.LayoutParams mLp;
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010070 private WindowManager.LayoutParams mLpChanged;
Jorim Jaggif6782ee2016-07-22 11:40:00 +020071 private boolean mHasTopUi;
72 private boolean mHasTopUiChanged;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073 private int mBarHeight;
74 private final boolean mKeyguardScreenRotation;
Adrian Roos3e23eb52017-07-07 15:58:57 +020075 private float mScreenBrightnessDoze;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010076 private final State mCurrentState = new State();
Jason Monk421a9412017-02-06 09:15:21 -080077 private OtherwisedCollapsedListener mListener;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078
Jason Monke59dc402018-08-16 12:05:01 -040079 private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Jason Monk1fd3fc32018-08-14 17:20:09 -040080
Lucas Dupin1a8588d2018-08-21 12:18:47 -070081 public StatusBarWindowController(Context context) {
Lucas Dupina3e36272018-08-21 13:22:33 -070082 this(context, context.getSystemService(WindowManager.class), ActivityManager.getService(),
83 DozeParameters.getInstance(context));
84 }
85
86 @VisibleForTesting
87 StatusBarWindowController(Context context, WindowManager windowManager,
88 IActivityManager activityManager, DozeParameters dozeParameters) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010089 mContext = context;
Lucas Dupina3e36272018-08-21 13:22:33 -070090 mWindowManager = windowManager;
91 mActivityManager = activityManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010092 mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
Lucas Dupina3e36272018-08-21 13:22:33 -070093 mDozeParameters = dozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070094 mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
Evan Laird91d0f102018-09-18 17:39:55 -040095 Dependency.get(StatusBarStateController.class).addListener(
96 mStateListener, StatusBarStateController.RANK_STATUS_BAR_WINDOW_CONTROLLER);
Jason Monke59dc402018-08-16 12:05:01 -040097 Dependency.get(ConfigurationController.class).addCallback(this);
Jorim Jaggi5cf17872014-03-26 18:31:48 +010098 }
99
100 private boolean shouldEnableKeyguardScreenRotation() {
101 Resources res = mContext.getResources();
102 return SystemProperties.getBoolean("lockscreen.rot_override", false)
103 || res.getBoolean(R.bool.config_enableLockScreenRotation);
104 }
105
106 /**
107 * Adds the status bar view to the window manager.
108 *
109 * @param statusBarView The view to add.
110 * @param barHeight The height of the status bar in collapsed state.
111 */
Mady Mellord1c78b262018-11-06 18:04:40 -0800112 public void add(ViewGroup statusBarView, int barHeight) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100113
114 // Now that the status bar window encompasses the sliding panel and its
115 // translucent backdrop, the entire thing is made TRANSLUCENT and is
116 // hardware-accelerated.
117 mLp = new WindowManager.LayoutParams(
118 ViewGroup.LayoutParams.MATCH_PARENT,
119 barHeight,
120 WindowManager.LayoutParams.TYPE_STATUS_BAR,
121 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
122 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
123 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
124 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Adrian Roosea562512014-05-05 13:33:03 +0200125 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100126 PixelFormat.TRANSLUCENT);
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800127 mLp.token = new Binder();
Jorim Jaggi76aaef52014-05-08 19:16:49 +0200128 mLp.gravity = Gravity.TOP;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100129 mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100130 mLp.setTitle("StatusBar");
131 mLp.packageName = mContext.getPackageName();
Adrian Roos7b54b072018-03-08 12:52:22 +0100132 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 mStatusBarView = statusBarView;
134 mBarHeight = barHeight;
135 mWindowManager.addView(mStatusBarView, mLp);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100136 mLpChanged = new WindowManager.LayoutParams();
137 mLpChanged.copyFrom(mLp);
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700138 onThemeChanged();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100139 }
140
Mady Mellord1c78b262018-11-06 18:04:40 -0800141 public ViewGroup getStatusBarView() {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800142 return mStatusBarView;
143 }
144
Adrian Roos3e23eb52017-07-07 15:58:57 +0200145 public void setDozeScreenBrightness(int value) {
146 mScreenBrightnessDoze = value / 255f;
147 }
148
Jason Monke59dc402018-08-16 12:05:01 -0400149 private void setKeyguardDark(boolean dark) {
Lucas Dupin987f1932017-05-13 21:02:52 -0700150 int vis = mStatusBarView.getSystemUiVisibility();
151 if (dark) {
152 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
153 vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
154 } else {
155 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
156 vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
157 }
158 mStatusBarView.setSystemUiVisibility(vis);
159 }
160
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100161 private void applyKeyguardFlags(State state) {
162 if (state.keyguardShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100163 mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100164 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100165 mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100166 }
Adrian Roosd5c2db62016-03-08 16:11:31 -0800167
Lucas Dupin16cfe452018-02-08 13:14:50 -0800168 final boolean scrimsOccludingWallpaper =
169 state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE;
Lucas Dupin47a65c72018-02-15 14:16:18 -0800170 final boolean keyguardOrAod = state.keyguardShowing
171 || (state.dozing && mDozeParameters.getAlwaysOn());
Selim Cinekdbf172e2018-08-08 18:31:45 +0000172 if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) {
Adrian Roosd5c2db62016-03-08 16:11:31 -0800173 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
174 } else {
175 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
176 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700177
178 if (state.dozing) {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700179 mLpChanged.privateFlags |= LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700180 } else {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700181 mLpChanged.privateFlags &= ~LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700182 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100183 }
184
185 private void adjustScreenOrientation(State state) {
Adrian Roos82069442017-06-28 19:37:24 +0200186 if (state.isKeyguardShowingAndNotOccluded() || state.dozing) {
Jorim Jaggica36cf72014-04-17 20:36:15 +0200187 if (mKeyguardScreenRotation) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100188 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200189 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100190 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Jorim Jaggica36cf72014-04-17 20:36:15 +0200191 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100192 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100193 mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100194 }
195 }
196
197 private void applyFocusableFlag(State state) {
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700198 boolean panelFocusable = state.statusBarFocusable && state.panelExpanded;
Jorim Jaggibb336692016-11-15 15:24:26 -0800199 if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput)
Eliot Courtneye77edea2017-11-15 14:25:21 +0900200 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100201 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
202 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700203 } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100204 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
205 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100206 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100207 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
208 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100209 }
Adrian Roosdc5b4532016-01-06 20:49:41 +0100210
Adrian Roos5153d4a2016-03-22 10:01:56 -0700211 mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100212 }
213
Tiger Huanga90dea42018-08-03 17:20:17 +0800214 private void applyForceShowNavigationFlag(State state) {
215 if (state.panelExpanded || state.bouncerShowing
Tiger Huang34046012018-06-29 15:26:52 +0800216 || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
Tiger Huanga90dea42018-08-03 17:20:17 +0800217 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800218 } else {
Tiger Huanga90dea42018-08-03 17:20:17 +0800219 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
Tiger Huang34046012018-06-29 15:26:52 +0800220 }
221 }
222
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100223 private void applyHeight(State state) {
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200224 boolean expanded = isExpanded(state);
Jason Monk421a9412017-02-06 09:15:21 -0800225 if (state.forcePluginOpen) {
226 mListener.setWouldOtherwiseCollapse(expanded);
227 expanded = true;
228 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100229 if (expanded) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100230 mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100231 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100232 mLpChanged.height = mBarHeight;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100233 }
234 }
235
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200236 private boolean isExpanded(State state) {
237 return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
238 || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
Mady Mellord1c78b262018-11-06 18:04:40 -0800239 || state.headsUpShowing || state.bubblesShowing
Lucas Dupin82aa1632017-12-13 00:13:57 -0800240 || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200241 }
242
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200243 private void applyFitsSystemWindows(State state) {
Adrian Roosa5d6cd02016-07-27 15:12:40 -0700244 boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded();
245 if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) {
246 mStatusBarView.setFitsSystemWindows(fitsSystemWindows);
247 mStatusBarView.requestApplyInsets();
248 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200249 }
250
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100251 private void applyUserActivityTimeout(State state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200252 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200253 && state.statusBarState == StatusBarState.KEYGUARD
254 && !state.qsExpanded) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100255 mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100256 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100257 mLpChanged.userActivityTimeout = -1;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100258 }
259 }
260
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200261 private void applyInputFeatures(State state) {
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200262 if (state.isKeyguardShowingAndNotOccluded()
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200263 && state.statusBarState == StatusBarState.KEYGUARD
Vadim Tryshev6069c402016-03-09 14:24:29 -0800264 && !state.qsExpanded && !state.forceUserActivity) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100265 mLpChanged.inputFeatures |=
266 WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200267 } else {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100268 mLpChanged.inputFeatures &=
269 ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200270 }
271 }
272
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100273 private void apply(State state) {
274 applyKeyguardFlags(state);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700275 applyForceStatusBarVisibleFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100276 applyFocusableFlag(state);
Tiger Huanga90dea42018-08-03 17:20:17 +0800277 applyForceShowNavigationFlag(state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100278 adjustScreenOrientation(state);
279 applyHeight(state);
280 applyUserActivityTimeout(state);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200281 applyInputFeatures(state);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200282 applyFitsSystemWindows(state);
Selim Cineka59ecc32015-04-07 10:51:49 -0700283 applyModalFlag(state);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700284 applyBrightness(state);
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200285 applyHasTopUi(state);
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200286 applySleepToken(state);
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700287 applyNotTouchable(state);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100288 if (mLp.copyFrom(mLpChanged) != 0) {
289 mWindowManager.updateViewLayout(mStatusBarView, mLp);
290 }
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200291 if (mHasTopUi != mHasTopUiChanged) {
292 try {
293 mActivityManager.setHasTopUi(mHasTopUiChanged);
294 } catch (RemoteException e) {
295 Log.e(TAG, "Failed to call setHasTopUi", e);
296 }
297 mHasTopUi = mHasTopUiChanged;
298 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100299 }
300
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700301 private void applyForceStatusBarVisibleFlag(State state) {
302 if (state.forceStatusBarVisible) {
303 mLpChanged.privateFlags |= WindowManager
304 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
305 } else {
306 mLpChanged.privateFlags &= ~WindowManager
307 .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
308 }
309 }
310
Selim Cineka59ecc32015-04-07 10:51:49 -0700311 private void applyModalFlag(State state) {
312 if (state.headsUpShowing) {
313 mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
314 } else {
315 mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
316 }
317 }
318
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700319 private void applyBrightness(State state) {
320 if (state.forceDozeBrightness) {
321 mLpChanged.screenBrightness = mScreenBrightnessDoze;
322 } else {
323 mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
324 }
325 }
326
Jorim Jaggif6782ee2016-07-22 11:40:00 +0200327 private void applyHasTopUi(State state) {
328 mHasTopUiChanged = isExpanded(state);
329 }
330
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200331 private void applySleepToken(State state) {
332 if (state.dozing) {
333 mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
334 } else {
335 mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
336 }
337 }
338
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700339 private void applyNotTouchable(State state) {
340 if (state.notTouchable) {
341 mLpChanged.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
342 } else {
343 mLpChanged.flags &= ~LayoutParams.FLAG_NOT_TOUCHABLE;
344 }
345 }
346
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100347 public void setKeyguardShowing(boolean showing) {
348 mCurrentState.keyguardShowing = showing;
349 apply(mCurrentState);
350 }
351
352 public void setKeyguardOccluded(boolean occluded) {
353 mCurrentState.keyguardOccluded = occluded;
354 apply(mCurrentState);
355 }
356
357 public void setKeyguardNeedsInput(boolean needsInput) {
358 mCurrentState.keyguardNeedsInput = needsInput;
359 apply(mCurrentState);
360 }
361
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700362 public void setPanelVisible(boolean visible) {
363 mCurrentState.panelVisible = visible;
364 mCurrentState.statusBarFocusable = visible;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100365 apply(mCurrentState);
366 }
367
368 public void setStatusBarFocusable(boolean focusable) {
369 mCurrentState.statusBarFocusable = focusable;
370 apply(mCurrentState);
371 }
372
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200373 public void setBouncerShowing(boolean showing) {
374 mCurrentState.bouncerShowing = showing;
375 apply(mCurrentState);
376 }
377
Adrian Roosd5c2db62016-03-08 16:11:31 -0800378 public void setBackdropShowing(boolean showing) {
379 mCurrentState.backdropShowing = showing;
380 apply(mCurrentState);
381 }
382
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200383 public void setKeyguardFadingAway(boolean keyguardFadingAway) {
384 mCurrentState.keyguardFadingAway = keyguardFadingAway;
385 apply(mCurrentState);
386 }
387
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200388 public void setQsExpanded(boolean expanded) {
389 mCurrentState.qsExpanded = expanded;
390 apply(mCurrentState);
391 }
392
Vadim Tryshev6069c402016-03-09 14:24:29 -0800393 public void setForceUserActivity(boolean forceUserActivity) {
394 mCurrentState.forceUserActivity = forceUserActivity;
395 apply(mCurrentState);
396 }
397
Lucas Dupin82aa1632017-12-13 00:13:57 -0800398 public void setScrimsVisibility(int scrimsVisibility) {
399 mCurrentState.scrimsVisibility = scrimsVisibility;
Adrian Roosa5c63222017-07-27 16:33:39 +0200400 apply(mCurrentState);
401 }
402
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700403 public void setHeadsUpShowing(boolean showing) {
404 mCurrentState.headsUpShowing = showing;
405 apply(mCurrentState);
406 }
407
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700408 public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
409 mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
410 apply(mCurrentState);
411 }
412
Jorim Jaggiecbab362014-04-23 16:13:15 +0200413 /**
Jason Monk1fd3fc32018-08-14 17:20:09 -0400414 * @param state The {@link StatusBarStateController} of the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200415 */
Jason Monk1fd3fc32018-08-14 17:20:09 -0400416 private void setStatusBarState(int state) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200417 mCurrentState.statusBarState = state;
418 apply(mCurrentState);
419 }
420
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700421 public void setForceStatusBarVisible(boolean forceStatusBarVisible) {
422 mCurrentState.forceStatusBarVisible = forceStatusBarVisible;
423 apply(mCurrentState);
424 }
425
Selim Cinek737bff32015-05-08 16:08:35 -0700426 /**
427 * Force the window to be collapsed, even if it should theoretically be expanded.
428 * Used for when a heads-up comes in but we still need to wait for the touchable regions to
429 * be computed.
430 */
431 public void setForceWindowCollapsed(boolean force) {
432 mCurrentState.forceCollapsed = force;
433 apply(mCurrentState);
434 }
435
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700436 public void setPanelExpanded(boolean isExpanded) {
437 mCurrentState.panelExpanded = isExpanded;
438 apply(mCurrentState);
439 }
440
Adrian Roosd28ccd72016-01-06 15:23:14 +0100441 @Override
442 public void onRemoteInputActive(boolean remoteInputActive) {
Adrian Roos1c0ca502015-10-07 12:20:42 -0700443 mCurrentState.remoteInputActive = remoteInputActive;
444 apply(mCurrentState);
445 }
446
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700447 /**
448 * Set whether the screen brightness is forced to the value we use for doze mode by the status
449 * bar window.
450 */
451 public void setForceDozeBrightness(boolean forceDozeBrightness) {
452 mCurrentState.forceDozeBrightness = forceDozeBrightness;
453 apply(mCurrentState);
454 }
455
Adrian Roos67cca742017-04-13 16:52:51 -0700456 public void setDozing(boolean dozing) {
457 mCurrentState.dozing = dozing;
458 apply(mCurrentState);
459 }
460
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700461 public void setBarHeight(int barHeight) {
462 mBarHeight = barHeight;
463 apply(mCurrentState);
464 }
465
Jason Monk421a9412017-02-06 09:15:21 -0800466 public void setForcePluginOpen(boolean forcePluginOpen) {
467 mCurrentState.forcePluginOpen = forcePluginOpen;
468 apply(mCurrentState);
469 }
470
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700471 public void setNotTouchable(boolean notTouchable) {
472 mCurrentState.notTouchable = notTouchable;
473 apply(mCurrentState);
474 }
475
Mady Mellord1c78b262018-11-06 18:04:40 -0800476 /**
477 * Sets whether there are bubbles showing on the screen.
478 */
479 public void setBubblesShowing(boolean bubblesShowing) {
480 mCurrentState.bubblesShowing = bubblesShowing;
481 apply(mCurrentState);
482 }
483
484 /**
485 * The bubbles showing state for the status bar.
486 */
487 public boolean getBubblesShowing() {
488 return mCurrentState.bubblesShowing;
489 }
490
Jason Monk421a9412017-02-06 09:15:21 -0800491 public void setStateListener(OtherwisedCollapsedListener listener) {
492 mListener = listener;
493 }
494
Selim Cinek7025f262015-07-13 16:22:48 -0700495 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700496 pw.println("StatusBarWindowController state:");
Selim Cinek7025f262015-07-13 16:22:48 -0700497 pw.println(mCurrentState);
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200498 }
499
Adrian Roosd5c2db62016-03-08 16:11:31 -0800500 public boolean isShowingWallpaper() {
501 return !mCurrentState.backdropShowing;
502 }
503
Jason Monke59dc402018-08-16 12:05:01 -0400504 @Override
505 public void onThemeChanged() {
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700506 if (mStatusBarView == null) {
507 return;
508 }
509
Jason Monke59dc402018-08-16 12:05:01 -0400510 StatusBarStateController state = Dependency.get(StatusBarStateController.class);
511 int which;
512 if (state.getState() == StatusBarState.KEYGUARD
513 || state.getState() == StatusBarState.SHADE_LOCKED) {
514 which = WallpaperManager.FLAG_LOCK;
515 } else {
516 which = WallpaperManager.FLAG_SYSTEM;
517 }
518 final boolean useDarkText = mColorExtractor.getColors(which,
519 true /* ignoreVisibility */).supportsDarkText();
520
521 // Make sure we have the correct navbar/statusbar colors.
522 setKeyguardDark(useDarkText);
523 }
524
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100525 private static class State {
526 boolean keyguardShowing;
527 boolean keyguardOccluded;
528 boolean keyguardNeedsInput;
Selim Cinek4a21a7f2015-05-19 11:00:38 -0700529 boolean panelVisible;
530 boolean panelExpanded;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100531 boolean statusBarFocusable;
Jorim Jaggi5fd4d052014-05-13 22:50:20 +0200532 boolean bouncerShowing;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200533 boolean keyguardFadingAway;
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200534 boolean qsExpanded;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700535 boolean headsUpShowing;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700536 boolean forceStatusBarVisible;
Selim Cinek737bff32015-05-08 16:08:35 -0700537 boolean forceCollapsed;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700538 boolean forceDozeBrightness;
Vadim Tryshev6069c402016-03-09 14:24:29 -0800539 boolean forceUserActivity;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800540 boolean backdropShowing;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700541 boolean wallpaperSupportsAmbientMode;
Hyunyoung Songc1647ea2018-08-20 12:23:46 -0700542 boolean notTouchable;
Mady Mellord1c78b262018-11-06 18:04:40 -0800543 boolean bubblesShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100544
Jorim Jaggiecbab362014-04-23 16:13:15 +0200545 /**
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500546 * The {@link StatusBar} state from the status bar.
Jorim Jaggiecbab362014-04-23 16:13:15 +0200547 */
548 int statusBarState;
549
Adrian Roos1c0ca502015-10-07 12:20:42 -0700550 boolean remoteInputActive;
Jason Monk421a9412017-02-06 09:15:21 -0800551 boolean forcePluginOpen;
Adrian Roos67cca742017-04-13 16:52:51 -0700552 boolean dozing;
Lucas Dupin82aa1632017-12-13 00:13:57 -0800553 int scrimsVisibility;
Adrian Roos1c0ca502015-10-07 12:20:42 -0700554
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100555 private boolean isKeyguardShowingAndNotOccluded() {
556 return keyguardShowing && !keyguardOccluded;
557 }
Selim Cinek6a1bd2b2015-06-02 16:02:41 +0200558
559 @Override
560 public String toString() {
561 StringBuilder result = new StringBuilder();
562 String newLine = "\n";
563 result.append("Window State {");
564 result.append(newLine);
565
566 Field[] fields = this.getClass().getDeclaredFields();
567
568 // Print field names paired with their values
569 for (Field field : fields) {
570 result.append(" ");
571 try {
572 result.append(field.getName());
573 result.append(": ");
574 //requires access to private field:
575 result.append(field.get(this));
576 } catch (IllegalAccessException ex) {
577 }
578 result.append(newLine);
579 }
580 result.append("}");
581
582 return result.toString();
583 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100584 }
Jason Monk421a9412017-02-06 09:15:21 -0800585
Evan Laird878c8532018-10-15 15:54:29 -0400586 private final StateListener mStateListener = new StateListener() {
587 @Override
588 public void onStateChanged(int newState) {
589 setStatusBarState(newState);
590 }
591
592 @Override
593 public void onDozingChanged(boolean isDozing) {
594 setDozing(isDozing);
595 }
596 };
597
Jason Monk421a9412017-02-06 09:15:21 -0800598 /**
599 * Custom listener to pipe data back to plugins about whether or not the status bar would be
600 * collapsed if not for the plugin.
601 * TODO: Find cleaner way to do this.
602 */
603 public interface OtherwisedCollapsedListener {
604 void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
605 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100606}