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; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 52 | import java.util.Arrays; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Controls Keyguard occluding, dismissing and transitions depending on what kind of activities are |
| 56 | * currently visible. |
| 57 | * <p> |
| 58 | * Note that everything in this class should only be accessed with the AM lock being held. |
| 59 | */ |
| 60 | class KeyguardController { |
| 61 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 62 | private static final String TAG = TAG_WITH_CLASS_NAME ? "KeyguardController" : TAG_ATM; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 63 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 64 | private final ActivityStackSupervisor mStackSupervisor; |
| 65 | private WindowManagerService mWindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 66 | private boolean mKeyguardShowing; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 67 | private boolean mAodShowing; |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 68 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 69 | private boolean mDismissalRequested; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 70 | private int[] mSecondaryDisplayIdsShowing; |
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 | private final SparseArray<KeyguardDisplayState> mDisplayStates = new SparseArray<>(); |
| 74 | private final ActivityTaskManagerService mService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 75 | private RootActivityContainer mRootActivityContainer; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 76 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 77 | KeyguardController(ActivityTaskManagerService service, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 78 | ActivityStackSupervisor stackSupervisor) { |
| 79 | mService = service; |
| 80 | mStackSupervisor = stackSupervisor; |
| 81 | } |
| 82 | |
| 83 | void setWindowManager(WindowManagerService windowManager) { |
| 84 | mWindowManager = windowManager; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 85 | mRootActivityContainer = mService.mRootActivityContainer; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 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 |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame^] | 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 | 498a4b8 | 2018-12-11 16:10:16 +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, |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 124 | int[] secondaryDisplaysShowing) { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 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; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 128 | if (!showingChanged && Arrays.equals(secondaryDisplaysShowing, |
| 129 | mSecondaryDisplayIdsShowing)) { |
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; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 134 | mSecondaryDisplayIdsShowing = secondaryDisplaysShowing; |
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 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 146 | mRootActivityContainer.ensureActivitiesVisible(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); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 164 | mRootActivityContainer.getDefaultDisplay().mDisplayContent |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 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) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 171 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
| 172 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
| 173 | mRootActivityContainer.addStartingWindowsForVisibleActivities( |
| 174 | true /* taskSwitch */); |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 175 | mWindowManager.executeAppTransition(); |
| 176 | } finally { |
| 177 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway: surfaceLayout"); |
| 178 | mWindowManager.continueSurfaceLayout(); |
| 179 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 180 | |
| 181 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 185 | void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, CharSequence message) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 186 | final ActivityRecord activityRecord = ActivityRecord.forTokenLocked(token); |
| 187 | if (activityRecord == null || !activityRecord.visibleIgnoringKeyguard) { |
| 188 | failCallback(callback); |
| 189 | return; |
| 190 | } |
Jorim Jaggi | d721489 | 2017-07-18 14:05:19 +0200 | [diff] [blame] | 191 | Slog.i(TAG, "Activity requesting to dismiss Keyguard: " + activityRecord); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 192 | |
| 193 | // If the client has requested to dismiss the keyguard and the Activity has the flag to |
| 194 | // turn the screen on, wakeup the screen if it's the top Activity. |
| 195 | if (activityRecord.getTurnScreenOnFlag() && activityRecord.isTopRunningActivity()) { |
| 196 | mStackSupervisor.wakeUp("dismissKeyguard"); |
| 197 | } |
| 198 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 199 | mWindowManager.dismissKeyguard(callback, message); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 202 | private void setKeyguardGoingAway(boolean keyguardGoingAway) { |
| 203 | mKeyguardGoingAway = keyguardGoingAway; |
| 204 | mWindowManager.setKeyguardGoingAway(keyguardGoingAway); |
| 205 | } |
| 206 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 207 | private void failCallback(IKeyguardDismissCallback callback) { |
| 208 | try { |
| 209 | callback.onDismissError(); |
| 210 | } catch (RemoteException e) { |
| 211 | Slog.w(TAG, "Failed to call callback", e); |
| 212 | } |
| 213 | } |
| 214 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 215 | private int convertTransitFlags(int keyguardGoingAwayFlags) { |
| 216 | int result = 0; |
| 217 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0) { |
| 218 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 219 | } |
| 220 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0) { |
| 221 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 222 | } |
| 223 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0) { |
| 224 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 225 | } |
| 226 | return result; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Starts a batch of visibility updates. |
| 231 | */ |
| 232 | void beginActivityVisibilityUpdate() { |
| 233 | mVisibilityTransactionDepth++; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Ends a batch of visibility updates. After all batches are done, this method makes sure to |
| 238 | * update lockscreen occluded/dismiss state if needed. |
| 239 | */ |
| 240 | void endActivityVisibilityUpdate() { |
| 241 | mVisibilityTransactionDepth--; |
| 242 | if (mVisibilityTransactionDepth == 0) { |
| 243 | visibilitiesUpdated(); |
| 244 | } |
| 245 | } |
| 246 | |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 247 | /** |
| 248 | * @return True if we may show an activity while Keyguard is showing because we are in the |
| 249 | * process of dismissing it anyways, false otherwise. |
| 250 | */ |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 251 | boolean canShowActivityWhileKeyguardShowing(ActivityRecord r, boolean dismissKeyguard) { |
| 252 | |
| 253 | // Allow to show it when we are about to dismiss Keyguard. This isn't allowed if r is |
| 254 | // already the dismissing activity, in which case we don't allow it to repeatedly dismiss |
| 255 | // Keyguard. |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 256 | return dismissKeyguard && canDismissKeyguard() && !mAodShowing |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 257 | && (mDismissalRequested |
| 258 | || getDisplay(r.getDisplayId()).mDismissingKeyguardActivity != r); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * @return True if we may show an activity while Keyguard is occluded, false otherwise. |
| 263 | */ |
| 264 | boolean canShowWhileOccluded(boolean dismissKeyguard, boolean showWhenLocked) { |
| 265 | return showWhenLocked || dismissKeyguard && !mWindowManager.isKeyguardSecure(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 268 | private void visibilitiesUpdated() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 269 | boolean requestDismissKeyguard = false; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 270 | for (int displayNdx = mRootActivityContainer.getChildCount() - 1; |
| 271 | displayNdx >= 0; displayNdx--) { |
| 272 | final ActivityDisplay display = mRootActivityContainer.getChildAt(displayNdx); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 273 | final KeyguardDisplayState state = getDisplay(display.mDisplayId); |
| 274 | state.visibilitiesUpdated(this, display); |
| 275 | requestDismissKeyguard |= state.mRequestDismissKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 276 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 277 | |
| 278 | // Dismissing Keyguard happens globally using the information from all displays. |
| 279 | if (requestDismissKeyguard) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 280 | handleDismissKeyguard(); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Called when occluded state changed. |
| 286 | */ |
| 287 | private void handleOccludedChanged() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 288 | mWindowManager.onKeyguardOccludedChanged(isDisplayOccluded(DEFAULT_DISPLAY)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 289 | if (isKeyguardLocked()) { |
| 290 | mWindowManager.deferSurfaceLayout(); |
| 291 | try { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 292 | mRootActivityContainer.getDefaultDisplay().mDisplayContent |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 293 | .prepareAppTransition(resolveOccludeTransit(), |
| 294 | false /* alwaysKeepCurrent */, 0 /* flags */, |
| 295 | true /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 296 | updateKeyguardSleepToken(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 297 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 298 | mWindowManager.executeAppTransition(); |
| 299 | } finally { |
| 300 | mWindowManager.continueSurfaceLayout(); |
| 301 | } |
| 302 | } |
| 303 | dismissDockedStackIfNeeded(); |
| 304 | } |
| 305 | |
| 306 | /** |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 307 | * Called when somebody wants to dismiss the Keyguard via the flag. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 308 | */ |
| 309 | private void handleDismissKeyguard() { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 310 | // We only allow dismissing Keyguard via the flag when Keyguard is secure for legacy |
| 311 | // reasons, because that's how apps used to dismiss Keyguard in the secure case. In the |
| 312 | // 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] | 313 | if (!mWindowManager.isKeyguardSecure()) { |
| 314 | return; |
| 315 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 316 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 317 | mWindowManager.dismissKeyguard(null /* callback */, null /* message */); |
| 318 | mDismissalRequested = true; |
| 319 | |
| 320 | // If we are about to unocclude the Keyguard, but we can dismiss it without security, |
| 321 | // 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] | 322 | final DisplayContent dc = |
| 323 | mRootActivityContainer.getDefaultDisplay().mDisplayContent; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 324 | if (mKeyguardShowing && canDismissKeyguard() |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 325 | && dc.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) { |
| 326 | dc.prepareAppTransition(mBeforeUnoccludeTransit, false /* alwaysKeepCurrent */, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 327 | 0 /* flags */, true /* forceOverride */); |
| 328 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
| 329 | mWindowManager.executeAppTransition(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 333 | private boolean isDisplayOccluded(int displayId) { |
| 334 | return getDisplay(displayId).mOccluded; |
| 335 | } |
| 336 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 337 | /** |
| 338 | * @return true if Keyguard can be currently dismissed without entering credentials. |
| 339 | */ |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 340 | boolean canDismissKeyguard() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 341 | return mWindowManager.isKeyguardTrusted() || !mWindowManager.isKeyguardSecure(); |
| 342 | } |
| 343 | |
| 344 | private int resolveOccludeTransit() { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 345 | final DisplayContent dc = |
| 346 | mService.mRootActivityContainer.getDefaultDisplay().mDisplayContent; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 347 | if (mBeforeUnoccludeTransit != TRANSIT_UNSET |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 348 | && dc.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 349 | // TODO(b/113840485): Handle app transition for individual display. |
| 350 | && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 351 | |
| 352 | // Reuse old transit in case we are occluding Keyguard again, meaning that we never |
| 353 | // actually occclude/unocclude Keyguard, but just run a normal transition. |
| 354 | return mBeforeUnoccludeTransit; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 355 | // TODO(b/113840485): Handle app transition for individual display. |
| 356 | } else if (!isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 357 | |
| 358 | // Save transit in case we dismiss/occlude Keyguard shortly after. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 359 | mBeforeUnoccludeTransit = dc.mAppTransition.getAppTransition(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 360 | return TRANSIT_KEYGUARD_UNOCCLUDE; |
| 361 | } else { |
| 362 | return TRANSIT_KEYGUARD_OCCLUDE; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | private void dismissDockedStackIfNeeded() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 367 | // TODO(b/113840485): Handle docked stack for individual display. |
| 368 | if (mKeyguardShowing && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 369 | // The lock screen is currently showing, but is occluded by a window that can |
| 370 | // show on top of the lock screen. In this can we want to dismiss the docked |
| 371 | // stack since it will be complicated/risky to try to put the activity on top |
| 372 | // of the lock screen in the right fullscreen configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 373 | final ActivityStack stack = |
| 374 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 375 | if (stack == null) { |
| 376 | return; |
| 377 | } |
| 378 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 379 | stack.isFocusedStackOnDisplay()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 380 | } |
| 381 | } |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 382 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 383 | private void updateKeyguardSleepToken() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 384 | for (int displayNdx = mRootActivityContainer.getChildCount() - 1; |
| 385 | displayNdx >= 0; displayNdx--) { |
| 386 | final ActivityDisplay display = mRootActivityContainer.getChildAt(displayNdx); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 387 | final KeyguardDisplayState state = getDisplay(display.mDisplayId); |
| 388 | if (isKeyguardOrAodShowing(display.mDisplayId) && state.mSleepToken == null) { |
| 389 | state.acquiredSleepToken(); |
| 390 | } else if (!isKeyguardOrAodShowing(display.mDisplayId) && state.mSleepToken != null) { |
| 391 | state.releaseSleepToken(); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | private KeyguardDisplayState getDisplay(int displayId) { |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 397 | KeyguardDisplayState state = mDisplayStates.get(displayId); |
| 398 | if (state == null) { |
| 399 | state = new KeyguardDisplayState(mService, displayId); |
| 400 | mDisplayStates.append(displayId, state); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 401 | } |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 402 | return state; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void onDisplayRemoved(int displayId) { |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 406 | final KeyguardDisplayState state = mDisplayStates.get(displayId); |
| 407 | if (state != null) { |
| 408 | state.onRemoved(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 409 | mDisplayStates.remove(displayId); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /** Represents Keyguard state per individual display. */ |
| 414 | private static class KeyguardDisplayState { |
| 415 | private final int mDisplayId; |
| 416 | private boolean mOccluded; |
| 417 | private ActivityRecord mDismissingKeyguardActivity; |
| 418 | private boolean mRequestDismissKeyguard; |
| 419 | private final ActivityTaskManagerService mService; |
| 420 | private SleepToken mSleepToken; |
| 421 | |
| 422 | KeyguardDisplayState(ActivityTaskManagerService service, int displayId) { |
| 423 | mService = service; |
| 424 | mDisplayId = displayId; |
| 425 | } |
| 426 | |
| 427 | void onRemoved() { |
| 428 | mDismissingKeyguardActivity = null; |
| 429 | releaseSleepToken(); |
| 430 | } |
| 431 | |
| 432 | void acquiredSleepToken() { |
| 433 | if (mSleepToken == null) { |
| 434 | mSleepToken = mService.acquireSleepToken("keyguard", mDisplayId); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | void releaseSleepToken() { |
| 439 | if (mSleepToken != null) { |
| 440 | mSleepToken.release(); |
| 441 | mSleepToken = null; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | void visibilitiesUpdated(KeyguardController controller, ActivityDisplay display) { |
| 446 | final boolean lastOccluded = mOccluded; |
| 447 | final ActivityRecord lastDismissActivity = mDismissingKeyguardActivity; |
| 448 | mRequestDismissKeyguard = false; |
| 449 | mOccluded = false; |
| 450 | mDismissingKeyguardActivity = null; |
| 451 | |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 452 | final ActivityStack stack = getStackForControllingOccluding(display); |
| 453 | if (stack != null) { |
| 454 | final ActivityRecord topDismissing = stack.getTopDismissingKeyguardActivity(); |
| 455 | mOccluded = stack.topActivityOccludesKeyguard() || (topDismissing != null |
| 456 | && stack.topRunningActivityLocked() == topDismissing |
| 457 | && controller.canShowWhileOccluded( |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 458 | true /* dismissKeyguard */, |
| 459 | false /* showWhenLocked */)); |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 460 | if (stack.getTopDismissingKeyguardActivity() != null) { |
| 461 | mDismissingKeyguardActivity = stack.getTopDismissingKeyguardActivity(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 462 | } |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame^] | 463 | // FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD only apply for secondary display. |
| 464 | if (mDisplayId != DEFAULT_DISPLAY) { |
| 465 | mOccluded |= stack.canShowWithInsecureKeyguard() |
| 466 | && controller.canDismissKeyguard(); |
| 467 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 468 | } |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame^] | 469 | // TODO(b/123372519): isShowingDream can only works on default display. |
| 470 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 471 | mOccluded |= controller.mWindowManager.isShowingDream(); |
| 472 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 473 | |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 474 | // TODO(b/113840485): Handle app transition for individual display, and apply occluded |
| 475 | // state change to secondary displays. |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 476 | // For now, only default display can change occluded. |
| 477 | if (lastOccluded != mOccluded && mDisplayId == DEFAULT_DISPLAY) { |
| 478 | controller.handleOccludedChanged(); |
| 479 | } |
| 480 | if (lastDismissActivity != mDismissingKeyguardActivity && !mOccluded |
| 481 | && mDismissingKeyguardActivity != null |
| 482 | && controller.mWindowManager.isKeyguardSecure()) { |
| 483 | mRequestDismissKeyguard = true; |
| 484 | } |
| 485 | } |
| 486 | |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 487 | /** |
| 488 | * Gets the stack used to check the occluded state. |
| 489 | * <p> |
| 490 | * Only the top non-pinned activity of the focusable stack on each display can control its |
| 491 | * occlusion state. |
| 492 | */ |
| 493 | private ActivityStack getStackForControllingOccluding(ActivityDisplay display) { |
| 494 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 495 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 496 | if (stack != null && stack.isFocusableAndVisible() |
| 497 | && !stack.inPinnedWindowingMode()) { |
| 498 | return stack; |
| 499 | } |
| 500 | } |
| 501 | return null; |
| 502 | } |
| 503 | |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 504 | void dumpStatus(PrintWriter pw, String prefix) { |
| 505 | final StringBuilder sb = new StringBuilder(); |
| 506 | sb.append(prefix); |
| 507 | sb.append(" Occluded=").append(mOccluded) |
| 508 | .append(" DismissingKeyguardActivity=") |
| 509 | .append(mDismissingKeyguardActivity) |
| 510 | .append(" at display=") |
| 511 | .append(mDisplayId); |
| 512 | pw.println(sb.toString()); |
| 513 | } |
| 514 | |
| 515 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 516 | final long token = proto.start(fieldId); |
| 517 | proto.write(DISPLAY_ID, mDisplayId); |
| 518 | proto.write(KEYGUARD_OCCLUDED, mOccluded); |
| 519 | proto.end(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 523 | void dump(PrintWriter pw, String prefix) { |
| 524 | pw.println(prefix + "KeyguardController:"); |
| 525 | pw.println(prefix + " mKeyguardShowing=" + mKeyguardShowing); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 526 | pw.println(prefix + " mAodShowing=" + mAodShowing); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 527 | pw.println(prefix + " mKeyguardGoingAway=" + mKeyguardGoingAway); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 528 | dumpDisplayStates(pw, prefix); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 529 | pw.println(prefix + " mDismissalRequested=" + mDismissalRequested); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 530 | pw.println(prefix + " mVisibilityTransactionDepth=" + mVisibilityTransactionDepth); |
| 531 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 532 | |
| 533 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 534 | final long token = proto.start(fieldId); |
| 535 | proto.write(KEYGUARD_SHOWING, mKeyguardShowing); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 536 | writeDisplayStatesToProto(proto, KEYGUARD_OCCLUDED_STATES); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 537 | proto.end(token); |
| 538 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 539 | |
| 540 | private void dumpDisplayStates(PrintWriter pw, String prefix) { |
| 541 | for (int i = 0; i < mDisplayStates.size(); i++) { |
| 542 | mDisplayStates.valueAt(i).dumpStatus(pw, prefix); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | private void writeDisplayStatesToProto(ProtoOutputStream proto, long fieldId) { |
| 547 | for (int i = 0; i < mDisplayStates.size(); i++) { |
| 548 | mDisplayStates.valueAt(i).writeToProto(proto, fieldId); |
| 549 | } |
| 550 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 551 | } |