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