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 | |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 19 | import static android.os.Trace.TRACE_TAG_WINDOW_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; |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 22 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 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; |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 30 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 31 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; |
| 32 | import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 33 | |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 34 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 35 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 36 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 37 | import static com.android.server.wm.KeyguardControllerProto.AOD_SHOWING; |
| 38 | import static com.android.server.wm.KeyguardControllerProto.KEYGUARD_OCCLUDED_STATES; |
| 39 | import static com.android.server.wm.KeyguardControllerProto.KEYGUARD_SHOWING; |
| 40 | import static com.android.server.wm.KeyguardOccludedProto.DISPLAY_ID; |
| 41 | import static com.android.server.wm.KeyguardOccludedProto.KEYGUARD_OCCLUDED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 42 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
| 44 | import android.os.RemoteException; |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 45 | import android.os.Trace; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 46 | import android.util.Slog; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 47 | import android.util.SparseArray; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 48 | import android.util.proto.ProtoOutputStream; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 49 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 50 | import com.android.internal.policy.IKeyguardDismissCallback; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 51 | import com.android.server.policy.WindowManagerPolicy; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 52 | import com.android.server.wm.ActivityTaskManagerInternal.SleepToken; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 53 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 54 | import java.io.PrintWriter; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Controls Keyguard occluding, dismissing and transitions depending on what kind of activities are |
| 58 | * currently visible. |
| 59 | * <p> |
| 60 | * Note that everything in this class should only be accessed with the AM lock being held. |
| 61 | */ |
| 62 | class KeyguardController { |
| 63 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 64 | private static final String TAG = TAG_WITH_CLASS_NAME ? "KeyguardController" : TAG_ATM; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 65 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 66 | private final ActivityStackSupervisor mStackSupervisor; |
| 67 | private WindowManagerService mWindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 68 | private boolean mKeyguardShowing; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 69 | private boolean mAodShowing; |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 70 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 71 | private boolean mDismissalRequested; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 72 | private int mBeforeUnoccludeTransit; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 73 | private final SparseArray<KeyguardDisplayState> mDisplayStates = new SparseArray<>(); |
| 74 | private final ActivityTaskManagerService mService; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 75 | private RootWindowContainer mRootWindowContainer; |
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; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 85 | mRootWindowContainer = mService.mRootWindowContainer; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [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. |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 91 | */ |
| 92 | boolean isKeyguardOrAodShowing(int displayId) { |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 93 | return (mKeyguardShowing || mAodShowing) && !mKeyguardGoingAway |
| 94 | && !isDisplayOccluded(displayId); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @return {@code true} for default display when AOD is showing. Otherwise, same as |
| 99 | * {@link #isKeyguardOrAodShowing(int)} |
| 100 | * TODO(b/125198167): Replace isKeyguardOrAodShowing() by this logic. |
| 101 | */ |
| 102 | boolean isKeyguardUnoccludedOrAodShowing(int displayId) { |
| 103 | if (displayId == DEFAULT_DISPLAY && mAodShowing) { |
| 104 | return true; |
| 105 | } |
| 106 | return isKeyguardOrAodShowing(displayId); |
Issei Suzuki | d6eb5a2 | 2019-02-20 23:08:03 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 110 | * @return true if Keyguard is showing, not going away, and not being occluded on the given |
| 111 | * display, false otherwise |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 112 | */ |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 113 | boolean isKeyguardShowing(int displayId) { |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 114 | return mKeyguardShowing && !mKeyguardGoingAway && !isDisplayOccluded(displayId); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @return true if Keyguard is either showing or occluded, but not going away |
| 119 | */ |
| 120 | boolean isKeyguardLocked() { |
| 121 | return mKeyguardShowing && !mKeyguardGoingAway; |
| 122 | } |
| 123 | |
| 124 | /** |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 125 | * @return {@code true} if the keyguard is going away, {@code false} otherwise. |
| 126 | */ |
| 127 | boolean isKeyguardGoingAway() { |
| 128 | // Also check keyguard showing in case value is stale. |
| 129 | return mKeyguardGoingAway && mKeyguardShowing; |
| 130 | } |
| 131 | |
| 132 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 133 | * Update the Keyguard showing state. |
| 134 | */ |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 135 | void setKeyguardShown(boolean keyguardShowing, boolean aodShowing) { |
Adrian Roos | 6ec76b7 | 2018-04-25 14:01:11 +0200 | [diff] [blame] | 136 | // If keyguard is going away, but SystemUI aborted the transition, need to reset state. |
wilsonshih | 2bc846c | 2019-05-02 14:35:21 +0800 | [diff] [blame] | 137 | final boolean keyguardChanged = keyguardShowing != mKeyguardShowing |
| 138 | || mKeyguardGoingAway && keyguardShowing; |
| 139 | final boolean aodChanged = aodShowing != mAodShowing; |
| 140 | if (!keyguardChanged && !aodChanged) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 141 | return; |
| 142 | } |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 143 | EventLogTags.writeWmSetKeyguardShown( |
wilsonshih | 30eca70 | 2019-07-10 09:22:11 +0800 | [diff] [blame] | 144 | keyguardShowing ? 1 : 0, |
| 145 | aodShowing ? 1 : 0, |
| 146 | mKeyguardGoingAway ? 1 : 0, |
| 147 | "setKeyguardShown"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 148 | mKeyguardShowing = keyguardShowing; |
| 149 | mAodShowing = aodShowing; |
chaviw | 0e9fb13 | 2018-06-05 16:29:13 -0700 | [diff] [blame] | 150 | mWindowManager.setAodShowing(aodShowing); |
wilsonshih | 2bc846c | 2019-05-02 14:35:21 +0800 | [diff] [blame] | 151 | |
| 152 | if (keyguardChanged) { |
| 153 | // Irrelevant to AOD. |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 154 | dismissDockedStackIfNeeded(); |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 155 | setKeyguardGoingAway(false); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 156 | if (keyguardShowing) { |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 157 | mDismissalRequested = false; |
| 158 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 159 | } |
wilsonshih | 2bc846c | 2019-05-02 14:35:21 +0800 | [diff] [blame] | 160 | // TODO(b/113840485): Check usage for non-default display |
| 161 | mWindowManager.setKeyguardOrAodShowingOnDefaultDisplay( |
| 162 | isKeyguardOrAodShowing(DEFAULT_DISPLAY)); |
| 163 | |
| 164 | // Update the sleep token first such that ensureActivitiesVisible has correct sleep token |
| 165 | // state when evaluating visibilities. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 166 | updateKeyguardSleepToken(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 167 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Called when Keyguard is going away. |
| 172 | * |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 173 | * @param flags See {@link WindowManagerPolicy#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE} |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 174 | * etc. |
| 175 | */ |
| 176 | void keyguardGoingAway(int flags) { |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 177 | if (!mKeyguardShowing) { |
| 178 | return; |
| 179 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 180 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "keyguardGoingAway"); |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 181 | mService.deferWindowLayout(); |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 182 | try { |
| 183 | setKeyguardGoingAway(true); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 184 | EventLogTags.writeWmSetKeyguardShown( |
wilsonshih | 30eca70 | 2019-07-10 09:22:11 +0800 | [diff] [blame] | 185 | 1 /* keyguardShowing */, |
| 186 | mAodShowing ? 1 : 0, |
| 187 | 1 /* keyguardGoingAway */, |
| 188 | "keyguardGoingAway"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 189 | mRootWindowContainer.getDefaultDisplay().mDisplayContent |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 190 | .prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, |
| 191 | false /* alwaysKeepCurrent */, convertTransitFlags(flags), |
| 192 | false /* forceOverride */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 193 | updateKeyguardSleepToken(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 194 | |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 195 | // Some stack visibility might change (e.g. docked stack) |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 196 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
| 197 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
| 198 | mRootWindowContainer.addStartingWindowsForVisibleActivities(); |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 199 | mWindowManager.executeAppTransition(); |
| 200 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 201 | mService.continueWindowLayout(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 202 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 206 | void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, CharSequence message) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 207 | final ActivityRecord activityRecord = ActivityRecord.forTokenLocked(token); |
| 208 | if (activityRecord == null || !activityRecord.visibleIgnoringKeyguard) { |
| 209 | failCallback(callback); |
| 210 | return; |
| 211 | } |
Jorim Jaggi | d721489 | 2017-07-18 14:05:19 +0200 | [diff] [blame] | 212 | Slog.i(TAG, "Activity requesting to dismiss Keyguard: " + activityRecord); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 213 | |
| 214 | // If the client has requested to dismiss the keyguard and the Activity has the flag to |
| 215 | // turn the screen on, wakeup the screen if it's the top Activity. |
| 216 | if (activityRecord.getTurnScreenOnFlag() && activityRecord.isTopRunningActivity()) { |
| 217 | mStackSupervisor.wakeUp("dismissKeyguard"); |
| 218 | } |
| 219 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 220 | mWindowManager.dismissKeyguard(callback, message); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 223 | private void setKeyguardGoingAway(boolean keyguardGoingAway) { |
| 224 | mKeyguardGoingAway = keyguardGoingAway; |
| 225 | mWindowManager.setKeyguardGoingAway(keyguardGoingAway); |
| 226 | } |
| 227 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 228 | private void failCallback(IKeyguardDismissCallback callback) { |
| 229 | try { |
| 230 | callback.onDismissError(); |
| 231 | } catch (RemoteException e) { |
| 232 | Slog.w(TAG, "Failed to call callback", e); |
| 233 | } |
| 234 | } |
| 235 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 236 | private int convertTransitFlags(int keyguardGoingAwayFlags) { |
| 237 | int result = 0; |
| 238 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0) { |
| 239 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 240 | } |
| 241 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0) { |
| 242 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 243 | } |
| 244 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0) { |
| 245 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 246 | } |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 247 | if ((keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS) != 0) { |
| 248 | result |= TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION; |
| 249 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 250 | return result; |
| 251 | } |
| 252 | |
| 253 | /** |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 254 | * @return True if we may show an activity while Keyguard is showing because we are in the |
| 255 | * process of dismissing it anyways, false otherwise. |
| 256 | */ |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 257 | boolean canShowActivityWhileKeyguardShowing(ActivityRecord r, boolean dismissKeyguard) { |
| 258 | |
| 259 | // Allow to show it when we are about to dismiss Keyguard. This isn't allowed if r is |
| 260 | // already the dismissing activity, in which case we don't allow it to repeatedly dismiss |
| 261 | // Keyguard. |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 262 | return dismissKeyguard && canDismissKeyguard() && !mAodShowing |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 263 | && (mDismissalRequested |
Arthur Hung | cf58b33 | 2019-04-17 16:07:10 +0800 | [diff] [blame] | 264 | || (r.canShowWhenLocked() |
| 265 | && getDisplay(r.getDisplayId()).mDismissingKeyguardActivity != r)); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @return True if we may show an activity while Keyguard is occluded, false otherwise. |
| 270 | */ |
| 271 | boolean canShowWhileOccluded(boolean dismissKeyguard, boolean showWhenLocked) { |
Brad Stenning | 2bdc21e | 2019-03-11 14:33:22 -0700 | [diff] [blame] | 272 | return showWhenLocked || dismissKeyguard |
| 273 | && !mWindowManager.isKeyguardSecure(mService.getCurrentUserId()); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Riddle Hsu | f2ff25f | 2020-04-29 19:15:33 +0800 | [diff] [blame] | 276 | /** |
| 277 | * Makes sure to update lockscreen occluded/dismiss state if needed after completing all |
| 278 | * visibility updates ({@link ActivityStackSupervisor#endActivityVisibilityUpdate}). |
| 279 | */ |
| 280 | void visibilitiesUpdated() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 281 | boolean requestDismissKeyguard = false; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 282 | for (int displayNdx = mRootWindowContainer.getChildCount() - 1; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 283 | displayNdx >= 0; displayNdx--) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 284 | final DisplayContent display = mRootWindowContainer.getChildAt(displayNdx); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 285 | final KeyguardDisplayState state = getDisplay(display.mDisplayId); |
| 286 | state.visibilitiesUpdated(this, display); |
| 287 | requestDismissKeyguard |= state.mRequestDismissKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 288 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 289 | |
| 290 | // Dismissing Keyguard happens globally using the information from all displays. |
| 291 | if (requestDismissKeyguard) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 292 | handleDismissKeyguard(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Called when occluded state changed. |
| 298 | */ |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 299 | private void handleOccludedChanged(int displayId) { |
| 300 | // TODO(b/113840485): Handle app transition for individual display, and apply occluded |
| 301 | // state change to secondary displays. |
| 302 | // For now, only default display fully supports occluded change. Other displays only |
| 303 | // updates keygaurd sleep token on that display. |
| 304 | if (displayId != DEFAULT_DISPLAY) { |
| 305 | updateKeyguardSleepToken(displayId); |
| 306 | return; |
| 307 | } |
| 308 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 309 | mWindowManager.mPolicy.onKeyguardOccludedChangedLw(isDisplayOccluded(DEFAULT_DISPLAY)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 310 | if (isKeyguardLocked()) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 311 | mService.deferWindowLayout(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 312 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 313 | mRootWindowContainer.getDefaultDisplay().mDisplayContent |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 314 | .prepareAppTransition(resolveOccludeTransit(), |
| 315 | false /* alwaysKeepCurrent */, 0 /* flags */, |
| 316 | true /* forceOverride */); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 317 | updateKeyguardSleepToken(DEFAULT_DISPLAY); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 318 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 319 | mWindowManager.executeAppTransition(); |
| 320 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 321 | mService.continueWindowLayout(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | dismissDockedStackIfNeeded(); |
| 325 | } |
| 326 | |
| 327 | /** |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 328 | * Called when somebody wants to dismiss the Keyguard via the flag. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 329 | */ |
| 330 | private void handleDismissKeyguard() { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 331 | // We only allow dismissing Keyguard via the flag when Keyguard is secure for legacy |
| 332 | // reasons, because that's how apps used to dismiss Keyguard in the secure case. In the |
| 333 | // insecure case, we actually show it on top of the lockscreen. See #canShowWhileOccluded. |
Brad Stenning | 2bdc21e | 2019-03-11 14:33:22 -0700 | [diff] [blame] | 334 | if (!mWindowManager.isKeyguardSecure(mService.getCurrentUserId())) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 335 | return; |
| 336 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 337 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 338 | mWindowManager.dismissKeyguard(null /* callback */, null /* message */); |
| 339 | mDismissalRequested = true; |
| 340 | |
| 341 | // If we are about to unocclude the Keyguard, but we can dismiss it without security, |
| 342 | // 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] | 343 | final DisplayContent dc = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 344 | mRootWindowContainer.getDefaultDisplay().mDisplayContent; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 345 | if (mKeyguardShowing && canDismissKeyguard() |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 346 | && dc.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) { |
| 347 | dc.prepareAppTransition(mBeforeUnoccludeTransit, false /* alwaysKeepCurrent */, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 348 | 0 /* flags */, true /* forceOverride */); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 349 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 350 | mWindowManager.executeAppTransition(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 354 | private boolean isDisplayOccluded(int displayId) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 355 | return getDisplay(displayId).mOccluded; |
| 356 | } |
| 357 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 358 | /** |
| 359 | * @return true if Keyguard can be currently dismissed without entering credentials. |
| 360 | */ |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 361 | boolean canDismissKeyguard() { |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 362 | return mWindowManager.mPolicy.isKeyguardTrustedLw() |
Brad Stenning | 2bdc21e | 2019-03-11 14:33:22 -0700 | [diff] [blame] | 363 | || !mWindowManager.isKeyguardSecure(mService.getCurrentUserId()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | private int resolveOccludeTransit() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 367 | final DisplayContent dc = mRootWindowContainer.getDefaultDisplay().mDisplayContent; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 368 | if (mBeforeUnoccludeTransit != TRANSIT_UNSET |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 369 | && dc.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 370 | // TODO(b/113840485): Handle app transition for individual display. |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 371 | && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 372 | |
| 373 | // Reuse old transit in case we are occluding Keyguard again, meaning that we never |
| 374 | // actually occclude/unocclude Keyguard, but just run a normal transition. |
| 375 | return mBeforeUnoccludeTransit; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 376 | // TODO(b/113840485): Handle app transition for individual display. |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 377 | } else if (!isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 378 | |
| 379 | // Save transit in case we dismiss/occlude Keyguard shortly after. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 380 | mBeforeUnoccludeTransit = dc.mAppTransition.getAppTransition(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 381 | return TRANSIT_KEYGUARD_UNOCCLUDE; |
| 382 | } else { |
| 383 | return TRANSIT_KEYGUARD_OCCLUDE; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | private void dismissDockedStackIfNeeded() { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 388 | // TODO(b/113840485): Handle docked stack for individual display. |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 389 | if (mKeyguardShowing && isDisplayOccluded(DEFAULT_DISPLAY)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 390 | // The lock screen is currently showing, but is occluded by a window that can |
| 391 | // show on top of the lock screen. In this can we want to dismiss the docked |
| 392 | // stack since it will be complicated/risky to try to put the activity on top |
| 393 | // of the lock screen in the right fullscreen configuration. |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 394 | final TaskDisplayArea taskDisplayArea = mRootWindowContainer |
| 395 | .getDefaultTaskDisplayArea(); |
| 396 | if (!taskDisplayArea.isSplitScreenModeActivated()) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 397 | return; |
| 398 | } |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 399 | taskDisplayArea.onSplitScreenModeDismissed(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 400 | } |
| 401 | } |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 402 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 403 | private void updateKeyguardSleepToken() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 404 | for (int displayNdx = mRootWindowContainer.getChildCount() - 1; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 405 | displayNdx >= 0; displayNdx--) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 406 | final DisplayContent display = mRootWindowContainer.getChildAt(displayNdx); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 407 | updateKeyguardSleepToken(display.mDisplayId); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | private void updateKeyguardSleepToken(int displayId) { |
| 412 | final KeyguardDisplayState state = getDisplay(displayId); |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 413 | if (isKeyguardUnoccludedOrAodShowing(displayId) && state.mSleepToken == null) { |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 414 | state.acquiredSleepToken(); |
Issei Suzuki | 16d4de5 | 2019-07-29 13:12:01 +0000 | [diff] [blame] | 415 | } else if (!isKeyguardUnoccludedOrAodShowing(displayId) && state.mSleepToken != null) { |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 416 | state.releaseSleepToken(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
| 420 | private KeyguardDisplayState getDisplay(int displayId) { |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 421 | KeyguardDisplayState state = mDisplayStates.get(displayId); |
| 422 | if (state == null) { |
| 423 | state = new KeyguardDisplayState(mService, displayId); |
| 424 | mDisplayStates.append(displayId, state); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 425 | } |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 426 | return state; |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void onDisplayRemoved(int displayId) { |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 430 | final KeyguardDisplayState state = mDisplayStates.get(displayId); |
| 431 | if (state != null) { |
| 432 | state.onRemoved(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 433 | mDisplayStates.remove(displayId); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /** Represents Keyguard state per individual display. */ |
| 438 | private static class KeyguardDisplayState { |
| 439 | private final int mDisplayId; |
| 440 | private boolean mOccluded; |
| 441 | private ActivityRecord mDismissingKeyguardActivity; |
| 442 | private boolean mRequestDismissKeyguard; |
| 443 | private final ActivityTaskManagerService mService; |
| 444 | private SleepToken mSleepToken; |
| 445 | |
| 446 | KeyguardDisplayState(ActivityTaskManagerService service, int displayId) { |
| 447 | mService = service; |
| 448 | mDisplayId = displayId; |
| 449 | } |
| 450 | |
| 451 | void onRemoved() { |
| 452 | mDismissingKeyguardActivity = null; |
| 453 | releaseSleepToken(); |
| 454 | } |
| 455 | |
| 456 | void acquiredSleepToken() { |
| 457 | if (mSleepToken == null) { |
| 458 | mSleepToken = mService.acquireSleepToken("keyguard", mDisplayId); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void releaseSleepToken() { |
| 463 | if (mSleepToken != null) { |
| 464 | mSleepToken.release(); |
| 465 | mSleepToken = null; |
| 466 | } |
| 467 | } |
| 468 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 469 | void visibilitiesUpdated(KeyguardController controller, DisplayContent display) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 470 | final boolean lastOccluded = mOccluded; |
| 471 | final ActivityRecord lastDismissActivity = mDismissingKeyguardActivity; |
| 472 | mRequestDismissKeyguard = false; |
| 473 | mOccluded = false; |
| 474 | mDismissingKeyguardActivity = null; |
| 475 | |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 476 | final ActivityStack stack = getStackForControllingOccluding(display); |
| 477 | if (stack != null) { |
| 478 | final ActivityRecord topDismissing = stack.getTopDismissingKeyguardActivity(); |
| 479 | mOccluded = stack.topActivityOccludesKeyguard() || (topDismissing != null |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 480 | && stack.topRunningActivity() == topDismissing |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 481 | && controller.canShowWhileOccluded( |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 482 | true /* dismissKeyguard */, |
| 483 | false /* showWhenLocked */)); |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 484 | if (stack.getTopDismissingKeyguardActivity() != null) { |
| 485 | mDismissingKeyguardActivity = stack.getTopDismissingKeyguardActivity(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 486 | } |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame] | 487 | // FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD only apply for secondary display. |
| 488 | if (mDisplayId != DEFAULT_DISPLAY) { |
| 489 | mOccluded |= stack.canShowWithInsecureKeyguard() |
| 490 | && controller.canDismissKeyguard(); |
| 491 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 492 | } |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame] | 493 | // TODO(b/123372519): isShowingDream can only works on default display. |
| 494 | if (mDisplayId == DEFAULT_DISPLAY) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 495 | mOccluded |= mService.mRootWindowContainer.getDefaultDisplay().mDisplayContent |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 496 | .getDisplayPolicy().isShowingDreamLw(); |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame] | 497 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 498 | |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 499 | if (lastOccluded != mOccluded) { |
| 500 | controller.handleOccludedChanged(mDisplayId); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 501 | } |
| 502 | if (lastDismissActivity != mDismissingKeyguardActivity && !mOccluded |
| 503 | && mDismissingKeyguardActivity != null |
Brad Stenning | 2bdc21e | 2019-03-11 14:33:22 -0700 | [diff] [blame] | 504 | && controller.mWindowManager.isKeyguardSecure( |
| 505 | controller.mService.getCurrentUserId())) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 506 | mRequestDismissKeyguard = true; |
| 507 | } |
| 508 | } |
| 509 | |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 510 | /** |
| 511 | * Gets the stack used to check the occluded state. |
| 512 | * <p> |
| 513 | * Only the top non-pinned activity of the focusable stack on each display can control its |
| 514 | * occlusion state. |
| 515 | */ |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 516 | private ActivityStack getStackForControllingOccluding(DisplayContent display) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 517 | for (int tdaNdx = display.getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 518 | final TaskDisplayArea taskDisplayArea = display.getTaskDisplayAreaAt(tdaNdx); |
| 519 | for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { |
| 520 | final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); |
| 521 | if (stack != null && stack.isFocusableAndVisible() |
| 522 | && !stack.inPinnedWindowingMode()) { |
| 523 | return stack; |
| 524 | } |
wilsonshih | 9a10e9d | 2019-01-11 14:39:27 +0800 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | return null; |
| 528 | } |
| 529 | |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 530 | void dumpStatus(PrintWriter pw, String prefix) { |
| 531 | final StringBuilder sb = new StringBuilder(); |
| 532 | sb.append(prefix); |
| 533 | sb.append(" Occluded=").append(mOccluded) |
| 534 | .append(" DismissingKeyguardActivity=") |
| 535 | .append(mDismissingKeyguardActivity) |
| 536 | .append(" at display=") |
| 537 | .append(mDisplayId); |
| 538 | pw.println(sb.toString()); |
| 539 | } |
| 540 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 541 | void dumpDebug(ProtoOutputStream proto, long fieldId) { |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 542 | final long token = proto.start(fieldId); |
| 543 | proto.write(DISPLAY_ID, mDisplayId); |
| 544 | proto.write(KEYGUARD_OCCLUDED, mOccluded); |
| 545 | proto.end(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 549 | void dump(PrintWriter pw, String prefix) { |
| 550 | pw.println(prefix + "KeyguardController:"); |
| 551 | pw.println(prefix + " mKeyguardShowing=" + mKeyguardShowing); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 552 | pw.println(prefix + " mAodShowing=" + mAodShowing); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 553 | pw.println(prefix + " mKeyguardGoingAway=" + mKeyguardGoingAway); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 554 | dumpDisplayStates(pw, prefix); |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 555 | pw.println(prefix + " mDismissalRequested=" + mDismissalRequested); |
Winson Chung | 268eccb | 2020-03-26 13:43:44 -0700 | [diff] [blame] | 556 | pw.println(); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 557 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 558 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 559 | void dumpDebug(ProtoOutputStream proto, long fieldId) { |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 560 | final long token = proto.start(fieldId); |
Issei Suzuki | d6eb5a2 | 2019-02-20 23:08:03 +0100 | [diff] [blame] | 561 | proto.write(AOD_SHOWING, mAodShowing); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 562 | proto.write(KEYGUARD_SHOWING, mKeyguardShowing); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 563 | writeDisplayStatesToProto(proto, KEYGUARD_OCCLUDED_STATES); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 564 | proto.end(token); |
| 565 | } |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 566 | |
| 567 | private void dumpDisplayStates(PrintWriter pw, String prefix) { |
| 568 | for (int i = 0; i < mDisplayStates.size(); i++) { |
| 569 | mDisplayStates.valueAt(i).dumpStatus(pw, prefix); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | private void writeDisplayStatesToProto(ProtoOutputStream proto, long fieldId) { |
| 574 | for (int i = 0; i < mDisplayStates.size(); i++) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 575 | mDisplayStates.valueAt(i).dumpDebug(proto, fieldId); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 576 | } |
| 577 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 578 | } |