Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 1 | package com.android.server.policy.keyguard; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3 | import android.app.ActivityManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4 | import android.content.ComponentName; |
| 5 | import android.content.Context; |
| 6 | import android.content.Intent; |
| 7 | import android.content.ServiceConnection; |
Bryce Lee | 2a18cbc | 2015-03-09 15:49:23 +0000 | [diff] [blame] | 8 | import android.content.res.Resources; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 9 | import android.os.Bundle; |
Jorim Jaggi | 4a0e791 | 2015-07-29 15:46:29 -0700 | [diff] [blame] | 10 | import android.os.Handler; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 11 | import android.os.IBinder; |
| 12 | import android.os.RemoteException; |
| 13 | import android.os.UserHandle; |
| 14 | import android.util.Log; |
| 15 | import android.util.Slog; |
| 16 | import android.view.WindowManagerPolicy.OnKeyguardExitResult; |
| 17 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 18 | import com.android.internal.policy.IKeyguardDismissCallback; |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 19 | import com.android.internal.policy.IKeyguardDrawnCallback; |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 20 | import com.android.internal.policy.IKeyguardExitCallback; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 21 | import com.android.internal.policy.IKeyguardService; |
Adrian Roos | 691546e | 2016-02-09 10:13:41 -0800 | [diff] [blame] | 22 | import com.android.server.UiThread; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 23 | |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 24 | import java.io.PrintWriter; |
| 25 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 26 | /** |
| 27 | * A local class that keeps a cache of keyguard state that can be restored in the event |
| 28 | * keyguard crashes. It currently also allows runtime-selectable |
| 29 | * local or remote instances of keyguard. |
| 30 | */ |
| 31 | public class KeyguardServiceDelegate { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 32 | private static final String TAG = "KeyguardServiceDelegate"; |
Joe Onorato | 82ba91d | 2017-04-27 16:18:05 -0700 | [diff] [blame] | 33 | private static final boolean DEBUG = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 34 | |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 35 | private static final int SCREEN_STATE_OFF = 0; |
| 36 | private static final int SCREEN_STATE_TURNING_ON = 1; |
| 37 | private static final int SCREEN_STATE_ON = 2; |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 38 | private static final int SCREEN_STATE_TURNING_OFF = 3; |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 39 | |
| 40 | private static final int INTERACTIVE_STATE_SLEEP = 0; |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 41 | private static final int INTERACTIVE_STATE_WAKING = 1; |
| 42 | private static final int INTERACTIVE_STATE_AWAKE = 2; |
| 43 | private static final int INTERACTIVE_STATE_GOING_TO_SLEEP = 3; |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 44 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 45 | protected KeyguardServiceWrapper mKeyguardService; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 46 | private final Context mContext; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 47 | private final Handler mHandler; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 48 | private final KeyguardState mKeyguardState = new KeyguardState(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 49 | private final KeyguardStateMonitor.StateCallback mCallback; |
| 50 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 51 | private DrawnListener mDrawnListenerWhenConnect; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 52 | |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 53 | private static final class KeyguardState { |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 54 | KeyguardState() { |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 55 | reset(); |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 56 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 57 | boolean showing; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 58 | boolean showingAndNotOccluded; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 59 | boolean inputRestricted; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 60 | boolean occluded; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 61 | boolean secure; |
| 62 | boolean dreaming; |
| 63 | boolean systemIsReady; |
Jim Miller | a8800f7 | 2014-12-12 13:34:43 -0800 | [diff] [blame] | 64 | boolean deviceHasKeyguard; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 65 | public boolean enabled; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 66 | public int offReason; |
| 67 | public int currentUser; |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 68 | public boolean bootCompleted; |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 69 | public int screenState; |
| 70 | public int interactiveState; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 71 | |
| 72 | private void reset() { |
| 73 | // Assume keyguard is showing and secure until we know for sure. This is here in |
| 74 | // the event something checks before the service is actually started. |
| 75 | // KeyguardService itself should default to this state until the real state is known. |
| 76 | showing = true; |
| 77 | showingAndNotOccluded = true; |
| 78 | secure = true; |
| 79 | deviceHasKeyguard = true; |
| 80 | enabled = true; |
| 81 | currentUser = UserHandle.USER_NULL; |
| 82 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 85 | public interface DrawnListener { |
| 86 | void onDrawn(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 89 | // A delegate class to map a particular invocation with a ShowListener object. |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 90 | private final class KeyguardShowDelegate extends IKeyguardDrawnCallback.Stub { |
| 91 | private DrawnListener mDrawnListener; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 92 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 93 | KeyguardShowDelegate(DrawnListener drawnListener) { |
| 94 | mDrawnListener = drawnListener; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 98 | public void onDrawn() throws RemoteException { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 99 | if (DEBUG) Log.v(TAG, "**** SHOWN CALLED ****"); |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 100 | if (mDrawnListener != null) { |
| 101 | mDrawnListener.onDrawn(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | // A delegate class to map a particular invocation with an OnKeyguardExitResult object. |
| 107 | private final class KeyguardExitDelegate extends IKeyguardExitCallback.Stub { |
| 108 | private OnKeyguardExitResult mOnKeyguardExitResult; |
| 109 | |
| 110 | KeyguardExitDelegate(OnKeyguardExitResult onKeyguardExitResult) { |
| 111 | mOnKeyguardExitResult = onKeyguardExitResult; |
| 112 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 113 | |
| 114 | @Override |
| 115 | public void onKeyguardExitResult(boolean success) throws RemoteException { |
| 116 | if (DEBUG) Log.v(TAG, "**** onKeyguardExitResult(" + success +") CALLED ****"); |
| 117 | if (mOnKeyguardExitResult != null) { |
| 118 | mOnKeyguardExitResult.onKeyguardExitResult(success); |
| 119 | } |
| 120 | } |
| 121 | }; |
| 122 | |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 123 | public KeyguardServiceDelegate(Context context, KeyguardStateMonitor.StateCallback callback) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 124 | mContext = context; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 125 | mHandler = UiThread.getHandler(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 126 | mCallback = callback; |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | public void bindService(Context context) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 130 | Intent intent = new Intent(); |
Bryce Lee | 2a18cbc | 2015-03-09 15:49:23 +0000 | [diff] [blame] | 131 | final Resources resources = context.getApplicationContext().getResources(); |
| 132 | |
| 133 | final ComponentName keyguardComponent = ComponentName.unflattenFromString( |
| 134 | resources.getString(com.android.internal.R.string.config_keyguardComponent)); |
Jeff Sharkey | 2f3e353 | 2015-12-21 14:16:43 -0700 | [diff] [blame] | 135 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
Bryce Lee | 2a18cbc | 2015-03-09 15:49:23 +0000 | [diff] [blame] | 136 | intent.setComponent(keyguardComponent); |
| 137 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 138 | if (!context.bindServiceAsUser(intent, mKeyguardConnection, |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 139 | Context.BIND_AUTO_CREATE, mHandler, UserHandle.SYSTEM)) { |
Bryce Lee | 2a18cbc | 2015-03-09 15:49:23 +0000 | [diff] [blame] | 140 | Log.v(TAG, "*** Keyguard: can't bind to " + keyguardComponent); |
Jim Miller | fb5fcea | 2014-01-08 14:57:54 -0800 | [diff] [blame] | 141 | mKeyguardState.showing = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 142 | mKeyguardState.showingAndNotOccluded = false; |
Jim Miller | fb5fcea | 2014-01-08 14:57:54 -0800 | [diff] [blame] | 143 | mKeyguardState.secure = false; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 144 | synchronized (mKeyguardState) { |
| 145 | // TODO: Fix synchronisation model in this class. The other state in this class |
| 146 | // is at least self-healing but a race condition here can lead to the scrim being |
| 147 | // stuck on keyguard-less devices. |
| 148 | mKeyguardState.deviceHasKeyguard = false; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 149 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 150 | } else { |
| 151 | if (DEBUG) Log.v(TAG, "*** Keyguard started"); |
| 152 | } |
| 153 | } |
| 154 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 155 | private final ServiceConnection mKeyguardConnection = new ServiceConnection() { |
| 156 | @Override |
| 157 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 158 | if (DEBUG) Log.v(TAG, "*** Keyguard connected (yay!)"); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 159 | mKeyguardService = new KeyguardServiceWrapper(mContext, |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 160 | IKeyguardService.Stub.asInterface(service), mCallback); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 161 | if (mKeyguardState.systemIsReady) { |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 162 | // If the system is ready, it means keyguard crashed and restarted. |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 163 | mKeyguardService.onSystemReady(); |
Suprabh Shukla | 323d2bb | 2016-07-27 17:00:12 -0700 | [diff] [blame] | 164 | if (mKeyguardState.currentUser != UserHandle.USER_NULL) { |
| 165 | // There has been a user switch earlier |
| 166 | mKeyguardService.setCurrentUser(mKeyguardState.currentUser); |
| 167 | } |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 168 | // This is used to hide the scrim once keyguard displays. |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 169 | if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE |
| 170 | || mKeyguardState.interactiveState == INTERACTIVE_STATE_WAKING) { |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 171 | mKeyguardService.onStartedWakingUp(); |
| 172 | } |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 173 | if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE) { |
| 174 | mKeyguardService.onFinishedWakingUp(); |
| 175 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 176 | if (mKeyguardState.screenState == SCREEN_STATE_ON |
| 177 | || mKeyguardState.screenState == SCREEN_STATE_TURNING_ON) { |
| 178 | mKeyguardService.onScreenTurningOn( |
| 179 | new KeyguardShowDelegate(mDrawnListenerWhenConnect)); |
| 180 | } |
| 181 | if (mKeyguardState.screenState == SCREEN_STATE_ON) { |
| 182 | mKeyguardService.onScreenTurnedOn(); |
| 183 | } |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 184 | mDrawnListenerWhenConnect = null; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 185 | } |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 186 | if (mKeyguardState.bootCompleted) { |
| 187 | mKeyguardService.onBootCompleted(); |
| 188 | } |
Adrian Roos | f253eeb | 2015-04-15 18:03:08 -0700 | [diff] [blame] | 189 | if (mKeyguardState.occluded) { |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 190 | mKeyguardService.setOccluded(mKeyguardState.occluded, false /* animate */); |
Adrian Roos | f253eeb | 2015-04-15 18:03:08 -0700 | [diff] [blame] | 191 | } |
Tony Mak | 2c0d6dc | 2016-04-29 16:16:54 +0100 | [diff] [blame] | 192 | if (!mKeyguardState.enabled) { |
| 193 | mKeyguardService.setKeyguardEnabled(mKeyguardState.enabled); |
| 194 | } |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 195 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 196 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 197 | @Override |
| 198 | public void onServiceDisconnected(ComponentName name) { |
| 199 | if (DEBUG) Log.v(TAG, "*** Keyguard disconnected (boo!)"); |
| 200 | mKeyguardService = null; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 201 | mKeyguardState.reset(); |
| 202 | mHandler.post(() -> { |
| 203 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 204 | ActivityManager.getService().setLockScreenShown(true); |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 205 | } catch (RemoteException e) { |
| 206 | // Local call. |
| 207 | } |
| 208 | }); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 209 | } |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 210 | }; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 211 | |
| 212 | public boolean isShowing() { |
| 213 | if (mKeyguardService != null) { |
| 214 | mKeyguardState.showing = mKeyguardService.isShowing(); |
| 215 | } |
| 216 | return mKeyguardState.showing; |
| 217 | } |
| 218 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 219 | public boolean isTrusted() { |
| 220 | if (mKeyguardService != null) { |
| 221 | return mKeyguardService.isTrusted(); |
| 222 | } |
| 223 | return false; |
| 224 | } |
| 225 | |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 226 | public boolean hasLockscreenWallpaper() { |
| 227 | if (mKeyguardService != null) { |
| 228 | return mKeyguardService.hasLockscreenWallpaper(); |
| 229 | } |
| 230 | return false; |
| 231 | } |
| 232 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 233 | public boolean isInputRestricted() { |
| 234 | if (mKeyguardService != null) { |
| 235 | mKeyguardState.inputRestricted = mKeyguardService.isInputRestricted(); |
| 236 | } |
| 237 | return mKeyguardState.inputRestricted; |
| 238 | } |
| 239 | |
| 240 | public void verifyUnlock(final OnKeyguardExitResult onKeyguardExitResult) { |
| 241 | if (mKeyguardService != null) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 242 | mKeyguardService.verifyUnlock(new KeyguardExitDelegate(onKeyguardExitResult)); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 246 | public void setOccluded(boolean isOccluded, boolean animate) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 247 | if (mKeyguardService != null) { |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 248 | if (DEBUG) Log.v(TAG, "setOccluded(" + isOccluded + ") animate=" + animate); |
| 249 | mKeyguardService.setOccluded(isOccluded, animate); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 250 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 251 | mKeyguardState.occluded = isOccluded; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 254 | public void dismiss(IKeyguardDismissCallback callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 255 | if (mKeyguardService != null) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 256 | mKeyguardService.dismiss(callback); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 260 | public boolean isSecure(int userId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 261 | if (mKeyguardService != null) { |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 262 | mKeyguardState.secure = mKeyguardService.isSecure(userId); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 263 | } |
| 264 | return mKeyguardState.secure; |
| 265 | } |
| 266 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 267 | public void onDreamingStarted() { |
| 268 | if (mKeyguardService != null) { |
| 269 | mKeyguardService.onDreamingStarted(); |
| 270 | } |
| 271 | mKeyguardState.dreaming = true; |
| 272 | } |
| 273 | |
| 274 | public void onDreamingStopped() { |
| 275 | if (mKeyguardService != null) { |
| 276 | mKeyguardService.onDreamingStopped(); |
| 277 | } |
| 278 | mKeyguardState.dreaming = false; |
| 279 | } |
| 280 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 281 | public void onStartedWakingUp() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 282 | if (mKeyguardService != null) { |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 283 | if (DEBUG) Log.v(TAG, "onStartedWakingUp()"); |
| 284 | mKeyguardService.onStartedWakingUp(); |
| 285 | } |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 286 | mKeyguardState.interactiveState = INTERACTIVE_STATE_WAKING; |
| 287 | } |
| 288 | |
| 289 | public void onFinishedWakingUp() { |
| 290 | if (mKeyguardService != null) { |
| 291 | if (DEBUG) Log.v(TAG, "onFinishedWakingUp()"); |
| 292 | mKeyguardService.onFinishedWakingUp(); |
| 293 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 294 | mKeyguardState.interactiveState = INTERACTIVE_STATE_AWAKE; |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 297 | public void onScreenTurningOff() { |
| 298 | if (mKeyguardService != null) { |
| 299 | if (DEBUG) Log.v(TAG, "onScreenTurningOff()"); |
| 300 | mKeyguardService.onScreenTurningOff(); |
| 301 | } |
| 302 | mKeyguardState.screenState = SCREEN_STATE_TURNING_OFF; |
| 303 | } |
| 304 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 305 | public void onScreenTurnedOff() { |
| 306 | if (mKeyguardService != null) { |
| 307 | if (DEBUG) Log.v(TAG, "onScreenTurnedOff()"); |
| 308 | mKeyguardService.onScreenTurnedOff(); |
| 309 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 310 | mKeyguardState.screenState = SCREEN_STATE_OFF; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 313 | public void onScreenTurningOn(final DrawnListener drawnListener) { |
| 314 | if (mKeyguardService != null) { |
| 315 | if (DEBUG) Log.v(TAG, "onScreenTurnedOn(showListener = " + drawnListener + ")"); |
| 316 | mKeyguardService.onScreenTurningOn(new KeyguardShowDelegate(drawnListener)); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 317 | } else { |
| 318 | // try again when we establish a connection |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 319 | Slog.w(TAG, "onScreenTurningOn(): no keyguard service!"); |
Jim Miller | a8800f7 | 2014-12-12 13:34:43 -0800 | [diff] [blame] | 320 | // This shouldn't happen, but if it does, show the scrim immediately and |
| 321 | // invoke the listener's callback after the service actually connects. |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 322 | mDrawnListenerWhenConnect = drawnListener; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 323 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 324 | mKeyguardState.screenState = SCREEN_STATE_TURNING_ON; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 327 | public void onScreenTurnedOn() { |
| 328 | if (mKeyguardService != null) { |
| 329 | if (DEBUG) Log.v(TAG, "onScreenTurnedOn()"); |
| 330 | mKeyguardService.onScreenTurnedOn(); |
| 331 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 332 | mKeyguardState.screenState = SCREEN_STATE_ON; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 335 | public void onStartedGoingToSleep(int why) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 336 | if (mKeyguardService != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 337 | mKeyguardService.onStartedGoingToSleep(why); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 338 | } |
| 339 | mKeyguardState.offReason = why; |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 340 | mKeyguardState.interactiveState = INTERACTIVE_STATE_GOING_TO_SLEEP; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 343 | public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 344 | if (mKeyguardService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 345 | mKeyguardService.onFinishedGoingToSleep(why, cameraGestureTriggered); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 346 | } |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 347 | mKeyguardState.interactiveState = INTERACTIVE_STATE_SLEEP; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | public void setKeyguardEnabled(boolean enabled) { |
| 351 | if (mKeyguardService != null) { |
| 352 | mKeyguardService.setKeyguardEnabled(enabled); |
| 353 | } |
| 354 | mKeyguardState.enabled = enabled; |
| 355 | } |
| 356 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 357 | public void onSystemReady() { |
| 358 | if (mKeyguardService != null) { |
| 359 | mKeyguardService.onSystemReady(); |
| 360 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 361 | mKeyguardState.systemIsReady = true; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | public void doKeyguardTimeout(Bundle options) { |
| 366 | if (mKeyguardService != null) { |
| 367 | mKeyguardService.doKeyguardTimeout(options); |
| 368 | } |
| 369 | } |
| 370 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 371 | public void setCurrentUser(int newUserId) { |
| 372 | if (mKeyguardService != null) { |
| 373 | mKeyguardService.setCurrentUser(newUserId); |
| 374 | } |
| 375 | mKeyguardState.currentUser = newUserId; |
| 376 | } |
| 377 | |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 378 | public void setSwitchingUser(boolean switching) { |
| 379 | if (mKeyguardService != null) { |
| 380 | mKeyguardService.setSwitchingUser(switching); |
| 381 | } |
| 382 | } |
| 383 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 384 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 385 | if (mKeyguardService != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 386 | mKeyguardService.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 390 | public void onBootCompleted() { |
| 391 | if (mKeyguardService != null) { |
| 392 | mKeyguardService.onBootCompleted(); |
| 393 | } |
| 394 | mKeyguardState.bootCompleted = true; |
| 395 | } |
| 396 | |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 397 | public void onShortPowerPressedGoHome() { |
| 398 | if (mKeyguardService != null) { |
| 399 | mKeyguardService.onShortPowerPressedGoHome(); |
| 400 | } |
| 401 | } |
| 402 | |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 403 | public void dump(String prefix, PrintWriter pw) { |
| 404 | pw.println(prefix + TAG); |
| 405 | prefix += " "; |
| 406 | pw.println(prefix + "showing=" + mKeyguardState.showing); |
| 407 | pw.println(prefix + "showingAndNotOccluded=" + mKeyguardState.showingAndNotOccluded); |
| 408 | pw.println(prefix + "inputRestricted=" + mKeyguardState.inputRestricted); |
| 409 | pw.println(prefix + "occluded=" + mKeyguardState.occluded); |
| 410 | pw.println(prefix + "secure=" + mKeyguardState.secure); |
| 411 | pw.println(prefix + "dreaming=" + mKeyguardState.dreaming); |
| 412 | pw.println(prefix + "systemIsReady=" + mKeyguardState.systemIsReady); |
| 413 | pw.println(prefix + "deviceHasKeyguard=" + mKeyguardState.deviceHasKeyguard); |
| 414 | pw.println(prefix + "enabled=" + mKeyguardState.enabled); |
| 415 | pw.println(prefix + "offReason=" + mKeyguardState.offReason); |
| 416 | pw.println(prefix + "currentUser=" + mKeyguardState.currentUser); |
| 417 | pw.println(prefix + "bootCompleted=" + mKeyguardState.bootCompleted); |
| 418 | pw.println(prefix + "screenState=" + mKeyguardState.screenState); |
| 419 | pw.println(prefix + "interactiveState=" + mKeyguardState.interactiveState); |
| 420 | if (mKeyguardService != null) { |
| 421 | mKeyguardService.dump(prefix, pw); |
| 422 | } |
| 423 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 424 | } |