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