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