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