Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.server.am; |
| 18 | |
| 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 20 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 21 | import static android.view.Display.DEFAULT_DISPLAY; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 22 | import static android.view.Display.INVALID_DISPLAY; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 23 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS; |
| 24 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; |
| 25 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 26 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 27 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 28 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 29 | import static com.android.server.am.proto.KeyguardControllerProto.KEYGUARD_OCCLUDED; |
| 30 | import static com.android.server.am.proto.KeyguardControllerProto.KEYGUARD_SHOWING; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 31 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 32 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 33 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 34 | import static com.android.server.wm.AppTransition.TRANSIT_KEYGUARD_GOING_AWAY; |
| 35 | import static com.android.server.wm.AppTransition.TRANSIT_KEYGUARD_OCCLUDE; |
| 36 | import static com.android.server.wm.AppTransition.TRANSIT_KEYGUARD_UNOCCLUDE; |
| 37 | import static com.android.server.wm.AppTransition.TRANSIT_UNSET; |
| 38 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 39 | import android.app.ActivityManagerInternal.SleepToken; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
| 41 | import android.os.RemoteException; |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 42 | import android.os.Trace; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 43 | import android.util.Slog; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 44 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 45 | |
| 46 | import com.android.internal.policy.IKeyguardDismissCallback; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 47 | import com.android.server.wm.WindowManagerService; |
| 48 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 49 | import java.io.PrintWriter; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 50 | import java.util.ArrayList; |
| 51 | |
| 52 | /** |
| 53 | * Controls Keyguard occluding, dismissing and transitions depending on what kind of activities are |
| 54 | * currently visible. |
| 55 | * <p> |
| 56 | * Note that everything in this class should only be accessed with the AM lock being held. |
| 57 | */ |
| 58 | class KeyguardController { |
| 59 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 60 | private static final String TAG = TAG_WITH_CLASS_NAME ? "KeyguardController" : TAG_AM; |
| 61 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 62 | private final ActivityManagerService mService; |
| 63 | private final ActivityStackSupervisor mStackSupervisor; |
| 64 | private WindowManagerService mWindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 65 | private boolean mKeyguardShowing; |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 66 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 67 | private boolean mOccluded; |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 68 | private boolean mDismissalRequested; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 69 | private ActivityRecord mDismissingKeyguardActivity; |
| 70 | private int mBeforeUnoccludeTransit; |
| 71 | private int mVisibilityTransactionDepth; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 72 | private SleepToken mSleepToken; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 73 | private int mSecondaryDisplayShowing = INVALID_DISPLAY; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 74 | |
| 75 | KeyguardController(ActivityManagerService service, |
| 76 | ActivityStackSupervisor stackSupervisor) { |
| 77 | mService = service; |
| 78 | mStackSupervisor = stackSupervisor; |
| 79 | } |
| 80 | |
| 81 | void setWindowManager(WindowManagerService windowManager) { |
| 82 | mWindowManager = windowManager; |
| 83 | } |
| 84 | |
| 85 | /** |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 86 | * @return true if Keyguard is showing, not going away, and not being occluded on the given |
| 87 | * display, false otherwise |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 88 | */ |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 89 | boolean isKeyguardShowing(int displayId) { |
| 90 | return mKeyguardShowing && !mKeyguardGoingAway && |
| 91 | (displayId == DEFAULT_DISPLAY ? !mOccluded : displayId == mSecondaryDisplayShowing); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return true if Keyguard is either showing or occluded, but not going away |
| 96 | */ |
| 97 | boolean isKeyguardLocked() { |
| 98 | return mKeyguardShowing && !mKeyguardGoingAway; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Update the Keyguard showing state. |
| 103 | */ |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 104 | void setKeyguardShown(boolean showing, int secondaryDisplayShowing) { |
| 105 | boolean showingChanged = showing != mKeyguardShowing; |
| 106 | if (!showingChanged && secondaryDisplayShowing == mSecondaryDisplayShowing) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | mKeyguardShowing = showing; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 110 | mSecondaryDisplayShowing = secondaryDisplayShowing; |
| 111 | if (showingChanged) { |
| 112 | dismissDockedStackIfNeeded(); |
| 113 | if (showing) { |
| 114 | setKeyguardGoingAway(false); |
| 115 | mDismissalRequested = false; |
| 116 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 117 | } |
| 118 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 119 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Called when Keyguard is going away. |
| 124 | * |
| 125 | * @param flags See {@link android.view.WindowManagerPolicy#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE} |
| 126 | * etc. |
| 127 | */ |
| 128 | void keyguardGoingAway(int flags) { |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 129 | if (!mKeyguardShowing) { |
| 130 | return; |
| 131 | } |
| 132 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway"); |
| 133 | mWindowManager.deferSurfaceLayout(); |
| 134 | try { |
| 135 | setKeyguardGoingAway(true); |
| 136 | mWindowManager.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, |
| 137 | false /* alwaysKeepCurrent */, convertTransitFlags(flags), |
| 138 | false /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 139 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 140 | |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 141 | // Some stack visibility might change (e.g. docked stack) |
| 142 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 143 | mStackSupervisor.addStartingWindowsForVisibleActivities(true /* taskSwitch */); |
| 144 | mWindowManager.executeAppTransition(); |
| 145 | } finally { |
| 146 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway: surfaceLayout"); |
| 147 | mWindowManager.continueSurfaceLayout(); |
| 148 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 149 | |
| 150 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 154 | void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback) { |
| 155 | final ActivityRecord activityRecord = ActivityRecord.forTokenLocked(token); |
| 156 | if (activityRecord == null || !activityRecord.visibleIgnoringKeyguard) { |
| 157 | failCallback(callback); |
| 158 | return; |
| 159 | } |
Jorim Jaggi | d721489 | 2017-07-18 14:05:19 +0200 | [diff] [blame] | 160 | Slog.i(TAG, "Activity requesting to dismiss Keyguard: " + activityRecord); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 161 | |
| 162 | // If the client has requested to dismiss the keyguard and the Activity has the flag to |
| 163 | // turn the screen on, wakeup the screen if it's the top Activity. |
| 164 | if (activityRecord.getTurnScreenOnFlag() && activityRecord.isTopRunningActivity()) { |
| 165 | mStackSupervisor.wakeUp("dismissKeyguard"); |
| 166 | } |
| 167 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 168 | mWindowManager.dismissKeyguard(callback); |
| 169 | } |
| 170 | |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 171 | private void setKeyguardGoingAway(boolean keyguardGoingAway) { |
| 172 | mKeyguardGoingAway = keyguardGoingAway; |
| 173 | mWindowManager.setKeyguardGoingAway(keyguardGoingAway); |
| 174 | } |
| 175 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 176 | private void failCallback(IKeyguardDismissCallback callback) { |
| 177 | try { |
| 178 | callback.onDismissError(); |
| 179 | } catch (RemoteException e) { |
| 180 | Slog.w(TAG, "Failed to call callback", e); |
| 181 | } |
| 182 | } |
| 183 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 184 | private int convertTransitFlags(int keyguardGoingAwayFlags) { |
| 185 | int result = 0; |
| 186 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0) { |
| 187 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 188 | } |
| 189 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0) { |
| 190 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 191 | } |
| 192 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0) { |
| 193 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 194 | } |
| 195 | return result; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Starts a batch of visibility updates. |
| 200 | */ |
| 201 | void beginActivityVisibilityUpdate() { |
| 202 | mVisibilityTransactionDepth++; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Ends a batch of visibility updates. After all batches are done, this method makes sure to |
| 207 | * update lockscreen occluded/dismiss state if needed. |
| 208 | */ |
| 209 | void endActivityVisibilityUpdate() { |
| 210 | mVisibilityTransactionDepth--; |
| 211 | if (mVisibilityTransactionDepth == 0) { |
| 212 | visibilitiesUpdated(); |
| 213 | } |
| 214 | } |
| 215 | |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 216 | /** |
| 217 | * @return True if we may show an activity while Keyguard is showing because we are in the |
| 218 | * process of dismissing it anyways, false otherwise. |
| 219 | */ |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 220 | boolean canShowActivityWhileKeyguardShowing(ActivityRecord r, boolean dismissKeyguard) { |
| 221 | |
| 222 | // Allow to show it when we are about to dismiss Keyguard. This isn't allowed if r is |
| 223 | // already the dismissing activity, in which case we don't allow it to repeatedly dismiss |
| 224 | // Keyguard. |
| 225 | return dismissKeyguard && canDismissKeyguard() && |
| 226 | (mDismissalRequested || r != mDismissingKeyguardActivity); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * @return True if we may show an activity while Keyguard is occluded, false otherwise. |
| 231 | */ |
| 232 | boolean canShowWhileOccluded(boolean dismissKeyguard, boolean showWhenLocked) { |
| 233 | return showWhenLocked || dismissKeyguard && !mWindowManager.isKeyguardSecure(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 236 | private void visibilitiesUpdated() { |
| 237 | final boolean lastOccluded = mOccluded; |
| 238 | final ActivityRecord lastDismissingKeyguardActivity = mDismissingKeyguardActivity; |
| 239 | mOccluded = false; |
| 240 | mDismissingKeyguardActivity = null; |
| 241 | final ArrayList<ActivityStack> stacks = mStackSupervisor.getStacksOnDefaultDisplay(); |
Wale Ogunwale | e287e19 | 2017-04-21 09:30:12 -0700 | [diff] [blame] | 242 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 243 | final ActivityStack stack = stacks.get(stackNdx); |
| 244 | |
Wale Ogunwale | e287e19 | 2017-04-21 09:30:12 -0700 | [diff] [blame] | 245 | // Only the focused stack top activity may control occluded state |
| 246 | if (mStackSupervisor.isFocusedStack(stack)) { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 247 | |
| 248 | // A dismissing activity occludes Keyguard in the insecure case for legacy reasons. |
| 249 | final ActivityRecord topDismissing = stack.getTopDismissingKeyguardActivity(); |
| 250 | mOccluded = stack.topActivityOccludesKeyguard() |
| 251 | || (topDismissing != null |
| 252 | && stack.topRunningActivityLocked() == topDismissing |
| 253 | && canShowWhileOccluded(true /* dismissKeyguard */, |
| 254 | false /* showWhenLocked */)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 255 | } |
| 256 | if (mDismissingKeyguardActivity == null |
| 257 | && stack.getTopDismissingKeyguardActivity() != null) { |
| 258 | mDismissingKeyguardActivity = stack.getTopDismissingKeyguardActivity(); |
| 259 | } |
| 260 | } |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 261 | mOccluded |= mWindowManager.isShowingDream(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 262 | if (mOccluded != lastOccluded) { |
| 263 | handleOccludedChanged(); |
| 264 | } |
| 265 | if (mDismissingKeyguardActivity != lastDismissingKeyguardActivity) { |
| 266 | handleDismissKeyguard(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Called when occluded state changed. |
| 272 | */ |
| 273 | private void handleOccludedChanged() { |
| 274 | mWindowManager.onKeyguardOccludedChanged(mOccluded); |
| 275 | if (isKeyguardLocked()) { |
| 276 | mWindowManager.deferSurfaceLayout(); |
| 277 | try { |
| 278 | mWindowManager.prepareAppTransition(resolveOccludeTransit(), |
| 279 | false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 280 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 281 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 282 | mWindowManager.executeAppTransition(); |
| 283 | } finally { |
| 284 | mWindowManager.continueSurfaceLayout(); |
| 285 | } |
| 286 | } |
| 287 | dismissDockedStackIfNeeded(); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Called when somebody might want to dismiss the Keyguard. |
| 292 | */ |
| 293 | private void handleDismissKeyguard() { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 294 | // We only allow dismissing Keyguard via the flag when Keyguard is secure for legacy |
| 295 | // reasons, because that's how apps used to dismiss Keyguard in the secure case. In the |
| 296 | // insecure case, we actually show it on top of the lockscreen. See #canShowWhileOccluded. |
| 297 | if (!mOccluded && mDismissingKeyguardActivity != null |
| 298 | && mWindowManager.isKeyguardSecure()) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 299 | mWindowManager.dismissKeyguard(null /* callback */); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 300 | mDismissalRequested = true; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 301 | |
| 302 | // If we are about to unocclude the Keyguard, but we can dismiss it without security, |
| 303 | // we immediately dismiss the Keyguard so the activity gets shown without a flicker. |
| 304 | if (mKeyguardShowing && canDismissKeyguard() |
| 305 | && mWindowManager.getPendingAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) { |
| 306 | mWindowManager.prepareAppTransition(mBeforeUnoccludeTransit, |
| 307 | false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 308 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 309 | mWindowManager.executeAppTransition(); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * @return true if Keyguard can be currently dismissed without entering credentials. |
| 316 | */ |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 317 | boolean canDismissKeyguard() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 318 | return mWindowManager.isKeyguardTrusted() || !mWindowManager.isKeyguardSecure(); |
| 319 | } |
| 320 | |
| 321 | private int resolveOccludeTransit() { |
| 322 | if (mBeforeUnoccludeTransit != TRANSIT_UNSET |
| 323 | && mWindowManager.getPendingAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
| 324 | && mOccluded) { |
| 325 | |
| 326 | // Reuse old transit in case we are occluding Keyguard again, meaning that we never |
| 327 | // actually occclude/unocclude Keyguard, but just run a normal transition. |
| 328 | return mBeforeUnoccludeTransit; |
| 329 | } else if (!mOccluded) { |
| 330 | |
| 331 | // Save transit in case we dismiss/occlude Keyguard shortly after. |
| 332 | mBeforeUnoccludeTransit = mWindowManager.getPendingAppTransition(); |
| 333 | return TRANSIT_KEYGUARD_UNOCCLUDE; |
| 334 | } else { |
| 335 | return TRANSIT_KEYGUARD_OCCLUDE; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | private void dismissDockedStackIfNeeded() { |
| 340 | if (mKeyguardShowing && mOccluded) { |
| 341 | // The lock screen is currently showing, but is occluded by a window that can |
| 342 | // show on top of the lock screen. In this can we want to dismiss the docked |
| 343 | // stack since it will be complicated/risky to try to put the activity on top |
| 344 | // of the lock screen in the right fullscreen configuration. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame^] | 345 | final ActivityStack stack = mStackSupervisor.getStack(DOCKED_STACK_ID); |
| 346 | if (stack == null) { |
| 347 | return; |
| 348 | } |
| 349 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, |
| 350 | mStackSupervisor.mFocusedStack == stack); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 351 | } |
| 352 | } |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 353 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 354 | private void updateKeyguardSleepToken() { |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 355 | if (mSleepToken == null && isKeyguardShowing(DEFAULT_DISPLAY)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 356 | mSleepToken = mService.acquireSleepToken("Keyguard", DEFAULT_DISPLAY); |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 357 | } else if (mSleepToken != null && !isKeyguardShowing(DEFAULT_DISPLAY)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 358 | mSleepToken.release(); |
| 359 | mSleepToken = null; |
| 360 | } |
| 361 | } |
| 362 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 363 | void dump(PrintWriter pw, String prefix) { |
| 364 | pw.println(prefix + "KeyguardController:"); |
| 365 | pw.println(prefix + " mKeyguardShowing=" + mKeyguardShowing); |
| 366 | pw.println(prefix + " mKeyguardGoingAway=" + mKeyguardGoingAway); |
| 367 | pw.println(prefix + " mOccluded=" + mOccluded); |
| 368 | pw.println(prefix + " mDismissingKeyguardActivity=" + mDismissingKeyguardActivity); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 369 | pw.println(prefix + " mDismissalRequested=" + mDismissalRequested); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 370 | pw.println(prefix + " mVisibilityTransactionDepth=" + mVisibilityTransactionDepth); |
| 371 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 372 | |
| 373 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 374 | final long token = proto.start(fieldId); |
| 375 | proto.write(KEYGUARD_SHOWING, mKeyguardShowing); |
| 376 | proto.write(KEYGUARD_OCCLUDED, mOccluded); |
| 377 | proto.end(token); |
| 378 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 379 | } |