The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 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 |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 14 | * limitations under the License |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 17 | package com.android.systemui.keyguard; |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 18 | |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 19 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 20 | import static android.view.Display.INVALID_DISPLAY; |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 21 | |
| 22 | import static com.android.internal.telephony.IccCardConstants.State.ABSENT; |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.IccCardConstants.State.PIN_REQUIRED; |
| 24 | import static com.android.internal.telephony.IccCardConstants.State.PUK_REQUIRED; |
| 25 | import static com.android.internal.telephony.IccCardConstants.State.READY; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 26 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; |
| 27 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; |
| 28 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 29 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 30 | |
Adrian Roos | b60d47c | 2014-09-08 19:23:00 +0200 | [diff] [blame] | 31 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.app.AlarmManager; |
| 33 | import android.app.PendingIntent; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 34 | import android.app.StatusBarManager; |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 35 | import android.app.trust.TrustManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 37 | import android.content.ContentResolver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.Context; |
| 39 | import android.content.Intent; |
| 40 | import android.content.IntentFilter; |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 41 | import android.content.pm.UserInfo; |
Daniel Sandler | aec967a | 2010-02-20 01:05:22 -0500 | [diff] [blame] | 42 | import android.media.AudioManager; |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 43 | import android.media.SoundPool; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 44 | import android.os.Bundle; |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 45 | import android.os.DeadObjectException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.os.Handler; |
Jeff Brown | 109025d | 2012-08-14 20:41:30 -0700 | [diff] [blame] | 47 | import android.os.Looper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 48 | import android.os.Message; |
| 49 | import android.os.PowerManager; |
Dianne Hackborn | 4994c66 | 2009-09-23 22:21:23 -0700 | [diff] [blame] | 50 | import android.os.RemoteException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 51 | import android.os.SystemClock; |
Jim Miller | 1b15202 | 2009-10-28 16:08:15 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 53 | import android.os.Trace; |
Jeff Sharkey | 6a25cbd | 2012-08-23 12:14:26 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 56 | import android.provider.Settings; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 57 | import android.telephony.SubscriptionManager; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 58 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 59 | import android.util.EventLog; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 60 | import android.util.Log; |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 61 | import android.util.Slog; |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 62 | import android.util.SparseArray; |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 63 | import android.view.ViewGroup; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 64 | import android.view.WindowManagerPolicyConstants; |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 65 | import android.view.animation.Animation; |
| 66 | import android.view.animation.AnimationUtils; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 67 | |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 68 | import com.android.internal.logging.MetricsLogger; |
| 69 | import com.android.internal.logging.nano.MetricsProto; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 70 | import com.android.internal.policy.IKeyguardDismissCallback; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 71 | import com.android.internal.policy.IKeyguardDrawnCallback; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 72 | import com.android.internal.policy.IKeyguardExitCallback; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 73 | import com.android.internal.policy.IKeyguardStateCallback; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 74 | import com.android.internal.telephony.IccCardConstants; |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 75 | import com.android.internal.util.LatencyTracker; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 76 | import com.android.internal.widget.LockPatternUtils; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 77 | import com.android.keyguard.KeyguardConstants; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 78 | import com.android.keyguard.KeyguardDisplayManager; |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 79 | import com.android.keyguard.KeyguardSecurityView; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 80 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 81 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 82 | import com.android.keyguard.ViewMediatorCallback; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 83 | import com.android.systemui.Dependency; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 84 | import com.android.systemui.SystemUI; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 85 | import com.android.systemui.SystemUIFactory; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 86 | import com.android.systemui.UiOffloadThread; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 87 | import com.android.systemui.classifier.FalsingManager; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.phone.FingerprintUnlockController; |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 89 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 90 | import com.android.systemui.statusbar.phone.StatusBar; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 91 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Adrian Roos | 58b58fe | 2014-01-31 16:00:39 -0800 | [diff] [blame] | 92 | |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 93 | import java.io.FileDescriptor; |
| 94 | import java.io.PrintWriter; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 95 | import java.util.ArrayList; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 96 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 97 | /** |
| 98 | * Mediates requests related to the keyguard. This includes queries about the |
| 99 | * state of the keyguard, power management events that effect whether the keyguard |
| 100 | * should be shown or reset, callbacks to the phone window manager to notify |
| 101 | * it of when the keyguard is showing, and events from the keyguard view itself |
| 102 | * stating that the keyguard was succesfully unlocked. |
| 103 | * |
| 104 | * Note that the keyguard view is shown when the screen is off (as appropriate) |
| 105 | * so that once the screen comes on, it will be ready immediately. |
| 106 | * |
| 107 | * Example queries about the keyguard: |
| 108 | * - is {movement, key} one that should wake the keygaurd? |
| 109 | * - is the keyguard showing? |
| 110 | * - are input events restricted due to the state of the keyguard? |
| 111 | * |
| 112 | * Callbacks to the phone window manager: |
| 113 | * - the keyguard is showing |
| 114 | * |
| 115 | * Example external events that translate to keyguard view changes: |
| 116 | * - screen turned off -> reset the keyguard, and show it so it will be ready |
| 117 | * next time the screen turns on |
| 118 | * - keyboard is slid open -> if the keyguard is not secure, hide it |
| 119 | * |
| 120 | * Events from the keyguard view: |
| 121 | * - user succesfully unlocked keyguard -> hide keyguard view, and no longer |
| 122 | * restrict input events. |
| 123 | * |
| 124 | * Note: in addition to normal power managment events that effect the state of |
| 125 | * whether the keyguard should be showing, external apps and services may request |
| 126 | * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When |
| 127 | * false, this will override all other conditions for turning on the keyguard. |
| 128 | * |
| 129 | * Threading and synchronization: |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 130 | * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants}, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | * and runs on its thread. The keyguard UI is created from that thread in the |
| 132 | * constructor of this class. The apis may be called from other threads, including the |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 133 | * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 134 | * Therefore, methods on this class are synchronized, and any action that is pointed |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 135 | * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 136 | * thread of the keyguard. |
| 137 | */ |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 138 | public class KeyguardViewMediator extends SystemUI { |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 139 | private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 140 | private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000; |
| 141 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 142 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
| 143 | private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 144 | |
| 145 | private final static String TAG = "KeyguardViewMediator"; |
| 146 | |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 147 | private static final String DELAYED_KEYGUARD_ACTION = |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 148 | "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 149 | private static final String DELAYED_LOCK_PROFILE_ACTION = |
| 150 | "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 151 | |
Kevin Chyn | 18e91aa | 2018-04-11 12:55:45 -0700 | [diff] [blame] | 152 | private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF"; |
| 153 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 154 | // used for handler messages |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 155 | private static final int SHOW = 1; |
| 156 | private static final int HIDE = 2; |
| 157 | private static final int RESET = 3; |
| 158 | private static final int VERIFY_UNLOCK = 4; |
| 159 | private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5; |
| 160 | private static final int NOTIFY_SCREEN_TURNING_ON = 6; |
| 161 | private static final int KEYGUARD_DONE = 7; |
| 162 | private static final int KEYGUARD_DONE_DRAWING = 8; |
| 163 | private static final int SET_OCCLUDED = 9; |
| 164 | private static final int KEYGUARD_TIMEOUT = 10; |
| 165 | private static final int DISMISS = 11; |
| 166 | private static final int START_KEYGUARD_EXIT_ANIM = 12; |
| 167 | private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13; |
| 168 | private static final int NOTIFY_STARTED_WAKING_UP = 14; |
| 169 | private static final int NOTIFY_SCREEN_TURNED_ON = 15; |
| 170 | private static final int NOTIFY_SCREEN_TURNED_OFF = 16; |
| 171 | private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17; |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 172 | private static final int SYSTEM_READY = 18; |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 173 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 174 | /** |
| 175 | * The default amount of time we stay awake (used for all key input) |
| 176 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 177 | public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 178 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 179 | /** |
| 180 | * How long to wait after the screen turns off due to timeout before |
| 181 | * turning on the keyguard (i.e, the user has this much time to turn |
| 182 | * the screen back on without having to face the keyguard). |
| 183 | */ |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 184 | private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 185 | |
| 186 | /** |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 187 | * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()} |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 188 | * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)} |
| 189 | * that is reenabling the keyguard. |
| 190 | */ |
| 191 | private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 192 | |
Daniel Sandler | 74d188c | 2011-08-10 00:00:31 -0400 | [diff] [blame] | 193 | /** |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 194 | * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the |
| 195 | * keyguard to show even if it is disabled for the current user. |
| 196 | */ |
| 197 | public static final String OPTION_FORCE_SHOW = "force_show"; |
| 198 | |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 199 | /** The stream type that the lock sounds are tied to. */ |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 200 | private int mUiSoundsStreamType; |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 201 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 202 | private AlarmManager mAlarmManager; |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 203 | private AudioManager mAudioManager; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 204 | private StatusBarManager mStatusBarManager; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 205 | private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 206 | |
| 207 | private boolean mSystemReady; |
Jason Monk | cf5a953 | 2014-09-17 16:22:19 -0400 | [diff] [blame] | 208 | private boolean mBootCompleted; |
| 209 | private boolean mBootSendUserPresent; |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 210 | private boolean mShuttingDown; |
Daniel Sandler | 0060a9b | 2010-03-15 23:09:57 -0400 | [diff] [blame] | 211 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 212 | /** High level access to the power manager for WakeLocks */ |
| 213 | private PowerManager mPM; |
| 214 | |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 215 | /** TrustManager for letting it know when we change visibility */ |
| 216 | private TrustManager mTrustManager; |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 217 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 218 | /** |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 219 | * Used to keep the device awake while to ensure the keyguard finishes opening before |
| 220 | * we sleep. |
| 221 | */ |
| 222 | private PowerManager.WakeLock mShowKeyguardWakeLock; |
| 223 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 224 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 225 | |
| 226 | // these are protected by synchronized (this) |
| 227 | |
| 228 | /** |
Mike Lockwood | 5d258b6 | 2009-12-02 13:50:45 -0500 | [diff] [blame] | 229 | * External apps (like the phone app) can tell us to disable the keygaurd. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 230 | */ |
| 231 | private boolean mExternallyEnabled = true; |
| 232 | |
| 233 | /** |
| 234 | * Remember if an external call to {@link #setKeyguardEnabled} with value |
| 235 | * false caused us to hide the keyguard, so that we need to reshow it once |
| 236 | * the keygaurd is reenabled with another call with value true. |
| 237 | */ |
| 238 | private boolean mNeedToReshowWhenReenabled = false; |
| 239 | |
| 240 | // cached value of whether we are showing (need to know this to quickly |
| 241 | // answer whether the input should be restricted) |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 242 | private boolean mShowing; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 243 | |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 244 | // AOD is enabled and status bar is in AOD state. |
| 245 | private boolean mAodShowing; |
| 246 | |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 247 | // display id of the secondary display on which we have put a keyguard window |
| 248 | private int mSecondaryDisplayShowing = INVALID_DISPLAY; |
| 249 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 250 | /** Cached value of #isInputRestricted */ |
| 251 | private boolean mInputRestricted; |
| 252 | |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 253 | // true if the keyguard is hidden by another window |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 254 | private boolean mOccluded = false; |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 255 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 256 | /** |
| 257 | * Helps remember whether the screen has turned on since the last time |
| 258 | * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} |
| 259 | */ |
| 260 | private int mDelayedShowingSequence; |
| 261 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 262 | /** |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 263 | * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case. |
| 264 | */ |
| 265 | private int mDelayedProfileShowingSequence; |
| 266 | |
| 267 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 268 | * If the user has disabled the keyguard, then requests to exit, this is |
| 269 | * how we'll ultimately let them know whether it was successful. We use this |
| 270 | * var being non-null as an indicator that there is an in progress request. |
| 271 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 272 | private IKeyguardExitCallback mExitSecureCallback; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 273 | private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 274 | |
| 275 | // the properties of the keyguard |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 276 | |
| 277 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 278 | |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 279 | /** |
| 280 | * Last SIM state reported by the telephony system. |
| 281 | * Index is the slotId - in case of multiple SIM cards. |
| 282 | */ |
| 283 | private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>(); |
| 284 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 285 | private boolean mDeviceInteractive; |
Jorim Jaggi | 4474f54 | 2015-07-09 16:08:02 -0700 | [diff] [blame] | 286 | private boolean mGoingToSleep; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 287 | |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 288 | // last known state of the cellular connection |
| 289 | private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; |
| 290 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 291 | /** |
Jorim Jaggi | 53c68a4 | 2014-06-17 15:04:47 -0700 | [diff] [blame] | 292 | * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be |
| 293 | * called. |
| 294 | * */ |
| 295 | private boolean mHiding; |
| 296 | |
| 297 | /** |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 298 | * we send this intent when the keyguard is dismissed. |
| 299 | */ |
Jim Miller | 17f509a | 2013-02-28 18:36:12 -0800 | [diff] [blame] | 300 | private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT) |
| 301 | .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
Chad Brubaker | 291df4f | 2017-03-14 10:23:02 -0700 | [diff] [blame] | 302 | | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
| 303 | | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS); |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 304 | |
| 305 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 306 | * {@link #setKeyguardEnabled} waits on this condition when it reenables |
| 307 | * the keyguard. |
| 308 | */ |
| 309 | private boolean mWaitingUntilKeyguardVisible = false; |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 310 | private LockPatternUtils mLockPatternUtils; |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 311 | private boolean mKeyguardDonePending = false; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 312 | private boolean mHideAnimationRun = false; |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 313 | private boolean mHideAnimationRunning = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 314 | |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 315 | private SoundPool mLockSounds; |
| 316 | private int mLockSoundId; |
| 317 | private int mUnlockSoundId; |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 318 | private int mTrustedSoundId; |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 319 | private int mLockSoundStreamId; |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 320 | |
| 321 | /** |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 322 | * The animation used for hiding keyguard. This is used to fetch the animation timings if |
| 323 | * WindowManager is not providing us with them. |
| 324 | */ |
| 325 | private Animation mHideAnimation; |
| 326 | |
| 327 | /** |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 328 | * The volume applied to the lock/unlock sounds. |
| 329 | */ |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 330 | private float mLockSoundVolume; |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 331 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 332 | /** |
Jim Miller | 3192148 | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 333 | * For managing external displays |
| 334 | */ |
| 335 | private KeyguardDisplayManager mKeyguardDisplayManager; |
| 336 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 337 | private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>(); |
| 338 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 339 | /** |
| 340 | * When starting going to sleep, we figured out that we need to reset Keyguard state and this |
| 341 | * should be committed when finished going to sleep. |
| 342 | */ |
| 343 | private boolean mPendingReset; |
| 344 | |
| 345 | /** |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 346 | * When starting going to sleep, we figured out that we need to lock Keyguard and this should be |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 347 | * committed when finished going to sleep. |
| 348 | */ |
| 349 | private boolean mPendingLock; |
| 350 | |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 351 | /** |
| 352 | * Controller for showing individual "work challenge" lock screen windows inside managed profile |
| 353 | * tasks when the current user has been unlocked but the profile is still locked. |
| 354 | */ |
| 355 | private WorkLockActivityController mWorkLockController; |
| 356 | |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 357 | /** |
| 358 | * @see #setPulsing(boolean) |
| 359 | */ |
| 360 | private boolean mPulsing; |
| 361 | |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 362 | private boolean mLockLater; |
| 363 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 364 | private boolean mWakeAndUnlocking; |
| 365 | private IKeyguardDrawnCallback mDrawnCallback; |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 366 | private boolean mLockWhenSimRemoved; |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 367 | private CharSequence mCustomMessage; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 368 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 369 | KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { |
| 370 | |
| 371 | @Override |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 372 | public void onUserSwitching(int userId) { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 373 | // Note that the mLockPatternUtils user has already been updated from setCurrentUser. |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 374 | // We need to force a reset of the views, since lockNow (called by |
| 375 | // ActivityManagerService) will not reconstruct the keyguard if it is already showing. |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 376 | synchronized (KeyguardViewMediator.this) { |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 377 | resetKeyguardDonePendingLocked(); |
Alex Chau | 77ef9fc | 2018-04-11 15:41:32 +0100 | [diff] [blame] | 378 | if (mLockPatternUtils.isLockScreenDisabled(userId)) { |
| 379 | // If we switching to a user that has keyguard disabled, dismiss keyguard. |
| 380 | dismiss(null /* callback */, null /* message */); |
| 381 | } else { |
| 382 | resetStateLocked(); |
| 383 | } |
John Spurlock | 4e6922d | 2012-10-04 14:51:51 -0400 | [diff] [blame] | 384 | adjustStatusBarLocked(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 385 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 389 | public void onUserSwitchComplete(int userId) { |
Xiaohui Chen | 87d0e25 | 2015-07-30 15:38:16 -0700 | [diff] [blame] | 390 | if (userId != UserHandle.USER_SYSTEM) { |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 391 | UserInfo info = UserManager.get(mContext).getUserInfo(userId); |
Kevin Chyn | f2c0a64 | 2017-05-25 11:29:08 -0700 | [diff] [blame] | 392 | // Don't try to dismiss if the user has Pin/Patter/Password set |
| 393 | if (info == null || mLockPatternUtils.isSecure(userId)) { |
| 394 | return; |
| 395 | } else if (info.isGuest() || info.isDemo()) { |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 396 | // If we just switched to a guest, try to dismiss keyguard. |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 397 | dismiss(null /* callback */, null /* message */); |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 398 | } |
| 399 | } |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Override |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 403 | public void onUserInfoChanged(int userId) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 407 | public void onPhoneStateChanged(int phoneState) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 408 | synchronized (KeyguardViewMediator.this) { |
| 409 | if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 410 | && !mDeviceInteractive // screen off |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 411 | && mExternallyEnabled) { // not disabled by any app |
| 412 | |
| 413 | // note: this is a way to gracefully reenable the keyguard when the call |
| 414 | // ends and the screen is off without always reenabling the keyguard |
| 415 | // each time the screen turns off while in call (and having an occasional ugly |
| 416 | // flicker while turning back on the screen and disabling the keyguard again). |
| 417 | if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the " |
| 418 | + "keyguard is showing"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 419 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 422 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 423 | |
| 424 | @Override |
| 425 | public void onClockVisibilityChanged() { |
| 426 | adjustStatusBarLocked(); |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void onDeviceProvisioned() { |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 431 | sendUserPresentBroadcast(); |
Amith Yamasani | cb15d66 | 2015-11-10 11:11:15 -0800 | [diff] [blame] | 432 | synchronized (KeyguardViewMediator.this) { |
| 433 | // If system user is provisioned, we might want to lock now to avoid showing launcher |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 434 | if (mustNotUnlockCurrentUser()) { |
Amith Yamasani | cb15d66 | 2015-11-10 11:11:15 -0800 | [diff] [blame] | 435 | doKeyguardLocked(null); |
| 436 | } |
| 437 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 440 | @Override |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 441 | public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) { |
| 442 | |
| 443 | if (DEBUG_SIM_STATES) { |
| 444 | Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId |
| 445 | + ",state=" + simState + ")"); |
| 446 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 447 | |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 448 | int size = mKeyguardStateCallbacks.size(); |
| 449 | boolean simPinSecure = mUpdateMonitor.isSimPinSecure(); |
| 450 | for (int i = size - 1; i >= 0; i--) { |
| 451 | try { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 452 | mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure); |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 453 | } catch (RemoteException e) { |
| 454 | Slog.w(TAG, "Failed to call onSimSecureStateChanged", e); |
| 455 | if (e instanceof DeadObjectException) { |
| 456 | mKeyguardStateCallbacks.remove(i); |
| 457 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 458 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 461 | boolean simWasLocked; |
| 462 | synchronized (KeyguardViewMediator.this) { |
| 463 | IccCardConstants.State lastState = mLastSimStates.get(slotId); |
Brad Ebinger | 4b2f6e2 | 2018-12-20 21:11:44 -0800 | [diff] [blame] | 464 | simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED); |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 465 | mLastSimStates.append(slotId, simState); |
| 466 | } |
| 467 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 468 | switch (simState) { |
| 469 | case NOT_READY: |
| 470 | case ABSENT: |
| 471 | // only force lock screen in case of missing sim if user hasn't |
| 472 | // gone through setup wizard |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 473 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | b256e4e2 | 2014-10-31 17:27:13 -0700 | [diff] [blame] | 474 | if (shouldWaitForProvisioning()) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 475 | if (!mShowing) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 476 | if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing," |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 477 | + " we need to show the keyguard since the " |
| 478 | + "device isn't provisioned yet."); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 479 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 480 | } else { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 481 | resetStateLocked(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 484 | if (simState == ABSENT) { |
| 485 | // MVNO SIMs can become transiently NOT_READY when switching networks, |
| 486 | // so we should only lock when they are ABSENT. |
| 487 | onSimAbsentLocked(); |
Lucas Dupin | 0b196c6 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 488 | if (simWasLocked) { |
Brad Ebinger | 4b2f6e2 | 2018-12-20 21:11:44 -0800 | [diff] [blame] | 489 | if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the " |
| 490 | + "previous state was locked. Reset the state."); |
Lucas Dupin | 0b196c6 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 491 | resetStateLocked(); |
| 492 | } |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 493 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 494 | } |
| 495 | break; |
| 496 | case PIN_REQUIRED: |
| 497 | case PUK_REQUIRED: |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 498 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 499 | if (!mShowing) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 500 | if (DEBUG_SIM_STATES) Log.d(TAG, |
| 501 | "INTENT_VALUE_ICC_LOCKED and keygaurd isn't " |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 502 | + "showing; need to show keyguard so user can enter sim pin"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 503 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 504 | } else { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 505 | resetStateLocked(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | break; |
| 509 | case PERM_DISABLED: |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 510 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 511 | if (!mShowing) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 512 | if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and " |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 513 | + "keygaurd isn't showing."); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 514 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 515 | } else { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 516 | if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to" |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 517 | + "show permanently disabled message in lockscreen."); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 518 | resetStateLocked(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 519 | } |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 520 | onSimAbsentLocked(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 521 | } |
| 522 | break; |
| 523 | case READY: |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 524 | synchronized (KeyguardViewMediator.this) { |
Lucas Dupin | 2508afe | 2018-09-17 17:17:14 -0700 | [diff] [blame] | 525 | if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing); |
| 526 | if (mShowing && simWasLocked) { |
Brad Ebinger | 4b2f6e2 | 2018-12-20 21:11:44 -0800 | [diff] [blame] | 527 | if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the " |
| 528 | + "previous state was locked. Reset the state."); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 529 | resetStateLocked(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 530 | } |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 531 | mLockWhenSimRemoved = true; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 532 | } |
| 533 | break; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 534 | default: |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 535 | if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 536 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 539 | |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 540 | private void onSimAbsentLocked() { |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 541 | if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) { |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 542 | mLockWhenSimRemoved = false; |
| 543 | MetricsLogger.action(mContext, |
| 544 | MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing); |
| 545 | if (!mShowing) { |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 546 | Log.i(TAG, "SIM removed, showing keyguard"); |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 547 | doKeyguardLocked(null); |
Adrian Roos | 1cffe3c | 2016-11-28 15:46:06 -0800 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 552 | @Override |
| 553 | public void onFingerprintAuthFailed() { |
| 554 | final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); |
| 555 | if (mLockPatternUtils.isSecure(currentUser)) { |
| 556 | mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt( |
| 557 | currentUser); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void onFingerprintAuthenticated(int userId) { |
| 563 | if (mLockPatternUtils.isSecure(userId)) { |
| 564 | mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt( |
| 565 | userId); |
| 566 | } |
| 567 | } |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 568 | |
| 569 | @Override |
| 570 | public void onTrustChanged(int userId) { |
| 571 | if (userId == KeyguardUpdateMonitor.getCurrentUser()) { |
| 572 | synchronized (KeyguardViewMediator.this) { |
| 573 | notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId)); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 578 | @Override |
| 579 | public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) { |
| 580 | synchronized (KeyguardViewMediator.this) { |
| 581 | notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper); |
| 582 | } |
| 583 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 584 | }; |
| 585 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 586 | ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 587 | |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 588 | @Override |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 589 | public void userActivity() { |
| 590 | KeyguardViewMediator.this.userActivity(); |
| 591 | } |
| 592 | |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 593 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 594 | public void keyguardDone(boolean strongAuth, int targetUserId) { |
| 595 | if (targetUserId != ActivityManager.getCurrentUser()) { |
| 596 | return; |
| 597 | } |
| 598 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 599 | tryKeyguardDone(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 602 | @Override |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 603 | public void keyguardDoneDrawing() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 604 | Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing"); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 605 | mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 606 | Trace.endSection(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public void setNeedsInput(boolean needsInput) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 611 | mStatusBarKeyguardViewManager.setNeedsInput(needsInput); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 612 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 613 | |
| 614 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 615 | public void keyguardDonePending(boolean strongAuth, int targetUserId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 616 | Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending"); |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 617 | if (targetUserId != ActivityManager.getCurrentUser()) { |
Nick Desaulniers | aeb2e1e | 2016-07-27 15:36:01 -0700 | [diff] [blame] | 618 | Trace.endSection(); |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 619 | return; |
| 620 | } |
| 621 | |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 622 | mKeyguardDonePending = true; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 623 | mHideAnimationRun = true; |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 624 | mHideAnimationRunning = true; |
| 625 | mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 626 | mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT, |
| 627 | KEYGUARD_DONE_PENDING_TIMEOUT_MS); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 628 | Trace.endSection(); |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 629 | } |
Jim Miller | 0b9d8ac | 2013-11-07 19:15:49 -0800 | [diff] [blame] | 630 | |
| 631 | @Override |
| 632 | public void keyguardGone() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 633 | Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone"); |
Jim Miller | 0b9d8ac | 2013-11-07 19:15:49 -0800 | [diff] [blame] | 634 | mKeyguardDisplayManager.hide(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 635 | Trace.endSection(); |
Jim Miller | 0b9d8ac | 2013-11-07 19:15:49 -0800 | [diff] [blame] | 636 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 637 | |
| 638 | @Override |
| 639 | public void readyForKeyguardDone() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 640 | Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone"); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 641 | if (mKeyguardDonePending) { |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 642 | mKeyguardDonePending = false; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 643 | tryKeyguardDone(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 644 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 645 | Trace.endSection(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 646 | } |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 647 | |
| 648 | @Override |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 649 | public void resetKeyguard() { |
| 650 | resetStateLocked(); |
| 651 | } |
| 652 | |
| 653 | @Override |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 654 | public void onBouncerVisiblityChanged(boolean shown) { |
| 655 | synchronized (KeyguardViewMediator.this) { |
| 656 | adjustStatusBarLocked(shown); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | @Override |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 661 | public void playTrustedSound() { |
| 662 | KeyguardViewMediator.this.playTrustedSound(); |
| 663 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 664 | |
| 665 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 666 | public boolean isScreenOn() { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 667 | return mDeviceInteractive; |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 668 | } |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 669 | |
| 670 | @Override |
| 671 | public int getBouncerPromptReason() { |
| 672 | int currentUser = ActivityManager.getCurrentUser(); |
Adrian Roos | c13723f | 2016-01-12 20:29:03 +0100 | [diff] [blame] | 673 | boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser); |
| 674 | boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser); |
| 675 | boolean any = trust || fingerprint; |
| 676 | KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker = |
| 677 | mUpdateMonitor.getStrongAuthTracker(); |
| 678 | int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser); |
| 679 | |
| 680 | if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) { |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 681 | return KeyguardSecurityView.PROMPT_REASON_RESTART; |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 682 | } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) { |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 683 | return KeyguardSecurityView.PROMPT_REASON_TIMEOUT; |
Adrian Roos | c13723f | 2016-01-12 20:29:03 +0100 | [diff] [blame] | 684 | } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) { |
| 685 | return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN; |
| 686 | } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) { |
| 687 | return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST; |
| 688 | } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) { |
| 689 | return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT; |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 690 | } |
| 691 | return KeyguardSecurityView.PROMPT_REASON_NONE; |
| 692 | } |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 693 | |
| 694 | @Override |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 695 | public CharSequence consumeCustomMessage() { |
| 696 | final CharSequence message = mCustomMessage; |
| 697 | mCustomMessage = null; |
| 698 | return message; |
| 699 | } |
| 700 | |
| 701 | @Override |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 702 | public void onSecondaryDisplayShowingChanged(int displayId) { |
| 703 | synchronized (KeyguardViewMediator.this) { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 704 | setShowingLocked(mShowing, mAodShowing, displayId, false); |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 707 | }; |
| 708 | |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 709 | public void userActivity() { |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 710 | mPM.userActivity(SystemClock.uptimeMillis(), false); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 713 | boolean mustNotUnlockCurrentUser() { |
Christine Franks | 338c6ed | 2017-08-08 09:39:16 -0700 | [diff] [blame] | 714 | return UserManager.isSplitSystemUser() |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 715 | && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM; |
| 716 | } |
| 717 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 718 | private void setupLocked() { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 719 | mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 720 | mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE); |
| 721 | |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 722 | mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); |
| 723 | mShowKeyguardWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 724 | |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 725 | IntentFilter filter = new IntentFilter(); |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 726 | filter.addAction(Intent.ACTION_SHUTDOWN); |
| 727 | mContext.registerReceiver(mBroadcastReceiver, filter); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 728 | |
Kevin Chyn | 18e91aa | 2018-04-11 12:55:45 -0700 | [diff] [blame] | 729 | final IntentFilter delayedActionFilter = new IntentFilter(); |
| 730 | delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION); |
| 731 | delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION); |
| 732 | mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter, |
| 733 | SYSTEMUI_PERMISSION, null /* scheduler */); |
| 734 | |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 735 | mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback); |
Jim Miller | 3192148 | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 736 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 737 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 738 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 739 | mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 740 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 741 | mLockPatternUtils = new LockPatternUtils(mContext); |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 742 | KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 743 | |
Jorim Jaggi | 7687aaa9 | 2017-05-12 00:21:06 +0200 | [diff] [blame] | 744 | // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard |
| 745 | // is disabled. |
| 746 | if (mContext.getResources().getBoolean( |
| 747 | com.android.keyguard.R.bool.config_enableKeyguardService)) { |
| 748 | setShowingLocked(!shouldWaitForProvisioning() |
| 749 | && !mLockPatternUtils.isLockScreenDisabled( |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 750 | KeyguardUpdateMonitor.getCurrentUser()), |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 751 | mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */); |
Leif Hendrik Wilden | c6dc1c9 | 2018-02-01 10:54:15 -0800 | [diff] [blame] | 752 | } else { |
| 753 | // The system's keyguard is disabled or missing. |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 754 | setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true); |
Jorim Jaggi | 7687aaa9 | 2017-05-12 00:21:06 +0200 | [diff] [blame] | 755 | } |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 756 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 757 | mStatusBarKeyguardViewManager = |
| 758 | SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext, |
| 759 | mViewMediatorCallback, mLockPatternUtils); |
Daniel Sandler | 687a327 | 2010-03-13 15:44:47 -0500 | [diff] [blame] | 760 | final ContentResolver cr = mContext.getContentResolver(); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 761 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 762 | mDeviceInteractive = mPM.isInteractive(); |
Daniel Hansson | 4b71686 | 2012-03-29 11:02:05 +0200 | [diff] [blame] | 763 | |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 764 | mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 765 | String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 766 | if (soundPath != null) { |
| 767 | mLockSoundId = mLockSounds.load(soundPath, 1); |
| 768 | } |
| 769 | if (soundPath == null || mLockSoundId == 0) { |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 770 | Log.w(TAG, "failed to load lock sound from " + soundPath); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 771 | } |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 772 | soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 773 | if (soundPath != null) { |
| 774 | mUnlockSoundId = mLockSounds.load(soundPath, 1); |
| 775 | } |
| 776 | if (soundPath == null || mUnlockSoundId == 0) { |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 777 | Log.w(TAG, "failed to load unlock sound from " + soundPath); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 778 | } |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 779 | soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND); |
| 780 | if (soundPath != null) { |
| 781 | mTrustedSoundId = mLockSounds.load(soundPath, 1); |
| 782 | } |
| 783 | if (soundPath == null || mTrustedSoundId == 0) { |
| 784 | Log.w(TAG, "failed to load trusted sound from " + soundPath); |
| 785 | } |
| 786 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 787 | int lockSoundDefaultAttenuation = mContext.getResources().getInteger( |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 788 | com.android.internal.R.integer.config_lockSoundVolumeDb); |
Jean-Michel Trivi | f2b0c11 | 2012-07-09 11:59:11 -0700 | [diff] [blame] | 789 | mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20); |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 790 | |
| 791 | mHideAnimation = AnimationUtils.loadAnimation(mContext, |
| 792 | com.android.internal.R.anim.lock_screen_behind_enter); |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 793 | |
| 794 | mWorkLockController = new WorkLockActivityController(mContext); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 795 | } |
| 796 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 797 | @Override |
| 798 | public void start() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 799 | synchronized (this) { |
| 800 | setupLocked(); |
| 801 | } |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 802 | putComponent(KeyguardViewMediator.class, this); |
| 803 | } |
| 804 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 805 | /** |
| 806 | * Let us know that the system is ready after startup. |
| 807 | */ |
| 808 | public void onSystemReady() { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 809 | mHandler.obtainMessage(SYSTEM_READY).sendToTarget(); |
| 810 | } |
| 811 | |
| 812 | private void handleSystemReady() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 813 | synchronized (this) { |
| 814 | if (DEBUG) Log.d(TAG, "onSystemReady"); |
| 815 | mSystemReady = true; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 816 | doKeyguardLocked(null); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 817 | mUpdateMonitor.registerCallback(mUpdateCallback); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 818 | } |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 819 | // Most services aren't available until the system reaches the ready state, so we |
| 820 | // send it here when the device first boots. |
| 821 | maybeSendUserPresentBroadcast(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Called to let us know the screen was turned off. |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 826 | * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or |
| 827 | * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 828 | */ |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 829 | public void onStartedGoingToSleep(int why) { |
| 830 | if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 831 | synchronized (this) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 832 | mDeviceInteractive = false; |
Jorim Jaggi | 4474f54 | 2015-07-09 16:08:02 -0700 | [diff] [blame] | 833 | mGoingToSleep = true; |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 834 | |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 835 | // Lock immediately based on setting if secure (user has a pin/pattern/password). |
| 836 | // This also "locks" the device when not secure to provide easy access to the |
| 837 | // camera while preventing unwanted input. |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 838 | int currentUser = KeyguardUpdateMonitor.getCurrentUser(); |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 839 | final boolean lockImmediately = |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 840 | mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser) |
| 841 | || !mLockPatternUtils.isSecure(currentUser); |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 842 | long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser()); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 843 | mLockLater = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 844 | if (mExitSecureCallback != null) { |
| 845 | if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 846 | try { |
| 847 | mExitSecureCallback.onKeyguardExitResult(false); |
| 848 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 849 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 850 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | mExitSecureCallback = null; |
| 852 | if (!mExternallyEnabled) { |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 853 | hideLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 854 | } |
| 855 | } else if (mShowing) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 856 | mPendingReset = true; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 857 | } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0) |
| 858 | || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) { |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 859 | doKeyguardLaterLocked(timeout); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 860 | mLockLater = true; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 861 | } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) { |
| 862 | mPendingLock = true; |
| 863 | } |
| 864 | |
Jorim Jaggi | 853cbe3 | 2015-06-04 16:31:54 -0700 | [diff] [blame] | 865 | if (mPendingLock) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 866 | playSounds(true); |
| 867 | } |
| 868 | } |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 869 | KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why); |
Jorim Jaggi | 18f18ae | 2015-09-10 15:48:21 -0700 | [diff] [blame] | 870 | notifyStartedGoingToSleep(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 873 | public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 874 | if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")"); |
| 875 | synchronized (this) { |
| 876 | mDeviceInteractive = false; |
Jorim Jaggi | 4474f54 | 2015-07-09 16:08:02 -0700 | [diff] [blame] | 877 | mGoingToSleep = false; |
Adrian Roos | e4cb6c8a | 2017-07-19 18:08:07 +0200 | [diff] [blame] | 878 | mWakeAndUnlocking = false; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 879 | |
| 880 | resetKeyguardDonePendingLocked(); |
| 881 | mHideAnimationRun = false; |
| 882 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 883 | notifyFinishedGoingToSleep(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 884 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 885 | if (cameraGestureTriggered) { |
| 886 | Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking."); |
| 887 | |
| 888 | // Just to make sure, make sure the device is awake. |
| 889 | mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(), |
| 890 | "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK"); |
| 891 | mPendingLock = false; |
| 892 | mPendingReset = false; |
| 893 | } |
| 894 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 895 | if (mPendingReset) { |
| 896 | resetStateLocked(); |
| 897 | mPendingReset = false; |
| 898 | } |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 899 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 900 | if (mPendingLock) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 901 | doKeyguardLocked(null); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 902 | mPendingLock = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 903 | } |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 904 | |
| 905 | // We do not have timeout and power button instant lock setting for profile lock. |
| 906 | // So we use the personal setting if there is any. But if there is no device |
| 907 | // we need to make sure we lock it immediately when the screen is off. |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 908 | if (!mLockLater && !cameraGestureTriggered) { |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 909 | doKeyguardForChildProfilesLocked(); |
| 910 | } |
| 911 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 912 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 913 | KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 916 | private long getLockTimeout(int userId) { |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 917 | // if the screen turned off because of timeout or the user hit the power button |
| 918 | // and we don't need to lock immediately, set an alarm |
| 919 | // to enable it a little bit later (i.e, give the user a chance |
| 920 | // to turn the screen back on within a certain window without |
| 921 | // having to unlock the screen) |
| 922 | final ContentResolver cr = mContext.getContentResolver(); |
| 923 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 924 | // From SecuritySettings |
| 925 | final long lockAfterTimeout = Settings.Secure.getInt(cr, |
| 926 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, |
| 927 | KEYGUARD_LOCK_AFTER_DELAY_DEFAULT); |
| 928 | |
| 929 | // From DevicePolicyAdmin |
| 930 | final long policyTimeout = mLockPatternUtils.getDevicePolicyManager() |
Pavel Grafov | 2893998 | 2017-10-03 15:11:52 +0100 | [diff] [blame] | 931 | .getMaximumTimeToLock(null, userId); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 932 | |
| 933 | long timeout; |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 934 | |
Clara Bayarri | 3dc575f | 2016-02-17 15:17:14 +0000 | [diff] [blame] | 935 | if (policyTimeout <= 0) { |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 936 | timeout = lockAfterTimeout; |
| 937 | } else { |
| 938 | // From DisplaySettings |
| 939 | long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT, |
| 940 | KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT); |
| 941 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 942 | // policy in effect. Make sure we don't go beyond policy limit. |
| 943 | displayTimeout = Math.max(displayTimeout, 0); // ignore negative values |
| 944 | timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 945 | timeout = Math.max(timeout, 0); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 946 | } |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 947 | return timeout; |
| 948 | } |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 949 | |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 950 | private void doKeyguardLaterLocked() { |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 951 | long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser()); |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 952 | if (timeout == 0) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 953 | doKeyguardLocked(null); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 954 | } else { |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 955 | doKeyguardLaterLocked(timeout); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 959 | private void doKeyguardLaterLocked(long timeout) { |
| 960 | // Lock in the future |
| 961 | long when = SystemClock.elapsedRealtime() + timeout; |
| 962 | Intent intent = new Intent(DELAYED_KEYGUARD_ACTION); |
| 963 | intent.putExtra("seq", mDelayedShowingSequence); |
Jorim Jaggi | ad0ce3a | 2016-04-27 13:15:41 -0700 | [diff] [blame] | 964 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 965 | PendingIntent sender = PendingIntent.getBroadcast(mContext, |
| 966 | 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); |
Jim Miller | a622d3cc | 2016-03-02 16:02:24 -0800 | [diff] [blame] | 967 | mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender); |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 968 | if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = " |
| 969 | + mDelayedShowingSequence); |
Clara Bayarri | 3dc575f | 2016-02-17 15:17:14 +0000 | [diff] [blame] | 970 | doKeyguardLaterForChildProfilesLocked(); |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 971 | } |
Clara Bayarri | 10ad84a | 2015-12-01 17:38:05 +0000 | [diff] [blame] | 972 | |
Clara Bayarri | 3dc575f | 2016-02-17 15:17:14 +0000 | [diff] [blame] | 973 | private void doKeyguardLaterForChildProfilesLocked() { |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 974 | UserManager um = UserManager.get(mContext); |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 975 | for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { |
| 976 | if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { |
| 977 | long userTimeout = getLockTimeout(profileId); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 978 | if (userTimeout == 0) { |
| 979 | doKeyguardForChildProfilesLocked(); |
| 980 | } else { |
| 981 | long userWhen = SystemClock.elapsedRealtime() + userTimeout; |
| 982 | Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION); |
| 983 | lockIntent.putExtra("seq", mDelayedProfileShowingSequence); |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 984 | lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId); |
Jorim Jaggi | ad0ce3a | 2016-04-27 13:15:41 -0700 | [diff] [blame] | 985 | lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 986 | PendingIntent lockSender = PendingIntent.getBroadcast( |
| 987 | mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT); |
| 988 | mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 989 | userWhen, lockSender); |
| 990 | } |
Clara Bayarri | 3dc575f | 2016-02-17 15:17:14 +0000 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | private void doKeyguardForChildProfilesLocked() { |
| 996 | UserManager um = UserManager.get(mContext); |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 997 | for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { |
| 998 | if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { |
| 999 | lockProfile(profileId); |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 1000 | } |
| 1001 | } |
Jorim Jaggi | 5c0c5ac8 | 2015-09-16 14:53:48 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1004 | private void cancelDoKeyguardLaterLocked() { |
| 1005 | mDelayedShowingSequence++; |
| 1006 | } |
| 1007 | |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 1008 | private void cancelDoKeyguardForChildProfilesLocked() { |
| 1009 | mDelayedProfileShowingSequence++; |
| 1010 | } |
| 1011 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1012 | /** |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1013 | * Let's us know when the device is waking up. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1014 | */ |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1015 | public void onStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1016 | Trace.beginSection("KeyguardViewMediator#onStartedWakingUp"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1017 | |
| 1018 | // TODO: Rename all screen off/on references to interactive/sleeping |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1019 | synchronized (this) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1020 | mDeviceInteractive = true; |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1021 | cancelDoKeyguardLaterLocked(); |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 1022 | cancelDoKeyguardForChildProfilesLocked(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1023 | if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1024 | notifyStartedWakingUp(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1025 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1026 | KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp(); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1027 | maybeSendUserPresentBroadcast(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1028 | Trace.endSection(); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1031 | public void onScreenTurningOn(IKeyguardDrawnCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1032 | Trace.beginSection("KeyguardViewMediator#onScreenTurningOn"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1033 | notifyScreenOn(callback); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1034 | Trace.endSection(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | public void onScreenTurnedOn() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1038 | Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1039 | notifyScreenTurnedOn(); |
| 1040 | mUpdateMonitor.dispatchScreenTurnedOn(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1041 | Trace.endSection(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | public void onScreenTurnedOff() { |
| 1045 | notifyScreenTurnedOff(); |
| 1046 | mUpdateMonitor.dispatchScreenTurnedOff(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1049 | private void maybeSendUserPresentBroadcast() { |
Adrian Roos | 8150d2a | 2015-04-16 17:11:20 -0700 | [diff] [blame] | 1050 | if (mSystemReady && mLockPatternUtils.isLockScreenDisabled( |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 1051 | KeyguardUpdateMonitor.getCurrentUser())) { |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1052 | // Lock screen is disabled because the user has set the preference to "None". |
| 1053 | // In this case, send out ACTION_USER_PRESENT here instead of in |
| 1054 | // handleKeyguardDone() |
| 1055 | sendUserPresentBroadcast(); |
Adrian Roos | fb95a81 | 2016-06-20 14:58:59 -0700 | [diff] [blame] | 1056 | } else if (mSystemReady && shouldWaitForProvisioning()) { |
| 1057 | // Skipping the lockscreen because we're not yet provisioned, but we still need to |
| 1058 | // notify the StrongAuthTracker that it's now safe to run trust agents, in case the |
| 1059 | // user sets a credential later. |
| 1060 | getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1061 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /** |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1065 | * A dream started. We should lock after the usual screen-off lock timeout but only |
| 1066 | * if there is a secure lock pattern. |
| 1067 | */ |
| 1068 | public void onDreamingStarted() { |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1069 | KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1070 | synchronized (this) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1071 | if (mDeviceInteractive |
| 1072 | && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) { |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1073 | doKeyguardLaterLocked(); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * A dream stopped. |
| 1080 | */ |
| 1081 | public void onDreamingStopped() { |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1082 | KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1083 | synchronized (this) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 1084 | if (mDeviceInteractive) { |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1085 | cancelDoKeyguardLaterLocked(); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | /** |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 1091 | * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1092 | * a way for external stuff to override normal keyguard behavior. For instance |
| 1093 | * the phone app disables the keyguard when it receives incoming calls. |
| 1094 | */ |
| 1095 | public void setKeyguardEnabled(boolean enabled) { |
| 1096 | synchronized (this) { |
| 1097 | if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")"); |
| 1098 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1099 | mExternallyEnabled = enabled; |
| 1100 | |
| 1101 | if (!enabled && mShowing) { |
| 1102 | if (mExitSecureCallback != null) { |
| 1103 | if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring"); |
| 1104 | // we're in the process of handling a request to verify the user |
| 1105 | // can get past the keyguard. ignore extraneous requests to disable / reenable |
| 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | // hiding keyguard that is showing, remember to reshow later |
| 1110 | if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, " |
| 1111 | + "disabling status bar expansion"); |
| 1112 | mNeedToReshowWhenReenabled = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1113 | updateInputRestrictedLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1114 | hideLocked(); |
| 1115 | } else if (enabled && mNeedToReshowWhenReenabled) { |
| 1116 | // reenabled after previously hidden, reshow |
| 1117 | if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling " |
| 1118 | + "status bar expansion"); |
| 1119 | mNeedToReshowWhenReenabled = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1120 | updateInputRestrictedLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1121 | |
| 1122 | if (mExitSecureCallback != null) { |
| 1123 | if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1124 | try { |
| 1125 | mExitSecureCallback.onKeyguardExitResult(false); |
| 1126 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1127 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1128 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1129 | mExitSecureCallback = null; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1130 | resetStateLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1131 | } else { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1132 | showLocked(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1133 | |
| 1134 | // block until we know the keygaurd is done drawing (and post a message |
| 1135 | // to unblock us after a timeout so we don't risk blocking too long |
| 1136 | // and causing an ANR). |
| 1137 | mWaitingUntilKeyguardVisible = true; |
| 1138 | mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS); |
| 1139 | if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false"); |
| 1140 | while (mWaitingUntilKeyguardVisible) { |
| 1141 | try { |
| 1142 | wait(); |
| 1143 | } catch (InterruptedException e) { |
| 1144 | Thread.currentThread().interrupt(); |
| 1145 | } |
| 1146 | } |
| 1147 | if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible"); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | /** |
| 1154 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 1155 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1156 | public void verifyUnlock(IKeyguardExitCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1157 | Trace.beginSection("KeyguardViewMediator#verifyUnlock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1158 | synchronized (this) { |
| 1159 | if (DEBUG) Log.d(TAG, "verifyUnlock"); |
Jim Miller | b256e4e2 | 2014-10-31 17:27:13 -0700 | [diff] [blame] | 1160 | if (shouldWaitForProvisioning()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1161 | // don't allow this api when the device isn't provisioned |
| 1162 | if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1163 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1164 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1165 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1166 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1167 | } |
Mike Lockwood | 5d258b6 | 2009-12-02 13:50:45 -0500 | [diff] [blame] | 1168 | } else if (mExternallyEnabled) { |
| 1169 | // this only applies when the user has externally disabled the |
| 1170 | // keyguard. this is unexpected and means the user is not |
| 1171 | // using the api properly. |
| 1172 | Log.w(TAG, "verifyUnlock called when not externally disabled"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1173 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1174 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1175 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1176 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1177 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1178 | } else if (mExitSecureCallback != null) { |
| 1179 | // already in progress with someone else |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1180 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1181 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1182 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1183 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1184 | } |
Jorim Jaggi | 302475e | 2015-09-22 12:44:47 -0700 | [diff] [blame] | 1185 | } else if (!isSecure()) { |
| 1186 | |
| 1187 | // Keyguard is not secure, no need to do anything, and we don't need to reshow |
| 1188 | // the Keyguard after the client releases the Keyguard lock. |
| 1189 | mExternallyEnabled = true; |
| 1190 | mNeedToReshowWhenReenabled = false; |
| 1191 | updateInputRestricted(); |
| 1192 | try { |
| 1193 | callback.onKeyguardExitResult(true); |
| 1194 | } catch (RemoteException e) { |
| 1195 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
| 1196 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1197 | } else { |
Jorim Jaggi | 302475e | 2015-09-22 12:44:47 -0700 | [diff] [blame] | 1198 | |
| 1199 | // Since we prevent apps from hiding the Keyguard if we are secure, this should be |
| 1200 | // a no-op as well. |
| 1201 | try { |
| 1202 | callback.onKeyguardExitResult(false); |
| 1203 | } catch (RemoteException e) { |
| 1204 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
| 1205 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1208 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1209 | } |
| 1210 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1211 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1212 | * Is the keyguard currently showing and not being force hidden? |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 1213 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1214 | public boolean isShowingAndNotOccluded() { |
| 1215 | return mShowing && !mOccluded; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Notify us when the keyguard is occluded by another window |
| 1220 | */ |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1221 | public void setOccluded(boolean isOccluded, boolean animate) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1222 | Trace.beginSection("KeyguardViewMediator#setOccluded"); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1223 | if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1224 | mHandler.removeMessages(SET_OCCLUDED); |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1225 | Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1226 | mHandler.sendMessage(msg); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1227 | Trace.endSection(); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1228 | } |
| 1229 | |
Lucas Dupin | 2986c15 | 2018-04-09 20:49:41 -0700 | [diff] [blame] | 1230 | public boolean isHiding() { |
| 1231 | return mHiding; |
| 1232 | } |
| 1233 | |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1234 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1235 | * Handles SET_OCCLUDED message sent by setOccluded() |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1236 | */ |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1237 | private void handleSetOccluded(boolean isOccluded, boolean animate) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1238 | Trace.beginSection("KeyguardViewMediator#handleSetOccluded"); |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 1239 | synchronized (KeyguardViewMediator.this) { |
Adrian Roos | f253eeb | 2015-04-15 18:03:08 -0700 | [diff] [blame] | 1240 | if (mHiding && isOccluded) { |
| 1241 | // We're in the process of going away but WindowManager wants to show a |
| 1242 | // SHOW_WHEN_LOCKED activity instead. |
| 1243 | startKeyguardExitAnimation(0, 0); |
| 1244 | } |
| 1245 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1246 | if (mOccluded != isOccluded) { |
| 1247 | mOccluded = isOccluded; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1248 | mUpdateMonitor.setKeyguardOccluded(isOccluded); |
Selim Cinek | 2f6272e | 2017-03-15 16:19:10 -0700 | [diff] [blame] | 1249 | mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate |
| 1250 | && mDeviceInteractive); |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1251 | adjustStatusBarLocked(); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1252 | } |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 1253 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1254 | Trace.endSection(); |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /** |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1258 | * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. |
| 1259 | * This must be safe to call from any thread and with any window manager locks held. |
| 1260 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1261 | public void doKeyguardTimeout(Bundle options) { |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1262 | mHandler.removeMessages(KEYGUARD_TIMEOUT); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1263 | Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1264 | mHandler.sendMessage(msg); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1268 | * Given the state of the keyguard, is the input restricted? |
| 1269 | * Input is restricted when the keyguard is showing, or when the keyguard |
| 1270 | * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. |
| 1271 | */ |
| 1272 | public boolean isInputRestricted() { |
Adrian Roos | 9f33d6c | 2015-06-15 15:58:35 -0700 | [diff] [blame] | 1273 | return mShowing || mNeedToReshowWhenReenabled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1276 | private void updateInputRestricted() { |
| 1277 | synchronized (this) { |
| 1278 | updateInputRestrictedLocked(); |
| 1279 | } |
| 1280 | } |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1281 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1282 | private void updateInputRestrictedLocked() { |
| 1283 | boolean inputRestricted = isInputRestricted(); |
| 1284 | if (mInputRestricted != inputRestricted) { |
| 1285 | mInputRestricted = inputRestricted; |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 1286 | int size = mKeyguardStateCallbacks.size(); |
| 1287 | for (int i = size - 1; i >= 0; i--) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1288 | final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i); |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 1289 | try { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1290 | callback.onInputRestrictedStateChanged(inputRestricted); |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 1291 | } catch (RemoteException e) { |
| 1292 | Slog.w(TAG, "Failed to call onDeviceProvisioned", e); |
| 1293 | if (e instanceof DeadObjectException) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1294 | mKeyguardStateCallbacks.remove(callback); |
dooyoung.hwang | 328472e | 2015-05-21 16:09:43 +0900 | [diff] [blame] | 1295 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1296 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1301 | /** |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1302 | * Enable the keyguard if the settings are appropriate. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1303 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1304 | private void doKeyguardLocked(Bundle options) { |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 1305 | if (KeyguardUpdateMonitor.CORE_APPS_ONLY) { |
| 1306 | // Don't show keyguard during half-booted cryptkeeper stage. |
| 1307 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper"); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1311 | // if another app is disabling us, don't show |
| 1312 | if (!mExternallyEnabled) { |
| 1313 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled"); |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 1314 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1315 | // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes |
| 1316 | // for an occasional ugly flicker in this situation: |
| 1317 | // 1) receive a call with the screen on (no keyguard) or make a call |
| 1318 | // 2) screen times out |
| 1319 | // 3) user hits key to turn screen back on |
| 1320 | // instead, we reenable the keyguard when we know the screen is off and the call |
| 1321 | // ends (see the broadcast receiver below) |
| 1322 | // TODO: clean this up when we have better support at the window manager level |
| 1323 | // for apps that wish to be on top of the keyguard |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 1324 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1325 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1326 | |
| 1327 | // if the keyguard is already showing, don't bother |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1328 | if (mStatusBarKeyguardViewManager.isShowing()) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1329 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing"); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 1330 | resetStateLocked(); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 1331 | return; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1334 | // In split system user mode, we never unlock system user. |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 1335 | if (!mustNotUnlockCurrentUser() |
Amith Yamasani | 27e025b | 2015-11-06 10:34:41 -0800 | [diff] [blame] | 1336 | || !mUpdateMonitor.isDeviceProvisioned()) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1337 | |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1338 | // if the setup wizard hasn't run yet, don't show |
| 1339 | final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false); |
| 1340 | final boolean absent = SubscriptionManager.isValidSubscriptionId( |
Adrian Roos | e92de95 | 2016-12-13 12:07:09 -0800 | [diff] [blame] | 1341 | mUpdateMonitor.getNextSubIdForState(ABSENT)); |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1342 | final boolean disabled = SubscriptionManager.isValidSubscriptionId( |
| 1343 | mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED)); |
| 1344 | final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure() |
| 1345 | || ((absent || disabled) && requireSim); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1346 | |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1347 | if (!lockedOrMissing && shouldWaitForProvisioning()) { |
| 1348 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned" |
| 1349 | + " and the sim is not locked or missing"); |
| 1350 | return; |
| 1351 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1352 | |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1353 | boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false); |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1354 | if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser()) |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1355 | && !lockedOrMissing && !forceShow) { |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1356 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); |
| 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) { |
| 1361 | if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted"); |
| 1362 | // Without this, settings is not enabled until the lock screen first appears |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1363 | setShowingLocked(false, mAodShowing); |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1364 | hideLocked(); |
| 1365 | return; |
| 1366 | } |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1369 | if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1370 | showLocked(options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 1373 | private void lockProfile(int userId) { |
| 1374 | mTrustManager.setDeviceLockedForUser(userId, true); |
| 1375 | } |
| 1376 | |
Jim Miller | b256e4e2 | 2014-10-31 17:27:13 -0700 | [diff] [blame] | 1377 | private boolean shouldWaitForProvisioning() { |
| 1378 | return !mUpdateMonitor.isDeviceProvisioned() && !isSecure(); |
| 1379 | } |
| 1380 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1381 | /** |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1382 | * Dismiss the keyguard through the security layers. |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1383 | * @param callback Callback to be informed about the result |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 1384 | * @param message Message that should be displayed on the bouncer. |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1385 | */ |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 1386 | private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1387 | if (mShowing) { |
| 1388 | if (callback != null) { |
| 1389 | mDismissCallbackRegistry.addCallback(callback); |
| 1390 | } |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 1391 | mCustomMessage = message; |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1392 | mStatusBarKeyguardViewManager.dismissAndCollapse(); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1393 | } else if (callback != null) { |
| 1394 | new DismissCallbackWrapper(callback).notifyDismissError(); |
Jim Miller | 87d0366 | 2012-11-05 20:28:09 -0800 | [diff] [blame] | 1395 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 1398 | public void dismiss(IKeyguardDismissCallback callback, CharSequence message) { |
| 1399 | mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1402 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1403 | * Send message to keyguard telling it to reset its state. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1404 | * @see #handleReset |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1405 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1406 | private void resetStateLocked() { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1407 | if (DEBUG) Log.e(TAG, "resetStateLocked"); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1408 | Message msg = mHandler.obtainMessage(RESET); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1409 | mHandler.sendMessage(msg); |
| 1410 | } |
| 1411 | |
| 1412 | /** |
| 1413 | * Send message to keyguard telling it to verify unlock |
| 1414 | * @see #handleVerifyUnlock() |
| 1415 | */ |
| 1416 | private void verifyUnlockLocked() { |
| 1417 | if (DEBUG) Log.d(TAG, "verifyUnlockLocked"); |
| 1418 | mHandler.sendEmptyMessage(VERIFY_UNLOCK); |
| 1419 | } |
| 1420 | |
Jorim Jaggi | 18f18ae | 2015-09-10 15:48:21 -0700 | [diff] [blame] | 1421 | private void notifyStartedGoingToSleep() { |
| 1422 | if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep"); |
| 1423 | mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP); |
| 1424 | } |
| 1425 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1426 | private void notifyFinishedGoingToSleep() { |
| 1427 | if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep"); |
| 1428 | mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1429 | } |
| 1430 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1431 | private void notifyStartedWakingUp() { |
| 1432 | if (DEBUG) Log.d(TAG, "notifyStartedWakingUp"); |
| 1433 | mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP); |
| 1434 | } |
| 1435 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1436 | private void notifyScreenOn(IKeyguardDrawnCallback callback) { |
| 1437 | if (DEBUG) Log.d(TAG, "notifyScreenOn"); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1438 | Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 1439 | mHandler.sendMessage(msg); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1442 | private void notifyScreenTurnedOn() { |
| 1443 | if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn"); |
| 1444 | Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON); |
| 1445 | mHandler.sendMessage(msg); |
| 1446 | } |
| 1447 | |
| 1448 | private void notifyScreenTurnedOff() { |
| 1449 | if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff"); |
| 1450 | Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF); |
| 1451 | mHandler.sendMessage(msg); |
| 1452 | } |
| 1453 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1454 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1455 | * Send message to keyguard telling it to show itself |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1456 | * @see #handleShow |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1457 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1458 | private void showLocked(Bundle options) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1459 | Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1460 | if (DEBUG) Log.d(TAG, "showLocked"); |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 1461 | // ensure we stay awake until we are finished displaying the keyguard |
| 1462 | mShowKeyguardWakeLock.acquire(); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1463 | Message msg = mHandler.obtainMessage(SHOW, options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1464 | mHandler.sendMessage(msg); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1465 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Send message to keyguard telling it to hide itself |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1470 | * @see #handleHide() |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1471 | */ |
| 1472 | private void hideLocked() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1473 | Trace.beginSection("KeyguardViewMediator#hideLocked"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1474 | if (DEBUG) Log.d(TAG, "hideLocked"); |
| 1475 | Message msg = mHandler.obtainMessage(HIDE); |
| 1476 | mHandler.sendMessage(msg); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1477 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1480 | public boolean isSecure() { |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1481 | return isSecure(KeyguardUpdateMonitor.getCurrentUser()); |
| 1482 | } |
| 1483 | |
| 1484 | public boolean isSecure(int userId) { |
| 1485 | return mLockPatternUtils.isSecure(userId) |
| 1486 | || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure(); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1487 | } |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1488 | |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1489 | public void setSwitchingUser(boolean switching) { |
Selim Cinek | bbe1924 | 2017-12-08 15:42:08 -0800 | [diff] [blame] | 1490 | KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching); |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1493 | /** |
| 1494 | * Update the newUserId. Call while holding WindowManagerService lock. |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 1495 | * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing. |
| 1496 | * |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1497 | * @param newUserId The id of the incoming user. |
| 1498 | */ |
| 1499 | public void setCurrentUser(int newUserId) { |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 1500 | KeyguardUpdateMonitor.setCurrentUser(newUserId); |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 1501 | synchronized (this) { |
| 1502 | notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId)); |
| 1503 | } |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Kevin Chyn | 18e91aa | 2018-04-11 12:55:45 -0700 | [diff] [blame] | 1506 | /** |
| 1507 | * This broadcast receiver should be registered with the SystemUI permission. |
| 1508 | */ |
| 1509 | private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1510 | @Override |
| 1511 | public void onReceive(Context context, Intent intent) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1512 | if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) { |
| 1513 | final int sequence = intent.getIntExtra("seq", 0); |
Jim Miller | f344735 | 2011-08-07 14:00:09 -0700 | [diff] [blame] | 1514 | if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = " |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1515 | + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1516 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 1517 | if (mDelayedShowingSequence == sequence) { |
| 1518 | doKeyguardLocked(null); |
| 1519 | } |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 1520 | } |
| 1521 | } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) { |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 1522 | final int sequence = intent.getIntExtra("seq", 0); |
Clara Bayarri | 56878a9 | 2015-10-29 15:43:55 +0000 | [diff] [blame] | 1523 | int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0); |
| 1524 | if (userId != 0) { |
| 1525 | synchronized (KeyguardViewMediator.this) { |
Tony Mak | 9c6e8ce | 2016-03-21 12:07:16 +0000 | [diff] [blame] | 1526 | if (mDelayedProfileShowingSequence == sequence) { |
| 1527 | lockProfile(userId); |
| 1528 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1529 | } |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 1530 | } |
Kevin Chyn | 18e91aa | 2018-04-11 12:55:45 -0700 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | }; |
| 1534 | |
| 1535 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1536 | @Override |
| 1537 | public void onReceive(Context context, Intent intent) { |
| 1538 | if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) { |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 1539 | synchronized (KeyguardViewMediator.this){ |
| 1540 | mShuttingDown = true; |
| 1541 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | }; |
| 1545 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1546 | public void keyguardDone() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1547 | Trace.beginSection("KeyguardViewMediator#keyguardDone"); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1548 | if (DEBUG) Log.d(TAG, "keyguardDone()"); |
Jorim Jaggi | b9d0491 | 2016-08-04 17:28:08 +0200 | [diff] [blame] | 1549 | userActivity(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1550 | EventLog.writeEvent(70000, 2); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1551 | Message msg = mHandler.obtainMessage(KEYGUARD_DONE); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1552 | mHandler.sendMessage(msg); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1553 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1557 | * This handler will be associated with the policy thread, which will also |
| 1558 | * be the UI thread of the keyguard. Since the apis of the policy, and therefore |
| 1559 | * this class, can be called by other threads, any action that directly |
| 1560 | * interacts with the keyguard ui should be posted to this handler, rather |
| 1561 | * than called directly. |
| 1562 | */ |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1563 | private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1564 | @Override |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 1565 | public void handleMessage(Message msg) { |
| 1566 | switch (msg.what) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1567 | case SHOW: |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1568 | handleShow((Bundle) msg.obj); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1569 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1570 | case HIDE: |
| 1571 | handleHide(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1572 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1573 | case RESET: |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1574 | handleReset(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1575 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1576 | case VERIFY_UNLOCK: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1577 | Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1578 | handleVerifyUnlock(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1579 | Trace.endSection(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1580 | break; |
Jorim Jaggi | 18f18ae | 2015-09-10 15:48:21 -0700 | [diff] [blame] | 1581 | case NOTIFY_STARTED_GOING_TO_SLEEP: |
| 1582 | handleNotifyStartedGoingToSleep(); |
| 1583 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1584 | case NOTIFY_FINISHED_GOING_TO_SLEEP: |
| 1585 | handleNotifyFinishedGoingToSleep(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1586 | break; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1587 | case NOTIFY_SCREEN_TURNING_ON: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1588 | Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON"); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1589 | handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1590 | Trace.endSection(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1591 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1592 | case NOTIFY_SCREEN_TURNED_ON: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1593 | Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1594 | handleNotifyScreenTurnedOn(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1595 | Trace.endSection(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | case NOTIFY_SCREEN_TURNED_OFF: |
| 1598 | handleNotifyScreenTurnedOff(); |
| 1599 | break; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1600 | case NOTIFY_STARTED_WAKING_UP: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1601 | Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP"); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1602 | handleNotifyStartedWakingUp(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1603 | Trace.endSection(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1604 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1605 | case KEYGUARD_DONE: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1606 | Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE"); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1607 | handleKeyguardDone(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1608 | Trace.endSection(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1609 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1610 | case KEYGUARD_DONE_DRAWING: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1611 | Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1612 | handleKeyguardDoneDrawing(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1613 | Trace.endSection(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1614 | break; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1615 | case SET_OCCLUDED: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1616 | Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED"); |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1617 | handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1618 | Trace.endSection(); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1619 | break; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1620 | case KEYGUARD_TIMEOUT: |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1621 | synchronized (KeyguardViewMediator.this) { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1622 | doKeyguardLocked((Bundle) msg.obj); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1623 | } |
| 1624 | break; |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1625 | case DISMISS: |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 1626 | final DismissMessage message = (DismissMessage) msg.obj; |
| 1627 | handleDismiss(message.getCallback(), message.getMessage()); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1628 | break; |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1629 | case START_KEYGUARD_EXIT_ANIM: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1630 | Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 1631 | StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj; |
| 1632 | handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1633 | FalsingManager.getInstance(mContext).onSucccessfulUnlock(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1634 | Trace.endSection(); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1635 | break; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1636 | case KEYGUARD_DONE_PENDING_TIMEOUT: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1637 | Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT"); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1638 | Log.w(TAG, "Timeout while waiting for activity drawn!"); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1639 | Trace.endSection(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1640 | break; |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 1641 | case SYSTEM_READY: |
| 1642 | handleSystemReady(); |
| 1643 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | }; |
| 1647 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1648 | private void tryKeyguardDone() { |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1649 | if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1650 | handleKeyguardDone(); |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1651 | } else if (!mHideAnimationRun) { |
| 1652 | mHideAnimationRun = true; |
| 1653 | mHideAnimationRunning = true; |
| 1654 | mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); |
| 1655 | } |
| 1656 | } |
| 1657 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1658 | /** |
| 1659 | * @see #keyguardDone |
| 1660 | * @see #KEYGUARD_DONE |
| 1661 | */ |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1662 | private void handleKeyguardDone() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1663 | Trace.beginSection("KeyguardViewMediator#handleKeyguardDone"); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 1664 | final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1665 | mUiOffloadThread.submit(() -> { |
| 1666 | if (mLockPatternUtils.isSecure(currentUser)) { |
| 1667 | mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser); |
| 1668 | } |
| 1669 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1670 | if (DEBUG) Log.d(TAG, "handleKeyguardDone"); |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1671 | synchronized (this) { |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1672 | resetKeyguardDonePendingLocked(); |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1673 | } |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1674 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1675 | mUpdateMonitor.clearFingerprintRecognized(); |
Jeff Sharkey | 6a25cbd | 2012-08-23 12:14:26 -0700 | [diff] [blame] | 1676 | |
Jorim Jaggi | 4474f54 | 2015-07-09 16:08:02 -0700 | [diff] [blame] | 1677 | if (mGoingToSleep) { |
| 1678 | Log.i(TAG, "Device is going to sleep, aborting keyguardDone"); |
| 1679 | return; |
| 1680 | } |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1681 | if (mExitSecureCallback != null) { |
| 1682 | try { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1683 | mExitSecureCallback.onKeyguardExitResult(true /* authenciated */); |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1684 | } catch (RemoteException e) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1685 | Slog.w(TAG, "Failed to call onKeyguardExitResult()", e); |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | mExitSecureCallback = null; |
| 1689 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1690 | // after succesfully exiting securely, no need to reshow |
| 1691 | // the keyguard when they've released the lock |
| 1692 | mExternallyEnabled = true; |
| 1693 | mNeedToReshowWhenReenabled = false; |
| 1694 | updateInputRestricted(); |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | handleHide(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1698 | Trace.endSection(); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | private void sendUserPresentBroadcast() { |
Jason Monk | cf5a953 | 2014-09-17 16:22:19 -0400 | [diff] [blame] | 1702 | synchronized (this) { |
| 1703 | if (mBootCompleted) { |
Adrian Roos | 4ab7e59 | 2016-04-13 15:38:13 -0700 | [diff] [blame] | 1704 | int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); |
| 1705 | final UserHandle currentUser = new UserHandle(currentUserId); |
Benjamin Franz | 4b9f8ed | 2014-12-01 16:51:48 +0000 | [diff] [blame] | 1706 | final UserManager um = (UserManager) mContext.getSystemService( |
| 1707 | Context.USER_SERVICE); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1708 | mUiOffloadThread.submit(() -> { |
| 1709 | for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) { |
| 1710 | mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId)); |
| 1711 | } |
| 1712 | getLockPatternUtils().userPresent(currentUserId); |
| 1713 | }); |
Jason Monk | cf5a953 | 2014-09-17 16:22:19 -0400 | [diff] [blame] | 1714 | } else { |
| 1715 | mBootSendUserPresent = true; |
| 1716 | } |
| 1717 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1721 | * @see #keyguardDone |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1722 | * @see #KEYGUARD_DONE_DRAWING |
| 1723 | */ |
| 1724 | private void handleKeyguardDoneDrawing() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1725 | Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1726 | synchronized(this) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1727 | if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1728 | if (mWaitingUntilKeyguardVisible) { |
| 1729 | if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible"); |
| 1730 | mWaitingUntilKeyguardVisible = false; |
| 1731 | notifyAll(); |
| 1732 | |
| 1733 | // there will usually be two of these sent, one as a timeout, and one |
| 1734 | // as a result of the callback, so remove any remaining messages from |
| 1735 | // the queue |
| 1736 | mHandler.removeMessages(KEYGUARD_DONE_DRAWING); |
| 1737 | } |
| 1738 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1739 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1742 | private void playSounds(boolean locked) { |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 1743 | playSound(locked ? mLockSoundId : mUnlockSoundId); |
| 1744 | } |
| 1745 | |
| 1746 | private void playSound(int soundId) { |
| 1747 | if (soundId == 0) return; |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1748 | final ContentResolver cr = mContext.getContentResolver(); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1749 | if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 1750 | |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 1751 | mLockSounds.stop(mLockSoundStreamId); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1752 | // Init mAudioManager |
| 1753 | if (mAudioManager == null) { |
| 1754 | mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1755 | if (mAudioManager == null) return; |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 1756 | mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType(); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1757 | } |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1758 | |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1759 | mUiOffloadThread.submit(() -> { |
| 1760 | // If the stream is muted, don't play the sound |
| 1761 | if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return; |
| 1762 | |
| 1763 | int id = mLockSounds.play(soundId, |
| 1764 | mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/); |
| 1765 | synchronized (this) { |
| 1766 | mLockSoundStreamId = id; |
| 1767 | } |
| 1768 | }); |
| 1769 | |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1770 | } |
Jim Miller | 2a98a4c | 2010-11-19 18:49:26 -0800 | [diff] [blame] | 1771 | } |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1772 | |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 1773 | private void playTrustedSound() { |
Adrian Roos | 49e057d | 2014-08-13 17:14:51 +0200 | [diff] [blame] | 1774 | playSound(mTrustedSoundId); |
| 1775 | } |
| 1776 | |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1777 | private void updateActivityLockScreenState(boolean showing, boolean aodShowing, |
| 1778 | int secondaryDisplayShowing) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1779 | mUiOffloadThread.submit(() -> { |
| 1780 | try { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1781 | ActivityManager.getService().setLockScreenShown(showing, aodShowing, |
| 1782 | secondaryDisplayShowing); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 1783 | } catch (RemoteException e) { |
| 1784 | } |
| 1785 | }); |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1788 | /** |
| 1789 | * Handle message sent by {@link #showLocked}. |
| 1790 | * @see #SHOW |
| 1791 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1792 | private void handleShow(Bundle options) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1793 | Trace.beginSection("KeyguardViewMediator#handleShow"); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 1794 | final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); |
| 1795 | if (mLockPatternUtils.isSecure(currentUser)) { |
| 1796 | mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser); |
Michal Karpinski | 779aad9 | 2016-01-20 11:56:22 +0000 | [diff] [blame] | 1797 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1798 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1799 | if (!mSystemReady) { |
| 1800 | if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready."); |
| 1801 | return; |
| 1802 | } else { |
| 1803 | if (DEBUG) Log.d(TAG, "handleShow"); |
| 1804 | } |
Jim Miller | 9c20d0e | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1805 | |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1806 | setShowingLocked(true, mAodShowing); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1807 | mStatusBarKeyguardViewManager.show(options); |
Jorim Jaggi | 53c68a4 | 2014-06-17 15:04:47 -0700 | [diff] [blame] | 1808 | mHiding = false; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1809 | mWakeAndUnlocking = false; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1810 | resetKeyguardDonePendingLocked(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1811 | mHideAnimationRun = false; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1812 | adjustStatusBarLocked(); |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 1813 | userActivity(); |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 1814 | mShowKeyguardWakeLock.release(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1815 | } |
Jim Miller | 3192148 | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 1816 | mKeyguardDisplayManager.show(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1817 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1820 | private final Runnable mKeyguardGoingAwayRunnable = new Runnable() { |
| 1821 | @Override |
| 1822 | public void run() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1823 | Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable"); |
Jorim Jaggi | b9d0491 | 2016-08-04 17:28:08 +0200 | [diff] [blame] | 1824 | if (DEBUG) Log.d(TAG, "keyguardGoingAway"); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1825 | try { |
Jorim Jaggi | 33ae80e | 2015-02-04 16:37:11 +0100 | [diff] [blame] | 1826 | mStatusBarKeyguardViewManager.keyguardGoingAway(); |
| 1827 | |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 1828 | int flags = 0; |
| 1829 | if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock() |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 1830 | || (mWakeAndUnlocking && !mPulsing)) { |
| 1831 | flags |= WindowManagerPolicyConstants |
| 1832 | .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS; |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 1833 | } |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 1834 | if (mStatusBarKeyguardViewManager.isGoingToNotificationShade() |
| 1835 | || (mWakeAndUnlocking && mPulsing)) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 1836 | flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 1837 | } |
| 1838 | if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 1839 | flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; |
Adrian Roos | d5c2db6 | 2016-03-08 16:11:31 -0800 | [diff] [blame] | 1840 | } |
| 1841 | |
Kevin Chyn | 6db7d5f | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 1842 | mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1843 | // Don't actually hide the Keyguard at the moment, wait for window |
| 1844 | // manager until it tells us it's safe to do so with |
| 1845 | // startKeyguardExitAnimation. |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1846 | ActivityManager.getService().keyguardGoingAway(flags); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1847 | } catch (RemoteException e) { |
| 1848 | Log.e(TAG, "Error while calling WindowManager", e); |
| 1849 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1850 | Trace.endSection(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1851 | } |
| 1852 | }; |
| 1853 | |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1854 | private final Runnable mHideAnimationFinishedRunnable = () -> { |
| 1855 | mHideAnimationRunning = false; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1856 | tryKeyguardDone(); |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1857 | }; |
| 1858 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1859 | /** |
| 1860 | * Handle message sent by {@link #hideLocked()} |
| 1861 | * @see #HIDE |
| 1862 | */ |
| 1863 | private void handleHide() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1864 | Trace.beginSection("KeyguardViewMediator#handleHide"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1865 | synchronized (KeyguardViewMediator.this) { |
| 1866 | if (DEBUG) Log.d(TAG, "handleHide"); |
Jorim Jaggi | b9d6079 | 2014-06-03 22:34:22 +0200 | [diff] [blame] | 1867 | |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 1868 | if (mustNotUnlockCurrentUser()) { |
Xiaohui Chen | f561d7f | 2015-07-09 16:35:00 -0700 | [diff] [blame] | 1869 | // In split system user mode, we never unlock system user. The end user has to |
| 1870 | // switch to another user. |
| 1871 | // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up |
| 1872 | // still completes and makes the screen blank. |
| 1873 | if (DEBUG) Log.d(TAG, "Split system user, quit unlocking."); |
| 1874 | return; |
| 1875 | } |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 1876 | mHiding = true; |
Jorim Jaggi | b9d6079 | 2014-06-03 22:34:22 +0200 | [diff] [blame] | 1877 | |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1878 | if (mShowing && !mOccluded) { |
| 1879 | mKeyguardGoingAwayRunnable.run(); |
| 1880 | } else { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 1881 | handleStartKeyguardExitAnimation( |
| 1882 | SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(), |
| 1883 | mHideAnimation.getDuration()); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1884 | } |
| 1885 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1886 | Trace.endSection(); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 1889 | private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1890 | Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation"); |
Jorim Jaggi | b9d0491 | 2016-08-04 17:28:08 +0200 | [diff] [blame] | 1891 | if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime |
| 1892 | + " fadeoutDuration=" + fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1893 | synchronized (KeyguardViewMediator.this) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1894 | |
Jorim Jaggi | 53c68a4 | 2014-06-17 15:04:47 -0700 | [diff] [blame] | 1895 | if (!mHiding) { |
Adrian Roos | 6ec76b7 | 2018-04-25 14:01:11 +0200 | [diff] [blame] | 1896 | // Tell ActivityManager that we canceled the keyguardExitAnimation. |
| 1897 | setShowingLocked(mShowing, mAodShowing, mSecondaryDisplayShowing, true /* force */); |
Jorim Jaggi | 53c68a4 | 2014-06-17 15:04:47 -0700 | [diff] [blame] | 1898 | return; |
| 1899 | } |
| 1900 | mHiding = false; |
| 1901 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 1902 | if (mWakeAndUnlocking && mDrawnCallback != null) { |
| 1903 | |
| 1904 | // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report |
| 1905 | // the next draw from here so we don't have to wait for window manager to signal |
| 1906 | // this to our ViewRootImpl. |
| 1907 | mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw(); |
| 1908 | notifyDrawn(mDrawnCallback); |
Jorim Jaggi | e93e6f9 | 2016-08-04 13:55:39 +0200 | [diff] [blame] | 1909 | mDrawnCallback = null; |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 1912 | // only play "unlock" noises if not on a call (since the incall UI |
| 1913 | // disables the keyguard) |
| 1914 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) { |
| 1915 | playSounds(false); |
| 1916 | } |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1917 | |
Jorim Jaggi | e93e6f9 | 2016-08-04 13:55:39 +0200 | [diff] [blame] | 1918 | mWakeAndUnlocking = false; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1919 | setShowingLocked(false, mAodShowing); |
Jorim Jaggi | 5277dea | 2017-05-18 02:05:29 +0200 | [diff] [blame] | 1920 | mDismissCallbackRegistry.notifyDismissSucceeded(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 1921 | mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1922 | resetKeyguardDonePendingLocked(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1923 | mHideAnimationRun = false; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1924 | adjustStatusBarLocked(); |
Jim Miller | 705004b | 2014-09-04 16:51:20 -0700 | [diff] [blame] | 1925 | sendUserPresentBroadcast(); |
Kevin Chyn | 6db7d5f | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 1926 | mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1927 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1928 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1931 | private void adjustStatusBarLocked() { |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 1932 | adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */); |
| 1933 | } |
| 1934 | |
| 1935 | private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) { |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1936 | if (mStatusBarManager == null) { |
| 1937 | mStatusBarManager = (StatusBarManager) |
| 1938 | mContext.getSystemService(Context.STATUS_BAR_SERVICE); |
| 1939 | } |
| 1940 | if (mStatusBarManager == null) { |
| 1941 | Log.w(TAG, "Could not get status bar manager"); |
| 1942 | } else { |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1943 | // Disable aspects of the system/status/navigation bars that must not be re-enabled by |
| 1944 | // windows that appear on top, ever |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1945 | int flags = StatusBarManager.DISABLE_NONE; |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 1946 | if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) { |
| 1947 | flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT; |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 1948 | } |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1949 | |
| 1950 | if (DEBUG) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1951 | Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 1952 | + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons |
| 1953 | + " --> flags=0x" + Integer.toHexString(flags)); |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
Jorim Jaggi | e3e0b06 | 2017-06-12 12:18:41 -0700 | [diff] [blame] | 1956 | mStatusBarManager.disable(flags); |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1960 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1961 | * Handle message sent by {@link #resetStateLocked} |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1962 | * @see #RESET |
| 1963 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1964 | private void handleReset() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1965 | synchronized (KeyguardViewMediator.this) { |
| 1966 | if (DEBUG) Log.d(TAG, "handleReset"); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1967 | mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * Handle message sent by {@link #verifyUnlock} |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 1973 | * @see #VERIFY_UNLOCK |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1974 | */ |
| 1975 | private void handleVerifyUnlock() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1976 | Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1977 | synchronized (KeyguardViewMediator.this) { |
| 1978 | if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 1979 | setShowingLocked(true, mAodShowing); |
Jorim Jaggi | 8d5a6e7 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1980 | mStatusBarKeyguardViewManager.dismissAndCollapse(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1981 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1982 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Jorim Jaggi | 18f18ae | 2015-09-10 15:48:21 -0700 | [diff] [blame] | 1985 | private void handleNotifyStartedGoingToSleep() { |
| 1986 | synchronized (KeyguardViewMediator.this) { |
| 1987 | if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep"); |
| 1988 | mStatusBarKeyguardViewManager.onStartedGoingToSleep(); |
| 1989 | } |
| 1990 | } |
| 1991 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1992 | /** |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1993 | * Handle message sent by {@link #notifyFinishedGoingToSleep()} |
| 1994 | * @see #NOTIFY_FINISHED_GOING_TO_SLEEP |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1995 | */ |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1996 | private void handleNotifyFinishedGoingToSleep() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1997 | synchronized (KeyguardViewMediator.this) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1998 | if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep"); |
| 1999 | mStatusBarKeyguardViewManager.onFinishedGoingToSleep(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2000 | } |
| 2001 | } |
| 2002 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2003 | private void handleNotifyStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2004 | Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2005 | synchronized (KeyguardViewMediator.this) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2006 | if (DEBUG) Log.d(TAG, "handleNotifyWakingUp"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2007 | mStatusBarKeyguardViewManager.onStartedWakingUp(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2008 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2009 | Trace.endSection(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2013 | Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn"); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2014 | synchronized (KeyguardViewMediator.this) { |
| 2015 | if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn"); |
Jorim Jaggi | 9373911 | 2015-08-13 15:53:14 -0700 | [diff] [blame] | 2016 | mStatusBarKeyguardViewManager.onScreenTurningOn(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2017 | if (callback != null) { |
| 2018 | if (mWakeAndUnlocking) { |
| 2019 | mDrawnCallback = callback; |
| 2020 | } else { |
| 2021 | notifyDrawn(callback); |
| 2022 | } |
| 2023 | } |
| 2024 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2025 | Trace.endSection(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2028 | private void handleNotifyScreenTurnedOn() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2029 | Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn"); |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 2030 | if (LatencyTracker.isEnabled(mContext)) { |
| 2031 | LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN); |
| 2032 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2033 | synchronized (this) { |
| 2034 | if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn"); |
| 2035 | mStatusBarKeyguardViewManager.onScreenTurnedOn(); |
| 2036 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2037 | Trace.endSection(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | private void handleNotifyScreenTurnedOff() { |
| 2041 | synchronized (this) { |
| 2042 | if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff"); |
| 2043 | mStatusBarKeyguardViewManager.onScreenTurnedOff(); |
Jorim Jaggi | e93e6f9 | 2016-08-04 13:55:39 +0200 | [diff] [blame] | 2044 | mDrawnCallback = null; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2048 | private void notifyDrawn(final IKeyguardDrawnCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2049 | Trace.beginSection("KeyguardViewMediator#notifyDrawn"); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 2050 | try { |
| 2051 | callback.onDrawn(); |
| 2052 | } catch (RemoteException e) { |
| 2053 | Slog.w(TAG, "Exception calling onDrawn():", e); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2054 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2055 | Trace.endSection(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2056 | } |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 2057 | |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 2058 | private void resetKeyguardDonePendingLocked() { |
| 2059 | mKeyguardDonePending = false; |
| 2060 | mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT); |
| 2061 | } |
| 2062 | |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 2063 | @Override |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 2064 | public void onBootCompleted() { |
| 2065 | mUpdateMonitor.dispatchBootCompleted(); |
Jason Monk | cf5a953 | 2014-09-17 16:22:19 -0400 | [diff] [blame] | 2066 | synchronized (this) { |
| 2067 | mBootCompleted = true; |
| 2068 | if (mBootSendUserPresent) { |
| 2069 | sendUserPresentBroadcast(); |
| 2070 | } |
| 2071 | } |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 2072 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2073 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 2074 | public void onWakeAndUnlocking() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2075 | Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 2076 | mWakeAndUnlocking = true; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2077 | keyguardDone(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2078 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 2081 | public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar, |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 2082 | ViewGroup container, NotificationPanelView panelView, |
| 2083 | FingerprintUnlockController fingerprintUnlockController) { |
| 2084 | mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView, |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 2085 | fingerprintUnlockController, mDismissCallbackRegistry); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 2086 | return mStatusBarKeyguardViewManager; |
| 2087 | } |
| 2088 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 2089 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2090 | Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 2091 | Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM, |
| 2092 | new StartKeyguardExitAnimParams(startTime, fadeoutDuration)); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2093 | mHandler.sendMessage(msg); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 2094 | Trace.endSection(); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 2097 | public void onShortPowerPressedGoHome() { |
| 2098 | // do nothing |
| 2099 | } |
| 2100 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 2101 | public ViewMediatorCallback getViewMediatorCallback() { |
| 2102 | return mViewMediatorCallback; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2103 | } |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 2104 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 2105 | public LockPatternUtils getLockPatternUtils() { |
| 2106 | return mLockPatternUtils; |
| 2107 | } |
| 2108 | |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 2109 | @Override |
| 2110 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2111 | pw.print(" mSystemReady: "); pw.println(mSystemReady); |
| 2112 | pw.print(" mBootCompleted: "); pw.println(mBootCompleted); |
| 2113 | pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent); |
| 2114 | pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled); |
Adrian Roos | 1f8025a | 2016-12-27 10:12:13 -0800 | [diff] [blame] | 2115 | pw.print(" mShuttingDown: "); pw.println(mShuttingDown); |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 2116 | pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled); |
| 2117 | pw.print(" mShowing: "); pw.println(mShowing); |
| 2118 | pw.print(" mInputRestricted: "); pw.println(mInputRestricted); |
| 2119 | pw.print(" mOccluded: "); pw.println(mOccluded); |
| 2120 | pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence); |
| 2121 | pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback); |
| 2122 | pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive); |
| 2123 | pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep); |
| 2124 | pw.print(" mHiding: "); pw.println(mHiding); |
| 2125 | pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible); |
| 2126 | pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending); |
| 2127 | pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun); |
| 2128 | pw.print(" mPendingReset: "); pw.println(mPendingReset); |
| 2129 | pw.print(" mPendingLock: "); pw.println(mPendingLock); |
| 2130 | pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking); |
| 2131 | pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback); |
| 2132 | } |
| 2133 | |
Lucas Dupin | c29b146 | 2018-07-02 13:15:23 -0700 | [diff] [blame] | 2134 | /** |
| 2135 | * @param aodShowing true when AOD - or ambient mode - is showing. |
| 2136 | */ |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2137 | public void setAodShowing(boolean aodShowing) { |
| 2138 | setShowingLocked(mShowing, aodShowing); |
| 2139 | } |
| 2140 | |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 2141 | /** |
| 2142 | * @param pulsing true when device temporarily wakes up to display an incoming notification. |
| 2143 | */ |
| 2144 | public void setPulsing(boolean pulsing) { |
| 2145 | mPulsing = pulsing; |
| 2146 | } |
| 2147 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 2148 | private static class StartKeyguardExitAnimParams { |
| 2149 | |
| 2150 | long startTime; |
| 2151 | long fadeoutDuration; |
| 2152 | |
| 2153 | private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) { |
| 2154 | this.startTime = startTime; |
| 2155 | this.fadeoutDuration = fadeoutDuration; |
| 2156 | } |
| 2157 | } |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 2158 | |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2159 | private void setShowingLocked(boolean showing, boolean aodShowing) { |
| 2160 | setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing, |
| 2161 | false /* forceCallbacks */); |
Jorim Jaggi | e8f321e | 2016-11-07 16:48:31 -0800 | [diff] [blame] | 2162 | } |
| 2163 | |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2164 | private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing, |
| 2165 | boolean forceCallbacks) { |
| 2166 | final boolean notifyDefaultDisplayCallbacks = showing != mShowing |
| 2167 | || aodShowing != mAodShowing || forceCallbacks; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 2168 | if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2169 | mShowing = showing; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2170 | mAodShowing = aodShowing; |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 2171 | mSecondaryDisplayShowing = secondaryDisplayShowing; |
| 2172 | if (notifyDefaultDisplayCallbacks) { |
| 2173 | notifyDefaultDisplayCallbacks(showing); |
| 2174 | } |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2175 | updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing); |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | private void notifyDefaultDisplayCallbacks(boolean showing) { |
| 2180 | int size = mKeyguardStateCallbacks.size(); |
| 2181 | for (int i = size - 1; i >= 0; i--) { |
| 2182 | IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i); |
| 2183 | try { |
| 2184 | callback.onShowingStateChanged(showing); |
| 2185 | } catch (RemoteException e) { |
| 2186 | Slog.w(TAG, "Failed to call onShowingStateChanged", e); |
| 2187 | if (e instanceof DeadObjectException) { |
| 2188 | mKeyguardStateCallbacks.remove(callback); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2189 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2190 | } |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 2191 | } |
David Stevens | 53a39ea | 2017-08-23 18:41:49 -0700 | [diff] [blame] | 2192 | updateInputRestrictedLocked(); |
| 2193 | mUiOffloadThread.submit(() -> { |
| 2194 | mTrustManager.reportKeyguardShowingChanged(); |
| 2195 | }); |
Adrian Roos | 481a6df | 2014-11-20 19:48:56 +0100 | [diff] [blame] | 2196 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2197 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 2198 | private void notifyTrustedChangedLocked(boolean trusted) { |
| 2199 | int size = mKeyguardStateCallbacks.size(); |
| 2200 | for (int i = size - 1; i >= 0; i--) { |
| 2201 | try { |
| 2202 | mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted); |
| 2203 | } catch (RemoteException e) { |
| 2204 | Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e); |
| 2205 | if (e instanceof DeadObjectException) { |
| 2206 | mKeyguardStateCallbacks.remove(i); |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | } |
| 2211 | |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 2212 | private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) { |
| 2213 | int size = mKeyguardStateCallbacks.size(); |
| 2214 | for (int i = size - 1; i >= 0; i--) { |
| 2215 | try { |
| 2216 | mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged( |
| 2217 | hasLockscreenWallpaper); |
| 2218 | } catch (RemoteException e) { |
| 2219 | Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e); |
| 2220 | if (e instanceof DeadObjectException) { |
| 2221 | mKeyguardStateCallbacks.remove(i); |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2227 | public void addStateMonitorCallback(IKeyguardStateCallback callback) { |
| 2228 | synchronized (this) { |
| 2229 | mKeyguardStateCallbacks.add(callback); |
| 2230 | try { |
| 2231 | callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure()); |
| 2232 | callback.onShowingStateChanged(mShowing); |
Adrian Roos | 4a963ac | 2015-04-24 16:04:53 -0700 | [diff] [blame] | 2233 | callback.onInputRestrictedStateChanged(mInputRestricted); |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 2234 | callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust( |
| 2235 | KeyguardUpdateMonitor.getCurrentUser())); |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 2236 | callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper()); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2237 | } catch (RemoteException e) { |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 2238 | Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | } |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 2242 | |
| 2243 | private static class DismissMessage { |
| 2244 | private final CharSequence mMessage; |
| 2245 | private final IKeyguardDismissCallback mCallback; |
| 2246 | |
| 2247 | DismissMessage(IKeyguardDismissCallback callback, CharSequence message) { |
| 2248 | mCallback = callback; |
| 2249 | mMessage = message; |
| 2250 | } |
| 2251 | |
| 2252 | public IKeyguardDismissCallback getCallback() { |
| 2253 | return mCallback; |
| 2254 | } |
| 2255 | |
| 2256 | public CharSequence getMessage() { |
| 2257 | return mMessage; |
| 2258 | } |
| 2259 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2260 | } |