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 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.pm.ActivityInfo; |
| 21 | import android.content.res.Resources; |
| 22 | import android.graphics.PixelFormat; |
| 23 | import android.os.SystemProperties; |
| 24 | import android.view.Gravity; |
| 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
| 27 | import android.view.WindowManager; |
| 28 | |
| 29 | import com.android.keyguard.R; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 30 | import com.android.systemui.statusbar.BaseStatusBar; |
| 31 | import com.android.systemui.statusbar.StatusBarState; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Encapsulates all logic for the status bar window state management. |
| 35 | */ |
| 36 | public class StatusBarWindowManager { |
| 37 | |
| 38 | private final Context mContext; |
| 39 | private final WindowManager mWindowManager; |
| 40 | private View mStatusBarView; |
| 41 | private WindowManager.LayoutParams mLp; |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 42 | private WindowManager.LayoutParams mLpChanged; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 43 | private int mBarHeight; |
| 44 | private final boolean mKeyguardScreenRotation; |
| 45 | |
| 46 | private final State mCurrentState = new State(); |
| 47 | |
| 48 | public StatusBarWindowManager(Context context) { |
| 49 | mContext = context; |
| 50 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 51 | mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation(); |
| 52 | } |
| 53 | |
| 54 | private boolean shouldEnableKeyguardScreenRotation() { |
| 55 | Resources res = mContext.getResources(); |
| 56 | return SystemProperties.getBoolean("lockscreen.rot_override", false) |
| 57 | || res.getBoolean(R.bool.config_enableLockScreenRotation); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Adds the status bar view to the window manager. |
| 62 | * |
| 63 | * @param statusBarView The view to add. |
| 64 | * @param barHeight The height of the status bar in collapsed state. |
| 65 | */ |
| 66 | public void add(View statusBarView, int barHeight) { |
| 67 | |
| 68 | // Now that the status bar window encompasses the sliding panel and its |
| 69 | // translucent backdrop, the entire thing is made TRANSLUCENT and is |
| 70 | // hardware-accelerated. |
| 71 | mLp = new WindowManager.LayoutParams( |
| 72 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 73 | barHeight, |
| 74 | WindowManager.LayoutParams.TYPE_STATUS_BAR, |
| 75 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 76 | | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 77 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 78 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 79 | | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 80 | PixelFormat.TRANSLUCENT); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 81 | mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
Jorim Jaggi | 76aaef5 | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 82 | mLp.gravity = Gravity.TOP; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 83 | mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 84 | mLp.setTitle("StatusBar"); |
| 85 | mLp.packageName = mContext.getPackageName(); |
| 86 | mStatusBarView = statusBarView; |
| 87 | mBarHeight = barHeight; |
| 88 | mWindowManager.addView(mStatusBarView, mLp); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 89 | mLpChanged = new WindowManager.LayoutParams(); |
| 90 | mLpChanged.copyFrom(mLp); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | private void applyKeyguardFlags(State state) { |
| 94 | if (state.keyguardShowing) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 95 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 96 | mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 97 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 98 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 99 | mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | private void adjustScreenOrientation(State state) { |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 104 | if (state.isKeyguardShowingAndNotOccluded()) { |
| 105 | if (mKeyguardScreenRotation) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 106 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER; |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 107 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 108 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
Jorim Jaggi | ca36cf7 | 2014-04-17 20:36:15 +0200 | [diff] [blame] | 109 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 110 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 111 | mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | private void applyFocusableFlag(State state) { |
Jorim Jaggi | 5fd4d05 | 2014-05-13 22:50:20 +0200 | [diff] [blame] | 116 | if (state.isKeyguardShowingAndNotOccluded() && state.keyguardNeedsInput |
| 117 | && state.bouncerShowing) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 118 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 119 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 120 | } else if (state.isKeyguardShowingAndNotOccluded() || state.statusBarFocusable) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 121 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 122 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 123 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 124 | mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 125 | mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | private void applyHeight(State state) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 130 | boolean expanded = state.isKeyguardShowingAndNotOccluded() || state.statusBarExpanded |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 131 | || state.keyguardFadingAway || state.bouncerShowing; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 132 | if (expanded) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 133 | mLpChanged.height = ViewGroup.LayoutParams.MATCH_PARENT; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 134 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 135 | mLpChanged.height = mBarHeight; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 139 | private void applyFitsSystemWindows(State state) { |
| 140 | mStatusBarView.setFitsSystemWindows(!state.isKeyguardShowingAndNotOccluded()); |
| 141 | } |
| 142 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 143 | private void applyUserActivityTimeout(State state) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 144 | if (state.isKeyguardShowingAndNotOccluded() |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 145 | && state.statusBarState == StatusBarState.KEYGUARD |
| 146 | && !state.qsExpanded) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 147 | mLpChanged.userActivityTimeout = state.keyguardUserActivityTimeout; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 148 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 149 | mLpChanged.userActivityTimeout = -1; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 153 | private void applyInputFeatures(State state) { |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 154 | if (state.isKeyguardShowingAndNotOccluded() |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 155 | && state.statusBarState == StatusBarState.KEYGUARD |
| 156 | && !state.qsExpanded) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 157 | mLpChanged.inputFeatures |= |
| 158 | WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 159 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 160 | mLpChanged.inputFeatures &= |
| 161 | ~WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 165 | private void apply(State state) { |
| 166 | applyKeyguardFlags(state); |
| 167 | applyFocusableFlag(state); |
| 168 | adjustScreenOrientation(state); |
| 169 | applyHeight(state); |
| 170 | applyUserActivityTimeout(state); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 171 | applyInputFeatures(state); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 172 | applyFitsSystemWindows(state); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame^] | 173 | if (mLp.copyFrom(mLpChanged) != 0) { |
| 174 | mWindowManager.updateViewLayout(mStatusBarView, mLp); |
| 175 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | public void setKeyguardShowing(boolean showing) { |
| 179 | mCurrentState.keyguardShowing = showing; |
| 180 | apply(mCurrentState); |
| 181 | } |
| 182 | |
| 183 | public void setKeyguardOccluded(boolean occluded) { |
| 184 | mCurrentState.keyguardOccluded = occluded; |
| 185 | apply(mCurrentState); |
| 186 | } |
| 187 | |
| 188 | public void setKeyguardNeedsInput(boolean needsInput) { |
| 189 | mCurrentState.keyguardNeedsInput = needsInput; |
| 190 | apply(mCurrentState); |
| 191 | } |
| 192 | |
| 193 | public void setStatusBarExpanded(boolean expanded) { |
| 194 | mCurrentState.statusBarExpanded = expanded; |
| 195 | mCurrentState.statusBarFocusable = expanded; |
| 196 | apply(mCurrentState); |
| 197 | } |
| 198 | |
| 199 | public void setStatusBarFocusable(boolean focusable) { |
| 200 | mCurrentState.statusBarFocusable = focusable; |
| 201 | apply(mCurrentState); |
| 202 | } |
| 203 | |
| 204 | public void setKeyguardUserActivityTimeout(long timeout) { |
| 205 | mCurrentState.keyguardUserActivityTimeout = timeout; |
| 206 | apply(mCurrentState); |
| 207 | } |
| 208 | |
Jorim Jaggi | 5fd4d05 | 2014-05-13 22:50:20 +0200 | [diff] [blame] | 209 | public void setBouncerShowing(boolean showing) { |
| 210 | mCurrentState.bouncerShowing = showing; |
| 211 | apply(mCurrentState); |
| 212 | } |
| 213 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 214 | public void setKeyguardFadingAway(boolean keyguardFadingAway) { |
| 215 | mCurrentState.keyguardFadingAway = keyguardFadingAway; |
| 216 | apply(mCurrentState); |
| 217 | } |
| 218 | |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 219 | public void setQsExpanded(boolean expanded) { |
| 220 | mCurrentState.qsExpanded = expanded; |
| 221 | apply(mCurrentState); |
| 222 | } |
| 223 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 224 | /** |
| 225 | * @param state The {@link StatusBarState} of the status bar. |
| 226 | */ |
| 227 | public void setStatusBarState(int state) { |
| 228 | mCurrentState.statusBarState = state; |
| 229 | apply(mCurrentState); |
| 230 | } |
| 231 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 232 | private static class State { |
| 233 | boolean keyguardShowing; |
| 234 | boolean keyguardOccluded; |
| 235 | boolean keyguardNeedsInput; |
| 236 | boolean statusBarExpanded; |
| 237 | boolean statusBarFocusable; |
| 238 | long keyguardUserActivityTimeout; |
Jorim Jaggi | 5fd4d05 | 2014-05-13 22:50:20 +0200 | [diff] [blame] | 239 | boolean bouncerShowing; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 240 | boolean keyguardFadingAway; |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 241 | boolean qsExpanded; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 242 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 243 | /** |
| 244 | * The {@link BaseStatusBar} state from the status bar. |
| 245 | */ |
| 246 | int statusBarState; |
| 247 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 248 | private boolean isKeyguardShowingAndNotOccluded() { |
| 249 | return keyguardShowing && !keyguardOccluded; |
| 250 | } |
| 251 | } |
| 252 | } |