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