Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Adrian Roos | 7b54b07 | 2018-03-08 12:52:22 +0100 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 20 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT; |
| 22 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 24 | import android.app.IActivityManager; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.pm.ActivityInfo; |
| 27 | import android.content.res.Resources; |
| 28 | import android.graphics.PixelFormat; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 29 | import android.os.Binder; |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 30 | import android.os.RemoteException; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 31 | import android.os.SystemProperties; |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 32 | import android.util.Log; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 33 | import android.view.Gravity; |
| 34 | import android.view.View; |
| 35 | import android.view.ViewGroup; |
| 36 | import android.view.WindowManager; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 37 | import android.view.WindowManager.LayoutParams; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 38 | |
| 39 | import com.android.keyguard.R; |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 40 | import com.android.systemui.Dumpable; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 41 | import com.android.systemui.keyguard.KeyguardViewMediator; |
Adrian Roos | d28ccd7 | 2016-01-06 15:23:14 +0100 | [diff] [blame] | 42 | import com.android.systemui.statusbar.RemoteInputController; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 43 | import com.android.systemui.statusbar.StatusBarState; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 44 | |
Selim Cinek | 7025f26 | 2015-07-13 16:22:48 -0700 | [diff] [blame] | 45 | import java.io.FileDescriptor; |
| 46 | import java.io.PrintWriter; |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 47 | import java.lang.reflect.Field; |
| 48 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 49 | /** |
| 50 | * Encapsulates all logic for the status bar window state management. |
| 51 | */ |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 52 | public class StatusBarWindowManager implements RemoteInputController.Callback, Dumpable { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 53 | |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 54 | private static final String TAG = "StatusBarWindowManager"; |
| 55 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 56 | private final Context mContext; |
| 57 | private final WindowManager mWindowManager; |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 58 | private final IActivityManager mActivityManager; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 59 | private final DozeParameters mDozeParameters; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 60 | private View mStatusBarView; |
| 61 | private WindowManager.LayoutParams mLp; |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 62 | private WindowManager.LayoutParams mLpChanged; |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 63 | private boolean mHasTopUi; |
| 64 | private boolean mHasTopUiChanged; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 65 | private int mBarHeight; |
| 66 | private final boolean mKeyguardScreenRotation; |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 67 | private float mScreenBrightnessDoze; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 68 | private final State mCurrentState = new State(); |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 69 | private OtherwisedCollapsedListener mListener; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 70 | |
| 71 | public StatusBarWindowManager(Context context) { |
| 72 | mContext = context; |
| 73 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 74 | mActivityManager = ActivityManager.getService(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 75 | mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 76 | mDozeParameters = DozeParameters.getInstance(mContext); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 77 | mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | private boolean shouldEnableKeyguardScreenRotation() { |
| 81 | Resources res = mContext.getResources(); |
| 82 | return SystemProperties.getBoolean("lockscreen.rot_override", false) |
| 83 | || res.getBoolean(R.bool.config_enableLockScreenRotation); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Adds the status bar view to the window manager. |
| 88 | * |
| 89 | * @param statusBarView The view to add. |
| 90 | * @param barHeight The height of the status bar in collapsed state. |
| 91 | */ |
| 92 | public void add(View statusBarView, int barHeight) { |
| 93 | |
| 94 | // Now that the status bar window encompasses the sliding panel and its |
| 95 | // translucent backdrop, the entire thing is made TRANSLUCENT and is |
| 96 | // hardware-accelerated. |
| 97 | mLp = new WindowManager.LayoutParams( |
| 98 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 99 | barHeight, |
| 100 | WindowManager.LayoutParams.TYPE_STATUS_BAR, |
| 101 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 102 | | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 103 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 104 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 105 | | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 106 | PixelFormat.TRANSLUCENT); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 107 | mLp.token = new Binder(); |
Jorim Jaggi | 76aaef5 | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 108 | mLp.gravity = Gravity.TOP; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 109 | mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 110 | mLp.setTitle("StatusBar"); |
| 111 | mLp.packageName = mContext.getPackageName(); |
Adrian Roos | 7b54b07 | 2018-03-08 12:52:22 +0100 | [diff] [blame] | 112 | mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 113 | mStatusBarView = statusBarView; |
| 114 | mBarHeight = barHeight; |
| 115 | mWindowManager.addView(mStatusBarView, mLp); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 116 | mLpChanged = new WindowManager.LayoutParams(); |
| 117 | mLpChanged.copyFrom(mLp); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 120 | public void setDozeScreenBrightness(int value) { |
| 121 | mScreenBrightnessDoze = value / 255f; |
| 122 | } |
| 123 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 124 | public void setKeyguardDark(boolean dark) { |
| 125 | int vis = mStatusBarView.getSystemUiVisibility(); |
| 126 | if (dark) { |
| 127 | vis = vis | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 128 | vis = vis | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 129 | } else { |
| 130 | vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 131 | vis = vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 132 | } |
| 133 | mStatusBarView.setSystemUiVisibility(vis); |
| 134 | } |
| 135 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 136 | private void applyKeyguardFlags(State state) { |
| 137 | if (state.keyguardShowing) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 138 | mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 139 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 140 | mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 141 | } |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 142 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 143 | final boolean scrimsOccludingWallpaper = |
| 144 | state.scrimsVisibility == ScrimController.VISIBILITY_FULLY_OPAQUE; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 145 | final boolean keyguardOrAod = state.keyguardShowing |
| 146 | || (state.dozing && mDozeParameters.getAlwaysOn()); |
| 147 | if (keyguardOrAod && !state.backdropShowing && !scrimsOccludingWallpaper) { |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 148 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 149 | } else { |
| 150 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 151 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | private void adjustScreenOrientation(State state) { |
Adrian Roos | 8206944 | 2017-06-28 19:37:24 +0200 | [diff] [blame] | 155 | if (state.isKeyguardShowingAndNotOccluded() || state.dozing) { |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 156 | if (mKeyguardScreenRotation) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 157 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER; |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 158 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 159 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 160 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 161 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 162 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | private void applyFocusableFlag(State state) { |
Selim Cinek | 4a21a7f | 2015-05-19 11:00:38 -0700 | [diff] [blame] | 167 | boolean panelFocusable = state.statusBarFocusable && state.panelExpanded; |
Jorim Jaggi | bb33669 | 2016-11-15 15:24:26 -0800 | [diff] [blame] | 168 | if (state.bouncerShowing && (state.keyguardOccluded || state.keyguardNeedsInput) |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 169 | || ENABLE_REMOTE_INPUT && state.remoteInputActive) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 170 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 171 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Selim Cinek | 4a21a7f | 2015-05-19 11:00:38 -0700 | [diff] [blame] | 172 | } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 173 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 174 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 175 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 176 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 177 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 178 | } |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 179 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 180 | mLpChanged.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Tiger Huang | 926f7d8 | 2018-06-29 15:26:52 +0800 | [diff] [blame] | 183 | private void applyExpandedFlag(State state) { |
| 184 | if (state.panelExpanded || state.isKeyguardShowingAndNotOccluded() || state.bouncerShowing |
| 185 | || ENABLE_REMOTE_INPUT && state.remoteInputActive) { |
| 186 | mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_BAR_EXPANDED; |
| 187 | } else { |
| 188 | mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_BAR_EXPANDED; |
| 189 | } |
| 190 | } |
| 191 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 192 | private void applyHeight(State state) { |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 193 | boolean expanded = isExpanded(state); |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 194 | if (state.forcePluginOpen) { |
| 195 | mListener.setWouldOtherwiseCollapse(expanded); |
| 196 | expanded = true; |
| 197 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 198 | if (expanded) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 199 | mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 200 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 201 | mLpChanged.height = mBarHeight; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 205 | private boolean isExpanded(State state) { |
| 206 | return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded() |
| 207 | || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 208 | || state.headsUpShowing |
| 209 | || state.scrimsVisibility != ScrimController.VISIBILITY_FULLY_TRANSPARENT); |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 212 | private void applyFitsSystemWindows(State state) { |
Adrian Roos | a5d6cd0 | 2016-07-27 15:12:40 -0700 | [diff] [blame] | 213 | boolean fitsSystemWindows = !state.isKeyguardShowingAndNotOccluded(); |
| 214 | if (mStatusBarView.getFitsSystemWindows() != fitsSystemWindows) { |
| 215 | mStatusBarView.setFitsSystemWindows(fitsSystemWindows); |
| 216 | mStatusBarView.requestApplyInsets(); |
| 217 | } |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 220 | private void applyUserActivityTimeout(State state) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 221 | if (state.isKeyguardShowingAndNotOccluded() |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 222 | && state.statusBarState == StatusBarState.KEYGUARD |
| 223 | && !state.qsExpanded) { |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 224 | mLpChanged.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 225 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 226 | mLpChanged.userActivityTimeout = -1; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 230 | private void applyInputFeatures(State state) { |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 231 | if (state.isKeyguardShowingAndNotOccluded() |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 232 | && state.statusBarState == StatusBarState.KEYGUARD |
Vadim Tryshev | 6069c40 | 2016-03-09 14:24:29 -0800 | [diff] [blame] | 233 | && !state.qsExpanded && !state.forceUserActivity) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 234 | mLpChanged.inputFeatures |= |
| 235 | WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 236 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 237 | mLpChanged.inputFeatures &= |
| 238 | ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 242 | private void apply(State state) { |
| 243 | applyKeyguardFlags(state); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 244 | applyForceStatusBarVisibleFlag(state); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 245 | applyFocusableFlag(state); |
Tiger Huang | 926f7d8 | 2018-06-29 15:26:52 +0800 | [diff] [blame] | 246 | applyExpandedFlag(state); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 247 | adjustScreenOrientation(state); |
| 248 | applyHeight(state); |
| 249 | applyUserActivityTimeout(state); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 250 | applyInputFeatures(state); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 251 | applyFitsSystemWindows(state); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 252 | applyModalFlag(state); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 253 | applyBrightness(state); |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 254 | applyHasTopUi(state); |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 255 | applySleepToken(state); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 256 | if (mLp.copyFrom(mLpChanged) != 0) { |
| 257 | mWindowManager.updateViewLayout(mStatusBarView, mLp); |
| 258 | } |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 259 | if (mHasTopUi != mHasTopUiChanged) { |
| 260 | try { |
| 261 | mActivityManager.setHasTopUi(mHasTopUiChanged); |
| 262 | } catch (RemoteException e) { |
| 263 | Log.e(TAG, "Failed to call setHasTopUi", e); |
| 264 | } |
| 265 | mHasTopUi = mHasTopUiChanged; |
| 266 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 269 | private void applyForceStatusBarVisibleFlag(State state) { |
| 270 | if (state.forceStatusBarVisible) { |
| 271 | mLpChanged.privateFlags |= WindowManager |
| 272 | .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT; |
| 273 | } else { |
| 274 | mLpChanged.privateFlags &= ~WindowManager |
| 275 | .LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT; |
| 276 | } |
| 277 | } |
| 278 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 279 | private void applyModalFlag(State state) { |
| 280 | if (state.headsUpShowing) { |
| 281 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 282 | } else { |
| 283 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 284 | } |
| 285 | } |
| 286 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 287 | private void applyBrightness(State state) { |
| 288 | if (state.forceDozeBrightness) { |
| 289 | mLpChanged.screenBrightness = mScreenBrightnessDoze; |
| 290 | } else { |
| 291 | mLpChanged.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; |
| 292 | } |
| 293 | } |
| 294 | |
Jorim Jaggi | f6782ee | 2016-07-22 11:40:00 +0200 | [diff] [blame] | 295 | private void applyHasTopUi(State state) { |
| 296 | mHasTopUiChanged = isExpanded(state); |
| 297 | } |
| 298 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 299 | private void applySleepToken(State state) { |
| 300 | if (state.dozing) { |
| 301 | mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN; |
| 302 | } else { |
| 303 | mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN; |
| 304 | } |
| 305 | } |
| 306 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 307 | public void setKeyguardShowing(boolean showing) { |
| 308 | mCurrentState.keyguardShowing = showing; |
| 309 | apply(mCurrentState); |
| 310 | } |
| 311 | |
| 312 | public void setKeyguardOccluded(boolean occluded) { |
| 313 | mCurrentState.keyguardOccluded = occluded; |
| 314 | apply(mCurrentState); |
| 315 | } |
| 316 | |
| 317 | public void setKeyguardNeedsInput(boolean needsInput) { |
| 318 | mCurrentState.keyguardNeedsInput = needsInput; |
| 319 | apply(mCurrentState); |
| 320 | } |
| 321 | |
Selim Cinek | 4a21a7f | 2015-05-19 11:00:38 -0700 | [diff] [blame] | 322 | public void setPanelVisible(boolean visible) { |
| 323 | mCurrentState.panelVisible = visible; |
| 324 | mCurrentState.statusBarFocusable = visible; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 325 | apply(mCurrentState); |
| 326 | } |
| 327 | |
| 328 | public void setStatusBarFocusable(boolean focusable) { |
| 329 | mCurrentState.statusBarFocusable = focusable; |
| 330 | apply(mCurrentState); |
| 331 | } |
| 332 | |
Jorim Jaggi | 5fd4d05 | 2014-05-13 22:50:20 +0200 | [diff] [blame] | 333 | public void setBouncerShowing(boolean showing) { |
| 334 | mCurrentState.bouncerShowing = showing; |
| 335 | apply(mCurrentState); |
| 336 | } |
| 337 | |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 338 | public void setBackdropShowing(boolean showing) { |
| 339 | mCurrentState.backdropShowing = showing; |
| 340 | apply(mCurrentState); |
| 341 | } |
| 342 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 343 | public void setKeyguardFadingAway(boolean keyguardFadingAway) { |
| 344 | mCurrentState.keyguardFadingAway = keyguardFadingAway; |
| 345 | apply(mCurrentState); |
| 346 | } |
| 347 | |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 348 | public void setQsExpanded(boolean expanded) { |
| 349 | mCurrentState.qsExpanded = expanded; |
| 350 | apply(mCurrentState); |
| 351 | } |
| 352 | |
Vadim Tryshev | 6069c40 | 2016-03-09 14:24:29 -0800 | [diff] [blame] | 353 | public void setForceUserActivity(boolean forceUserActivity) { |
| 354 | mCurrentState.forceUserActivity = forceUserActivity; |
| 355 | apply(mCurrentState); |
| 356 | } |
| 357 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 358 | public void setScrimsVisibility(int scrimsVisibility) { |
| 359 | mCurrentState.scrimsVisibility = scrimsVisibility; |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 360 | apply(mCurrentState); |
| 361 | } |
| 362 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 363 | public void setHeadsUpShowing(boolean showing) { |
| 364 | mCurrentState.headsUpShowing = showing; |
| 365 | apply(mCurrentState); |
| 366 | } |
| 367 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 368 | public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) { |
| 369 | mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode; |
| 370 | apply(mCurrentState); |
| 371 | } |
| 372 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 373 | /** |
| 374 | * @param state The {@link StatusBarState} of the status bar. |
| 375 | */ |
| 376 | public void setStatusBarState(int state) { |
| 377 | mCurrentState.statusBarState = state; |
| 378 | apply(mCurrentState); |
| 379 | } |
| 380 | |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 381 | public void setForceStatusBarVisible(boolean forceStatusBarVisible) { |
| 382 | mCurrentState.forceStatusBarVisible = forceStatusBarVisible; |
| 383 | apply(mCurrentState); |
| 384 | } |
| 385 | |
Selim Cinek | 737bff3 | 2015-05-08 16:08:35 -0700 | [diff] [blame] | 386 | /** |
| 387 | * Force the window to be collapsed, even if it should theoretically be expanded. |
| 388 | * Used for when a heads-up comes in but we still need to wait for the touchable regions to |
| 389 | * be computed. |
| 390 | */ |
| 391 | public void setForceWindowCollapsed(boolean force) { |
| 392 | mCurrentState.forceCollapsed = force; |
| 393 | apply(mCurrentState); |
| 394 | } |
| 395 | |
Selim Cinek | 4a21a7f | 2015-05-19 11:00:38 -0700 | [diff] [blame] | 396 | public void setPanelExpanded(boolean isExpanded) { |
| 397 | mCurrentState.panelExpanded = isExpanded; |
| 398 | apply(mCurrentState); |
| 399 | } |
| 400 | |
Adrian Roos | d28ccd7 | 2016-01-06 15:23:14 +0100 | [diff] [blame] | 401 | @Override |
| 402 | public void onRemoteInputActive(boolean remoteInputActive) { |
Adrian Roos | 1c0ca50 | 2015-10-07 12:20:42 -0700 | [diff] [blame] | 403 | mCurrentState.remoteInputActive = remoteInputActive; |
| 404 | apply(mCurrentState); |
| 405 | } |
| 406 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 407 | /** |
| 408 | * Set whether the screen brightness is forced to the value we use for doze mode by the status |
| 409 | * bar window. |
| 410 | */ |
| 411 | public void setForceDozeBrightness(boolean forceDozeBrightness) { |
| 412 | mCurrentState.forceDozeBrightness = forceDozeBrightness; |
| 413 | apply(mCurrentState); |
| 414 | } |
| 415 | |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 416 | public void setDozing(boolean dozing) { |
| 417 | mCurrentState.dozing = dozing; |
| 418 | apply(mCurrentState); |
| 419 | } |
| 420 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 421 | public void setBarHeight(int barHeight) { |
| 422 | mBarHeight = barHeight; |
| 423 | apply(mCurrentState); |
| 424 | } |
| 425 | |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 426 | public void setForcePluginOpen(boolean forcePluginOpen) { |
| 427 | mCurrentState.forcePluginOpen = forcePluginOpen; |
| 428 | apply(mCurrentState); |
| 429 | } |
| 430 | |
| 431 | public void setStateListener(OtherwisedCollapsedListener listener) { |
| 432 | mListener = listener; |
| 433 | } |
| 434 | |
Selim Cinek | 7025f26 | 2015-07-13 16:22:48 -0700 | [diff] [blame] | 435 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 436 | pw.println("StatusBarWindowManager state:"); |
| 437 | pw.println(mCurrentState); |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 440 | public boolean isShowingWallpaper() { |
| 441 | return !mCurrentState.backdropShowing; |
| 442 | } |
| 443 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 444 | private static class State { |
| 445 | boolean keyguardShowing; |
| 446 | boolean keyguardOccluded; |
| 447 | boolean keyguardNeedsInput; |
Selim Cinek | 4a21a7f | 2015-05-19 11:00:38 -0700 | [diff] [blame] | 448 | boolean panelVisible; |
| 449 | boolean panelExpanded; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 450 | boolean statusBarFocusable; |
Jorim Jaggi | 5fd4d05 | 2014-05-13 22:50:20 +0200 | [diff] [blame] | 451 | boolean bouncerShowing; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 452 | boolean keyguardFadingAway; |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 453 | boolean qsExpanded; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 454 | boolean headsUpShowing; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 455 | boolean forceStatusBarVisible; |
Selim Cinek | 737bff3 | 2015-05-08 16:08:35 -0700 | [diff] [blame] | 456 | boolean forceCollapsed; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 457 | boolean forceDozeBrightness; |
Vadim Tryshev | 6069c40 | 2016-03-09 14:24:29 -0800 | [diff] [blame] | 458 | boolean forceUserActivity; |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 459 | boolean backdropShowing; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 460 | boolean wallpaperSupportsAmbientMode; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 461 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 462 | /** |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 463 | * The {@link StatusBar} state from the status bar. |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 464 | */ |
| 465 | int statusBarState; |
| 466 | |
Adrian Roos | 1c0ca50 | 2015-10-07 12:20:42 -0700 | [diff] [blame] | 467 | boolean remoteInputActive; |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 468 | boolean forcePluginOpen; |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 469 | boolean dozing; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 470 | int scrimsVisibility; |
Adrian Roos | 1c0ca50 | 2015-10-07 12:20:42 -0700 | [diff] [blame] | 471 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 472 | private boolean isKeyguardShowingAndNotOccluded() { |
| 473 | return keyguardShowing && !keyguardOccluded; |
| 474 | } |
Selim Cinek | 6a1bd2b | 2015-06-02 16:02:41 +0200 | [diff] [blame] | 475 | |
| 476 | @Override |
| 477 | public String toString() { |
| 478 | StringBuilder result = new StringBuilder(); |
| 479 | String newLine = "\n"; |
| 480 | result.append("Window State {"); |
| 481 | result.append(newLine); |
| 482 | |
| 483 | Field[] fields = this.getClass().getDeclaredFields(); |
| 484 | |
| 485 | // Print field names paired with their values |
| 486 | for (Field field : fields) { |
| 487 | result.append(" "); |
| 488 | try { |
| 489 | result.append(field.getName()); |
| 490 | result.append(": "); |
| 491 | //requires access to private field: |
| 492 | result.append(field.get(this)); |
| 493 | } catch (IllegalAccessException ex) { |
| 494 | } |
| 495 | result.append(newLine); |
| 496 | } |
| 497 | result.append("}"); |
| 498 | |
| 499 | return result.toString(); |
| 500 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 501 | } |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * Custom listener to pipe data back to plugins about whether or not the status bar would be |
| 505 | * collapsed if not for the plugin. |
| 506 | * TODO: Find cleaner way to do this. |
| 507 | */ |
| 508 | public interface OtherwisedCollapsedListener { |
| 509 | void setWouldOtherwiseCollapse(boolean otherwiseCollapse); |
| 510 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 511 | } |