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