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; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 23 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 24 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 25 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; |
| 26 | import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE; |
| 27 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
| 28 | import static android.view.WindowManager.TRANSIT_UNSET; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 29 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS; |
| 30 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; |
| 31 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 32 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 33 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 34 | import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 35 | import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 36 | import static com.android.server.am.KeyguardControllerProto.KEYGUARD_OCCLUDED_STATES; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 37 | import static com.android.server.am.KeyguardControllerProto.KEYGUARD_SHOWING; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 38 | import static com.android.server.am.KeyguardOccludedProto.DISPLAY_ID; |
| 39 | import static com.android.server.am.KeyguardOccludedProto.KEYGUARD_OCCLUDED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 40 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 41 | import android.os.IBinder; |
| 42 | import android.os.RemoteException; |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 43 | import android.os.Trace; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 44 | import android.util.Slog; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 45 | import android.util.SparseArray; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 46 | import android.util.proto.ProtoOutputStream; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 47 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 48 | import com.android.internal.policy.IKeyguardDismissCallback; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 49 | import com.android.server.policy.WindowManagerPolicy; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 50 | import com.android.server.wm.ActivityTaskManagerInternal.SleepToken; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 51 | import com.android.server.wm.DisplayWindowController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 52 | import com.android.server.wm.WindowManagerService; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 53 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 54 | import java.io.PrintWriter; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Controls Keyguard occluding, dismissing and transitions depending on what kind of activities are |
| 58 | * currently visible. |
| 59 | * <p> |
| 60 | * Note that everything in this class should only be accessed with the AM lock being held. |
| 61 | */ |
| 62 | class KeyguardController { |
| 63 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 64 | private static final String TAG = TAG_WITH_CLASS_NAME ? "KeyguardController" : TAG_ATM; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 65 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 66 | private final ActivityStackSupervisor mStackSupervisor; |
| 67 | private WindowManagerService mWindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 68 | private boolean mKeyguardShowing; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 69 | private boolean mAodShowing; |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 70 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 71 | private boolean mDismissalRequested; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 72 | private int mBeforeUnoccludeTransit; |
| 73 | private int mVisibilityTransactionDepth; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 74 | // TODO(b/111955725): Support multiple external displays |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 75 | private int mSecondaryDisplayShowing = INVALID_DISPLAY; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 76 | private final SparseArray<KeyguardDisplayState> mDisplayStates = new SparseArray<>(); |
| 77 | private final ActivityTaskManagerService mService; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 78 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 79 | KeyguardController(ActivityTaskManagerService service, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 80 | ActivityStackSupervisor stackSupervisor) { |
| 81 | mService = service; |
| 82 | mStackSupervisor = stackSupervisor; |
| 83 | } |
| 84 | |
| 85 | void setWindowManager(WindowManagerService windowManager) { |
| 86 | mWindowManager = windowManager; |
| 87 | } |
| 88 | |
| 89 | /** |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 90 | * @return true if either Keyguard or AOD are showing, not going away, and not being occluded |
| 91 | * on the given display, false otherwise |
| 92 | */ |
| 93 | boolean isKeyguardOrAodShowing(int displayId) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 94 | return (mKeyguardShowing || mAodShowing) && !mKeyguardGoingAway |
| 95 | && !isDisplayOccluded(displayId); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 99 | * @return true if Keyguard is showing, not going away, and not being occluded on the given |
| 100 | * display, false otherwise |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 101 | */ |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 102 | boolean isKeyguardShowing(int displayId) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 103 | return mKeyguardShowing && !mKeyguardGoingAway && !isDisplayOccluded(displayId); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return true if Keyguard is either showing or occluded, but not going away |
| 108 | */ |
| 109 | boolean isKeyguardLocked() { |
| 110 | return mKeyguardShowing && !mKeyguardGoingAway; |
| 111 | } |
| 112 | |
| 113 | /** |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 114 | * @return {@code true} if the keyguard is going away, {@code false} otherwise. |
| 115 | */ |
| 116 | boolean isKeyguardGoingAway() { |
| 117 | // Also check keyguard showing in case value is stale. |
| 118 | return mKeyguardGoingAway && mKeyguardShowing; |
| 119 | } |
| 120 | |
| 121 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 122 | * Update the Keyguard showing state. |
| 123 | */ |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 124 | void setKeyguardShown(boolean keyguardShowing, boolean aodShowing, |
| 125 | int secondaryDisplayShowing) { |
| 126 | boolean showingChanged = keyguardShowing != mKeyguardShowing || aodShowing != mAodShowing; |
Adrian Roos | 6ec76b7 | 2018-04-25 14:01:11 +0200 | [diff] [blame] | 127 | // If keyguard is going away, but SystemUI aborted the transition, need to reset state. |
| 128 | showingChanged |= mKeyguardGoingAway && keyguardShowing; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 129 | if (!showingChanged && secondaryDisplayShowing == mSecondaryDisplayShowing) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 130 | return; |
| 131 | } |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 132 | mKeyguardShowing = keyguardShowing; |
| 133 | mAodShowing = aodShowing; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 134 | mSecondaryDisplayShowing = secondaryDisplayShowing; |
chaviw | 0e9fb13 | 2018-06-05 16:29:13 -0700 | [diff] [blame] | 135 | mWindowManager.setAodShowing(aodShowing); |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 136 | if (showingChanged) { |
| 137 | dismissDockedStackIfNeeded(); |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 138 | setKeyguardGoingAway(false); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 139 | // TODO(b/113840485): Check usage for non-default display |
Adrian Roos | b56b3c3 | 2018-05-17 17:32:26 +0200 | [diff] [blame] | 140 | mWindowManager.setKeyguardOrAodShowingOnDefaultDisplay( |
| 141 | isKeyguardOrAodShowing(DEFAULT_DISPLAY)); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 142 | if (keyguardShowing) { |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 143 | mDismissalRequested = false; |
| 144 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 145 | } |
| 146 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 147 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Called when Keyguard is going away. |
| 152 | * |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 153 | * @param flags See {@link WindowManagerPolicy#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE} |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 154 | * etc. |
| 155 | */ |
| 156 | void keyguardGoingAway(int flags) { |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 157 | if (!mKeyguardShowing) { |
| 158 | return; |
| 159 | } |
| 160 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway"); |
| 161 | mWindowManager.deferSurfaceLayout(); |
| 162 | try { |
| 163 | setKeyguardGoingAway(true); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 164 | mStackSupervisor.getDefaultDisplay().getWindowContainerController() |
| 165 | .prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, |
| 166 | false /* alwaysKeepCurrent */, convertTransitFlags(flags), |
| 167 | false /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 168 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 169 | |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 170 | // Some stack visibility might change (e.g. docked stack) |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 171 | mStackSupervisor.resumeFocusedStacksTopActivitiesLocked(); |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 172 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 173 | mStackSupervisor.addStartingWindowsForVisibleActivities(true /* taskSwitch */); |
| 174 | mWindowManager.executeAppTransition(); |
| 175 | } finally { |
| 176 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway: surfaceLayout"); |
| 177 | mWindowManager.continueSurfaceLayout(); |
| 178 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 179 | |
| 180 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 184 | void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, CharSequence message) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 185 | final ActivityRecord activityRecord = ActivityRecord.forTokenLocked(token); |
| 186 | if (activityRecord == null || !activityRecord.visibleIgnoringKeyguard) { |
| 187 | failCallback(callback); |
| 188 | return; |
| 189 | } |
Jorim Jaggi | d721489 | 2017-07-18 14:05:19 +0200 | [diff] [blame] | 190 | Slog.i(TAG, "Activity requesting to dismiss Keyguard: " + activityRecord); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 191 | |
| 192 | // If the client has requested to dismiss the keyguard and the Activity has the flag to |
| 193 | // turn the screen on, wakeup the screen if it's the top Activity. |
| 194 | if (activityRecord.getTurnScreenOnFlag() && activityRecord.isTopRunningActivity()) { |
| 195 | mStackSupervisor.wakeUp("dismissKeyguard"); |
| 196 | } |
| 197 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 198 | mWindowManager.dismissKeyguard(callback, message); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 201 | private void setKeyguardGoingAway(boolean keyguardGoingAway) { |
| 202 | mKeyguardGoingAway = keyguardGoingAway; |
| 203 | mWindowManager.setKeyguardGoingAway(keyguardGoingAway); |
| 204 | } |
| 205 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 206 | private void failCallback(IKeyguardDismissCallback callback) { |
| 207 | try { |
| 208 | callback.onDismissError(); |
| 209 | } catch (RemoteException e) { |
| 210 | Slog.w(TAG, "Failed to call callback", e); |
| 211 | } |
| 212 | } |
| 213 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 214 | private int convertTransitFlags(int keyguardGoingAwayFlags) { |
| 215 | int result = 0; |
| 216 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0) { |
| 217 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 218 | } |
| 219 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0) { |
| 220 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 221 | } |
| 222 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0) { |
| 223 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 224 | } |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Starts a batch of visibility updates. |
| 230 | */ |
| 231 | void beginActivityVisibilityUpdate() { |
| 232 | mVisibilityTransactionDepth++; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Ends a batch of visibility updates. After all batches are done, this method makes sure to |
| 237 | * update lockscreen occluded/dismiss state if needed. |
| 238 | */ |
| 239 | void endActivityVisibilityUpdate() { |
| 240 | mVisibilityTransactionDepth--; |
| 241 | if (mVisibilityTransactionDepth == 0) { |
| 242 | visibilitiesUpdated(); |
| 243 | } |
| 244 | } |
| 245 | |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 246 | /** |
| 247 | * @return True if we may show an activity while Keyguard is showing because we are in the |
| 248 | * process of dismissing it anyways, false otherwise. |
| 249 | */ |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 250 | boolean canShowActivityWhileKeyguardShowing(ActivityRecord r, boolean dismissKeyguard) { |
| 251 | |
| 252 | // Allow to show it when we are about to dismiss Keyguard. This isn't allowed if r is |
| 253 | // already the dismissing activity, in which case we don't allow it to repeatedly dismiss |
| 254 | // Keyguard. |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 255 | return dismissKeyguard && canDismissKeyguard() && !mAodShowing |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 256 | && (mDismissalRequested |
| 257 | || getDisplay(r.getDisplayId()).mDismissingKeyguardActivity != r); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
| 261 | * @return True if we may show an activity while Keyguard is occluded, false otherwise. |
| 262 | */ |
| 263 | boolean canShowWhileOccluded(boolean dismissKeyguard, boolean showWhenLocked) { |
| 264 | return showWhenLocked || dismissKeyguard && !mWindowManager.isKeyguardSecure(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 267 | private void visibilitiesUpdated() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 268 | boolean requestDismissKeyguard = false; |
Pat Plunkett | 40426e0 | 2017-10-31 14:06:29 -0700 | [diff] [blame] | 269 | for (int displayNdx = mStackSupervisor.getChildCount() - 1; displayNdx >= 0; displayNdx--) { |
| 270 | final ActivityDisplay display = mStackSupervisor.getChildAt(displayNdx); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 271 | final KeyguardDisplayState state = getDisplay(display.mDisplayId); |
| 272 | state.visibilitiesUpdated(this, display); |
| 273 | requestDismissKeyguard |= state.mRequestDismissKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 274 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 275 | |
| 276 | // Dismissing Keyguard happens globally using the information from all displays. |
| 277 | if (requestDismissKeyguard) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 278 | handleDismissKeyguard(); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Called when occluded state changed. |
| 284 | */ |
| 285 | private void handleOccludedChanged() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 286 | mWindowManager.onKeyguardOccludedChanged(isDisplayOccluded(DEFAULT_DISPLAY)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 287 | if (isKeyguardLocked()) { |
| 288 | mWindowManager.deferSurfaceLayout(); |
| 289 | try { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 290 | mStackSupervisor.getDefaultDisplay().getWindowContainerController() |
| 291 | .prepareAppTransition(resolveOccludeTransit(), |
| 292 | false /* alwaysKeepCurrent */, 0 /* flags */, |
| 293 | true /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 294 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 295 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 296 | mWindowManager.executeAppTransition(); |
| 297 | } finally { |
| 298 | mWindowManager.continueSurfaceLayout(); |
| 299 | } |
| 300 | } |
| 301 | dismissDockedStackIfNeeded(); |
| 302 | } |
| 303 | |
| 304 | /** |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 305 | * Called when somebody wants to dismiss the Keyguard via the flag. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 306 | */ |
| 307 | private void handleDismissKeyguard() { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 308 | // We only allow dismissing Keyguard via the flag when Keyguard is secure for legacy |
| 309 | // reasons, because that's how apps used to dismiss Keyguard in the secure case. In the |
| 310 | // insecure case, we actually show it on top of the lockscreen. See #canShowWhileOccluded. |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 311 | if (mWindowManager.isKeyguardSecure()) { |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 312 | mWindowManager.dismissKeyguard(null /* callback */, null /* message */); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 313 | mDismissalRequested = true; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 314 | |
| 315 | // If we are about to unocclude the Keyguard, but we can dismiss it without security, |
| 316 | // we immediately dismiss the Keyguard so the activity gets shown without a flicker. |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 317 | final DisplayWindowController dwc = |
| 318 | mStackSupervisor.getDefaultDisplay().getWindowContainerController(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 319 | if (mKeyguardShowing && canDismissKeyguard() |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 320 | && dwc.getPendingAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) { |
| 321 | dwc.prepareAppTransition(mBeforeUnoccludeTransit, false /* alwaysKeepCurrent */, |
| 322 | 0 /* flags */, true /* forceOverride */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 323 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 324 | mWindowManager.executeAppTransition(); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 329 | private boolean isDisplayOccluded(int displayId) { |
| 330 | return getDisplay(displayId).mOccluded; |
| 331 | } |
| 332 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 333 | /** |
| 334 | * @return true if Keyguard can be currently dismissed without entering credentials. |
| 335 | */ |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 336 | boolean canDismissKeyguard() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 337 | return mWindowManager.isKeyguardTrusted() || !mWindowManager.isKeyguardSecure(); |
| 338 | } |
| 339 | |
| 340 | private int resolveOccludeTransit() { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 341 | final DisplayWindowController dwc = |
| 342 | mStackSupervisor.getDefaultDisplay().getWindowContainerController(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 343 | if (mBeforeUnoccludeTransit != TRANSIT_UNSET |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 344 | && dwc.getPendingAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 345 | // TODO(b/113840485): Handle app transition for individual display. |
| 346 | && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 347 | |
| 348 | // Reuse old transit in case we are occluding Keyguard again, meaning that we never |
| 349 | // actually occclude/unocclude Keyguard, but just run a normal transition. |
| 350 | return mBeforeUnoccludeTransit; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 351 | // TODO(b/113840485): Handle app transition for individual display. |
| 352 | } else if (!isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 353 | |
| 354 | // Save transit in case we dismiss/occlude Keyguard shortly after. |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 355 | mBeforeUnoccludeTransit = dwc.getPendingAppTransition(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 356 | return TRANSIT_KEYGUARD_UNOCCLUDE; |
| 357 | } else { |
| 358 | return TRANSIT_KEYGUARD_OCCLUDE; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | private void dismissDockedStackIfNeeded() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 363 | // TODO(b/113840485): Handle docked stack for individual display. |
| 364 | if (mKeyguardShowing && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 365 | // The lock screen is currently showing, but is occluded by a window that can |
| 366 | // show on top of the lock screen. In this can we want to dismiss the docked |
| 367 | // stack since it will be complicated/risky to try to put the activity on top |
| 368 | // of the lock screen in the right fullscreen configuration. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 369 | final ActivityStack stack = mStackSupervisor.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 370 | if (stack == null) { |
| 371 | return; |
| 372 | } |
| 373 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 374 | stack.isFocusedStackOnDisplay()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 375 | } |
| 376 | } |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 377 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 378 | private void updateKeyguardSleepToken() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 379 | for (int displayNdx = mStackSupervisor.getChildCount() - 1; displayNdx >= 0; displayNdx--) { |
| 380 | final ActivityDisplay display = mStackSupervisor.getChildAt(displayNdx); |
| 381 | final KeyguardDisplayState state = getDisplay(display.mDisplayId); |
| 382 | if (isKeyguardOrAodShowing(display.mDisplayId) && state.mSleepToken == null) { |
| 383 | state.acquiredSleepToken(); |
| 384 | } else if (!isKeyguardOrAodShowing(display.mDisplayId) && state.mSleepToken != null) { |
| 385 | state.releaseSleepToken(); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | private KeyguardDisplayState getDisplay(int displayId) { |
| 391 | if (mDisplayStates.get(displayId) == null) { |
| 392 | mDisplayStates.append(displayId, |
| 393 | new KeyguardDisplayState(mService, displayId)); |
| 394 | } |
| 395 | return mDisplayStates.get(displayId); |
| 396 | } |
| 397 | |
| 398 | void onDisplayRemoved(int displayId) { |
| 399 | if (mDisplayStates.get(displayId) != null) { |
| 400 | mDisplayStates.get(displayId).onRemoved(); |
| 401 | mDisplayStates.remove(displayId); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /** Represents Keyguard state per individual display. */ |
| 406 | private static class KeyguardDisplayState { |
| 407 | private final int mDisplayId; |
| 408 | private boolean mOccluded; |
| 409 | private ActivityRecord mDismissingKeyguardActivity; |
| 410 | private boolean mRequestDismissKeyguard; |
| 411 | private final ActivityTaskManagerService mService; |
| 412 | private SleepToken mSleepToken; |
| 413 | |
| 414 | KeyguardDisplayState(ActivityTaskManagerService service, int displayId) { |
| 415 | mService = service; |
| 416 | mDisplayId = displayId; |
| 417 | } |
| 418 | |
| 419 | void onRemoved() { |
| 420 | mDismissingKeyguardActivity = null; |
| 421 | releaseSleepToken(); |
| 422 | } |
| 423 | |
| 424 | void acquiredSleepToken() { |
| 425 | if (mSleepToken == null) { |
| 426 | mSleepToken = mService.acquireSleepToken("keyguard", mDisplayId); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | void releaseSleepToken() { |
| 431 | if (mSleepToken != null) { |
| 432 | mSleepToken.release(); |
| 433 | mSleepToken = null; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | void visibilitiesUpdated(KeyguardController controller, ActivityDisplay display) { |
| 438 | final boolean lastOccluded = mOccluded; |
| 439 | final ActivityRecord lastDismissActivity = mDismissingKeyguardActivity; |
| 440 | mRequestDismissKeyguard = false; |
| 441 | mOccluded = false; |
| 442 | mDismissingKeyguardActivity = null; |
| 443 | |
| 444 | // Only the top activity of the focused stack on each display may control it's |
| 445 | // occluded state. |
| 446 | final ActivityStack focusedStack = display.getFocusedStack(); |
| 447 | if (focusedStack != null) { |
| 448 | final ActivityRecord topDismissing = |
| 449 | focusedStack.getTopDismissingKeyguardActivity(); |
| 450 | mOccluded = focusedStack.topActivityOccludesKeyguard() || (topDismissing != null |
| 451 | && focusedStack.topRunningActivityLocked() == topDismissing |
| 452 | && controller.canShowWhileOccluded( |
| 453 | true /* dismissKeyguard */, |
| 454 | false /* showWhenLocked */)); |
| 455 | if (focusedStack.getTopDismissingKeyguardActivity() != null) { |
| 456 | mDismissingKeyguardActivity = focusedStack.getTopDismissingKeyguardActivity(); |
| 457 | } |
| 458 | mOccluded |= controller.mWindowManager.isShowingDream(); |
| 459 | } |
| 460 | |
| 461 | // TODO(b/113840485): Handle app transition for individual display. |
| 462 | // For now, only default display can change occluded. |
| 463 | if (lastOccluded != mOccluded && mDisplayId == DEFAULT_DISPLAY) { |
| 464 | controller.handleOccludedChanged(); |
| 465 | } |
| 466 | if (lastDismissActivity != mDismissingKeyguardActivity && !mOccluded |
| 467 | && mDismissingKeyguardActivity != null |
| 468 | && controller.mWindowManager.isKeyguardSecure()) { |
| 469 | mRequestDismissKeyguard = true; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | void dumpStatus(PrintWriter pw, String prefix) { |
| 474 | final StringBuilder sb = new StringBuilder(); |
| 475 | sb.append(prefix); |
| 476 | sb.append(" Occluded=").append(mOccluded) |
| 477 | .append(" DismissingKeyguardActivity=") |
| 478 | .append(mDismissingKeyguardActivity) |
| 479 | .append(" at display=") |
| 480 | .append(mDisplayId); |
| 481 | pw.println(sb.toString()); |
| 482 | } |
| 483 | |
| 484 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 485 | final long token = proto.start(fieldId); |
| 486 | proto.write(DISPLAY_ID, mDisplayId); |
| 487 | proto.write(KEYGUARD_OCCLUDED, mOccluded); |
| 488 | proto.end(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 492 | void dump(PrintWriter pw, String prefix) { |
| 493 | pw.println(prefix + "KeyguardController:"); |
| 494 | pw.println(prefix + " mKeyguardShowing=" + mKeyguardShowing); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 495 | pw.println(prefix + " mAodShowing=" + mAodShowing); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 496 | pw.println(prefix + " mKeyguardGoingAway=" + mKeyguardGoingAway); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 497 | dumpDisplayStates(pw, prefix); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 498 | pw.println(prefix + " mDismissalRequested=" + mDismissalRequested); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 499 | pw.println(prefix + " mVisibilityTransactionDepth=" + mVisibilityTransactionDepth); |
| 500 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 501 | |
| 502 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 503 | final long token = proto.start(fieldId); |
| 504 | proto.write(KEYGUARD_SHOWING, mKeyguardShowing); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 505 | writeDisplayStatesToProto(proto, KEYGUARD_OCCLUDED_STATES); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 506 | proto.end(token); |
| 507 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 508 | |
| 509 | private void dumpDisplayStates(PrintWriter pw, String prefix) { |
| 510 | for (int i = 0; i < mDisplayStates.size(); i++) { |
| 511 | mDisplayStates.valueAt(i).dumpStatus(pw, prefix); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | private void writeDisplayStatesToProto(ProtoOutputStream proto, long fieldId) { |
| 516 | for (int i = 0; i < mDisplayStates.size(); i++) { |
| 517 | mDisplayStates.valueAt(i).writeToProto(proto, fieldId); |
| 518 | } |
| 519 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 520 | } |