blob: 35bea268b836a4a0fd8dbf3d1d9d484617b8f41e [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
18
Jim Miller25190572013-02-28 17:36:24 -080019import com.android.internal.policy.IKeyguardShowCallback;
Jim Miller5ecd8112013-01-09 18:50:26 -080020import com.android.internal.widget.LockPatternUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080021
Jim Millerdcb3d842012-08-23 19:18:12 -070022import android.app.Activity;
Dianne Hackbornb3756322011-08-12 13:58:13 -070023import android.app.ActivityManager;
Michael Jurka76017ca2012-11-06 16:21:09 -080024import android.appwidget.AppWidgetManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080025import android.content.Context;
26import android.content.pm.ActivityInfo;
Jim Millerdcb3d842012-08-23 19:18:12 -070027import android.content.res.Configuration;
Jim Miller06cc78a2011-06-02 16:10:16 -070028import android.content.res.Resources;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.graphics.PixelFormat;
Jim Miller2b84b812012-11-30 15:42:18 -080030import android.graphics.Rect;
Adam Cohenf7522022012-10-03 20:03:18 -070031import android.os.Bundle;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070032import android.os.IBinder;
Jim Miller6bcd7322012-10-02 16:32:04 -070033import android.os.Parcelable;
Jim Miller5ecd8112013-01-09 18:50:26 -080034import android.os.RemoteException;
Jim Miller56bacd72011-09-09 14:12:54 -070035import android.os.SystemProperties;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080036import android.util.Log;
Craig Mautner0cbfcff2012-09-17 16:40:28 -070037import android.util.Slog;
Jim Miller6bcd7322012-10-02 16:32:04 -070038import android.util.SparseArray;
Adam Cohenf7522022012-10-03 20:03:18 -070039import android.view.KeyEvent;
Jim Millerdcb3d842012-08-23 19:18:12 -070040import android.view.LayoutInflater;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.view.View;
42import android.view.ViewGroup;
43import android.view.ViewManager;
44import android.view.WindowManager;
45import android.widget.FrameLayout;
46
47/**
48 * Manages creating, showing, hiding and resetting the keyguard. Calls back
Craig Mautner904732c2012-10-17 15:20:24 -070049 * via {@link KeyguardViewMediator.ViewMediatorCallback} to poke
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050 * the wake lock and report that the keyguard is done, which is in turn,
51 * reported to this class by the current {@link KeyguardViewBase}.
52 */
Jim Millerdcb3d842012-08-23 19:18:12 -070053public class KeyguardViewManager {
Jim Millera71984f2012-10-24 22:08:49 -070054 private final static boolean DEBUG = KeyguardViewMediator.DEBUG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055 private static String TAG = "KeyguardViewManager";
Jim Miller3af630c2012-09-26 14:29:18 -070056 public static boolean USE_UPPER_CASE = true;
Chris Wrenf41c61b2012-11-29 15:19:54 -050057 public final static String IS_SWITCHING_USER = "is_switching_user";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058
Jim Miller9cf2c522012-10-04 22:02:29 -070059 // Timeout used for keypresses
60 static final int DIGIT_PRESS_WAKE_MILLIS = 5000;
61
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062 private final Context mContext;
63 private final ViewManager mViewManager;
Jim Millerdcb3d842012-08-23 19:18:12 -070064 private final KeyguardViewMediator.ViewMediatorCallback mViewMediatorCallback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080065
66 private WindowManager.LayoutParams mWindowLayoutParams;
67 private boolean mNeedsInput = false;
Jim Miller22dfe722009-10-07 01:30:21 -070068
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069 private FrameLayout mKeyguardHost;
Jim Millerdcb3d842012-08-23 19:18:12 -070070 private KeyguardHostView mKeyguardView;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071
Craig Mautnerad09bcc2012-10-08 13:33:11 -070072 private boolean mScreenOn = false;
Jim Millerdcb3d842012-08-23 19:18:12 -070073 private LockPatternUtils mLockPatternUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074
Dianne Hackborn38e29a62011-09-18 14:43:08 -070075 public interface ShowListener {
76 void onShown(IBinder windowToken);
77 };
78
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079 /**
80 * @param context Used to create views.
81 * @param viewManager Keyguard will be attached to this.
82 * @param callback Used to notify of changes.
Jim Millerdcb3d842012-08-23 19:18:12 -070083 * @param lockPatternUtils
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084 */
85 public KeyguardViewManager(Context context, ViewManager viewManager,
Jim Millerdcb3d842012-08-23 19:18:12 -070086 KeyguardViewMediator.ViewMediatorCallback callback,
87 LockPatternUtils lockPatternUtils) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088 mContext = context;
89 mViewManager = viewManager;
Jim Millerdcb3d842012-08-23 19:18:12 -070090 mViewMediatorCallback = callback;
91 mLockPatternUtils = lockPatternUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092 }
93
94 /**
95 * Show the keyguard. Will handle creating and attaching to the view manager
96 * lazily.
97 */
Adam Cohenf7522022012-10-03 20:03:18 -070098 public synchronized void show(Bundle options) {
Daniel Sandler16541e42009-11-13 17:07:50 -080099 if (DEBUG) Log.d(TAG, "show(); mKeyguardView==" + mKeyguardView);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800100
Jim Millerdcb3d842012-08-23 19:18:12 -0700101 boolean enableScreenRotation = shouldEnableScreenRotation();
102
Jim Millera71984f2012-10-24 22:08:49 -0700103 maybeCreateKeyguardLocked(enableScreenRotation, false, options);
Jim Millerdcb3d842012-08-23 19:18:12 -0700104 maybeEnableScreenRotation(enableScreenRotation);
105
Jim Millere23ab8b2012-09-16 15:45:44 -0700106 // Disable common aspects of the system/status/navigation bars that are not appropriate or
107 // useful on any keyguard screen but can be re-shown by dialogs or SHOW_WHEN_LOCKED
108 // activities. Other disabled bits are handled by the KeyguardViewMediator talking
109 // directly to the status bar service.
110 final int visFlags = View.STATUS_BAR_DISABLE_HOME;
Jim Millera71984f2012-10-24 22:08:49 -0700111 if (DEBUG) Log.v(TAG, "show:setSystemUiVisibility(" + Integer.toHexString(visFlags)+")");
Jim Millerdcb3d842012-08-23 19:18:12 -0700112 mKeyguardHost.setSystemUiVisibility(visFlags);
113
114 mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
115 mKeyguardHost.setVisibility(View.VISIBLE);
116 mKeyguardView.show();
117 mKeyguardView.requestFocus();
118 }
119
120 private boolean shouldEnableScreenRotation() {
Jim Miller06cc78a2011-06-02 16:10:16 -0700121 Resources res = mContext.getResources();
Jim Millerdcb3d842012-08-23 19:18:12 -0700122 return SystemProperties.getBoolean("lockscreen.rot_override",false)
Jim Miller5ecd8112013-01-09 18:50:26 -0800123 || res.getBoolean(R.bool.config_enableLockScreenRotation);
Jim Millerdcb3d842012-08-23 19:18:12 -0700124 }
125
126 class ViewManagerHost extends FrameLayout {
127 public ViewManagerHost(Context context) {
128 super(context);
Adam Powell5da64302012-11-05 14:16:59 -0800129 setFitsSystemWindows(true);
Jim Millerdcb3d842012-08-23 19:18:12 -0700130 }
131
132 @Override
Jim Miller2b84b812012-11-30 15:42:18 -0800133 protected boolean fitSystemWindows(Rect insets) {
134 Log.v("TAG", "bug 7643792: fitSystemWindows(" + insets.toShortString() + ")");
135 return super.fitSystemWindows(insets);
136 }
137
138 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700139 protected void onConfigurationChanged(Configuration newConfig) {
140 super.onConfigurationChanged(newConfig);
Jim Millera71984f2012-10-24 22:08:49 -0700141 if (mKeyguardHost.getVisibility() == View.VISIBLE) {
142 // only propagate configuration messages if we're currently showing
143 maybeCreateKeyguardLocked(shouldEnableScreenRotation(), true, null);
144 } else {
145 if (DEBUG) Log.v(TAG, "onConfigurationChanged: view not visible");
146 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700147 }
Jim Miller0a34d9e2012-10-05 17:15:41 -0700148
149 @Override
150 public boolean dispatchKeyEvent(KeyEvent event) {
Jim Miller42df15e2012-12-05 15:15:00 -0800151 if (mKeyguardView != null) {
152 // Always process back and menu keys, regardless of focus
153 if (event.getAction() == KeyEvent.ACTION_DOWN) {
154 int keyCode = event.getKeyCode();
155 if (keyCode == KeyEvent.KEYCODE_BACK && mKeyguardView.handleBackKey()) {
156 return true;
157 } else if (keyCode == KeyEvent.KEYCODE_MENU && mKeyguardView.handleMenuKey()) {
158 return true;
159 }
160 }
161 // Always process media keys, regardless of focus
162 if (mKeyguardView.dispatchKeyEvent(event)) {
Jim Miller0a34d9e2012-10-05 17:15:41 -0700163 return true;
164 }
165 }
166 return super.dispatchKeyEvent(event);
167 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700168 }
169
Jim Miller6bcd7322012-10-02 16:32:04 -0700170 SparseArray<Parcelable> mStateContainer = new SparseArray<Parcelable>();
171
Jim Millera71984f2012-10-24 22:08:49 -0700172 private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean force,
173 Bundle options) {
Jim Miller6bcd7322012-10-02 16:32:04 -0700174 if (mKeyguardHost != null) {
175 mKeyguardHost.saveHierarchyState(mStateContainer);
176 }
177
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800178 if (mKeyguardHost == null) {
179 if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");
180
Jim Millerdcb3d842012-08-23 19:18:12 -0700181 mKeyguardHost = new ViewManagerHost(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182
Adam Powell5da64302012-11-05 14:16:59 -0800183 int flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
184 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Adam Powella9fa92e2012-11-08 00:03:34 -0800185 | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
Jim Millerd2b82f72012-09-18 20:52:55 -0700186 | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Jim Millerdcb3d842012-08-23 19:18:12 -0700187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 if (!mNeedsInput) {
189 flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
190 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700191
192 final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
Jim Miller5ecd8112013-01-09 18:50:26 -0800193 final int type = WindowManager.LayoutParams.TYPE_KEYGUARD;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
Jim Millerdcb3d842012-08-23 19:18:12 -0700195 stretch, stretch, type, flags, PixelFormat.TRANSLUCENT);
Jim Miller6b05d582011-07-18 13:09:59 -0700196 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Jim Miller5ecd8112013-01-09 18:50:26 -0800197 lp.windowAnimations = R.style.Animation_LockScreen;
Jim Miller8e26cd82013-03-12 18:45:28 -0700198 lp.screenOrientation = enableScreenRotation ?
199 ActivityInfo.SCREEN_ORIENTATION_USER : ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
200
Jeff Brown98365d72012-08-19 20:30:52 -0700201 if (ActivityManager.isHighEndGfx()) {
Dianne Hackborn5d927c22011-09-02 12:22:18 -0700202 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
203 lp.privateFlags |=
204 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
205 }
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800206 lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
Jeff Brown3dc524b2012-09-30 19:49:11 -0700207 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
Jim Millercf182aa2013-06-28 16:55:56 -0700208 lp.setTitle("Keyguard");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800209 mWindowLayoutParams = lp;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 mViewManager.addView(mKeyguardHost, lp);
211 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700212
Jim Millera71984f2012-10-24 22:08:49 -0700213 if (force || mKeyguardView == null) {
214 inflateKeyguardView(options);
Jim Miller147f9562012-12-03 17:55:16 -0800215 mKeyguardView.requestFocus();
Jim Millera71984f2012-10-24 22:08:49 -0700216 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700217 updateUserActivityTimeoutInWindowLayoutParams();
Jim Millerdcb3d842012-08-23 19:18:12 -0700218 mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
Jim Miller6bcd7322012-10-02 16:32:04 -0700219
220 mKeyguardHost.restoreHierarchyState(mStateContainer);
Jim Millerdcb3d842012-08-23 19:18:12 -0700221 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800222
Adam Cohenf7522022012-10-03 20:03:18 -0700223 private void inflateKeyguardView(Bundle options) {
Craig Mautner00baebe2012-09-28 15:22:39 -0700224 View v = mKeyguardHost.findViewById(R.id.keyguard_host_view);
225 if (v != null) {
226 mKeyguardHost.removeView(v);
Jim Millerdcb3d842012-08-23 19:18:12 -0700227 }
228 final LayoutInflater inflater = LayoutInflater.from(mContext);
229 View view = inflater.inflate(R.layout.keyguard_host_view, mKeyguardHost, true);
230 mKeyguardView = (KeyguardHostView) view.findViewById(R.id.keyguard_host_view);
231 mKeyguardView.setLockPatternUtils(mLockPatternUtils);
232 mKeyguardView.setViewMediatorCallback(mViewMediatorCallback);
Chris Wrenf41c61b2012-11-29 15:19:54 -0500233 mKeyguardView.initializeSwitchingUserState(options != null &&
234 options.getBoolean(IS_SWITCHING_USER));
Jim Millerdcb3d842012-08-23 19:18:12 -0700235
Adam Powell70bc9f22012-10-12 22:02:27 -0700236 // HACK
237 // The keyguard view will have set up window flags in onFinishInflate before we set
238 // the view mediator callback. Make sure it knows the correct IME state.
239 if (mViewMediatorCallback != null) {
240 KeyguardPasswordView kpv = (KeyguardPasswordView) mKeyguardView.findViewById(
241 R.id.keyguard_password_view);
242
243 if (kpv != null) {
244 mViewMediatorCallback.setNeedsInput(kpv.needsInput());
245 }
246 }
247
Jim Miller0ff7f012012-10-11 20:40:01 -0700248 if (options != null) {
Michael Jurka76017ca2012-11-06 16:21:09 -0800249 int widgetToShow = options.getInt(LockPatternUtils.KEYGUARD_SHOW_APPWIDGET,
250 AppWidgetManager.INVALID_APPWIDGET_ID);
251 if (widgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) {
252 mKeyguardView.goToWidget(widgetToShow);
253 }
Adam Cohenf7522022012-10-03 20:03:18 -0700254 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700255 }
256
Jeff Brownc7505bc2012-10-05 21:58:15 -0700257 public void updateUserActivityTimeout() {
258 updateUserActivityTimeoutInWindowLayoutParams();
259 mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
260 }
261
262 private void updateUserActivityTimeoutInWindowLayoutParams() {
263 // Use the user activity timeout requested by the keyguard view, if any.
264 if (mKeyguardView != null) {
265 long timeout = mKeyguardView.getUserActivityTimeout();
266 if (timeout >= 0) {
267 mWindowLayoutParams.userActivityTimeout = timeout;
268 return;
269 }
270 }
271
272 // Otherwise, use the default timeout.
273 mWindowLayoutParams.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
274 }
275
Jim Millerdcb3d842012-08-23 19:18:12 -0700276 private void maybeEnableScreenRotation(boolean enableScreenRotation) {
277 // TODO: move this outside
Jim Miller06cc78a2011-06-02 16:10:16 -0700278 if (enableScreenRotation) {
Jim Millerf3447352011-08-07 14:00:09 -0700279 if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen On!");
Jim Miller82f91962012-07-24 13:33:08 -0700280 mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
Jim Miller06cc78a2011-06-02 16:10:16 -0700281 } else {
Jim Millerf3447352011-08-07 14:00:09 -0700282 if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen Off!");
Jim Miller06cc78a2011-06-02 16:10:16 -0700283 mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
284 }
Jim Miller06cc78a2011-06-02 16:10:16 -0700285 mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800286 }
287
288 public void setNeedsInput(boolean needsInput) {
289 mNeedsInput = needsInput;
290 if (mWindowLayoutParams != null) {
291 if (needsInput) {
292 mWindowLayoutParams.flags &=
293 ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
294 } else {
295 mWindowLayoutParams.flags |=
296 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
297 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700298
299 try {
300 mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
301 } catch (java.lang.IllegalArgumentException e) {
302 // TODO: Ensure this method isn't called on views that are changing...
303 Log.w(TAG,"Can't update input method on " + mKeyguardHost + " window not attached");
304 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 }
306 }
Jim Miller22dfe722009-10-07 01:30:21 -0700307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800308 /**
309 * Reset the state of the view.
310 */
Adam Cohenf7522022012-10-03 20:03:18 -0700311 public synchronized void reset(Bundle options) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800312 if (DEBUG) Log.d(TAG, "reset()");
Amith Yamasanid979dd72012-09-11 15:53:37 -0700313 // User might have switched, check if we need to go back to keyguard
314 // TODO: It's preferable to stay and show the correct lockscreen or unlock if none
Jim Millera71984f2012-10-24 22:08:49 -0700315 maybeCreateKeyguardLocked(shouldEnableScreenRotation(), true, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800316 }
317
318 public synchronized void onScreenTurnedOff() {
319 if (DEBUG) Log.d(TAG, "onScreenTurnedOff()");
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700320 mScreenOn = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800321 if (mKeyguardView != null) {
322 mKeyguardView.onScreenTurnedOff();
Brian Colonna15ea55a2011-09-09 11:48:16 -0400323 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800324 }
325
Jim Miller25190572013-02-28 17:36:24 -0800326 public synchronized void onScreenTurnedOn(final IKeyguardShowCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800327 if (DEBUG) Log.d(TAG, "onScreenTurnedOn()");
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700328 mScreenOn = true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800329 if (mKeyguardView != null) {
330 mKeyguardView.onScreenTurnedOn();
Jim Miller6edf2632011-09-05 16:03:14 -0700331
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700332 // Caller should wait for this window to be shown before turning
333 // on the screen.
Jim Miller25190572013-02-28 17:36:24 -0800334 if (callback != null) {
Craig Mautner904732c2012-10-17 15:20:24 -0700335 if (mKeyguardHost.getVisibility() == View.VISIBLE) {
336 // Keyguard may be in the process of being shown, but not yet
337 // updated with the window manager... give it a chance to do so.
338 mKeyguardHost.post(new Runnable() {
339 @Override
340 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800341 IBinder token = null;
Craig Mautner904732c2012-10-17 15:20:24 -0700342 if (mKeyguardHost.getVisibility() == View.VISIBLE) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800343 token = mKeyguardHost.getWindowToken();
344 }
345 try {
Jim Miller25190572013-02-28 17:36:24 -0800346 callback.onShown(token);
Jim Miller5ecd8112013-01-09 18:50:26 -0800347 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800348 Slog.w(TAG, "Exception calling onShown():", e);
Craig Mautner904732c2012-10-17 15:20:24 -0700349 }
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700350 }
Craig Mautner904732c2012-10-17 15:20:24 -0700351 });
352 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -0800353 try {
Jim Miller25190572013-02-28 17:36:24 -0800354 callback.onShown(null);
Jim Miller5ecd8112013-01-09 18:50:26 -0800355 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800356 Slog.w(TAG, "Exception calling onShown():", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800357 }
Craig Mautner904732c2012-10-17 15:20:24 -0700358 }
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700359 }
Jim Miller25190572013-02-28 17:36:24 -0800360 } else if (callback != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800361 try {
Jim Miller25190572013-02-28 17:36:24 -0800362 callback.onShown(null);
Jim Miller5ecd8112013-01-09 18:50:26 -0800363 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800364 Slog.w(TAG, "Exception calling onShown():", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800365 }
Brian Colonna15ea55a2011-09-09 11:48:16 -0400366 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800367 }
368
369 public synchronized void verifyUnlock() {
370 if (DEBUG) Log.d(TAG, "verifyUnlock()");
Adam Cohenf7522022012-10-03 20:03:18 -0700371 show(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800372 mKeyguardView.verifyUnlock();
373 }
374
375 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800376 * Hides the keyguard view
377 */
378 public synchronized void hide() {
379 if (DEBUG) Log.d(TAG, "hide()");
Jim Miller6edf2632011-09-05 16:03:14 -0700380
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800381 if (mKeyguardHost != null) {
382 mKeyguardHost.setVisibility(View.GONE);
Jim Miller223ce5c2012-10-05 19:13:23 -0700383
384 // We really only want to preserve keyguard state for configuration changes. Hence
385 // we should clear state of widgets (e.g. Music) when we hide keyguard so it can
386 // start with a fresh state when we return.
387 mStateContainer.clear();
388
Karl Rosaena35d7532009-09-25 10:24:26 -0700389 // Don't do this right away, so we can let the view continue to animate
Dianne Hackborn01ad2f42009-09-24 19:24:56 -0700390 // as it goes away.
Karl Rosaena35d7532009-09-25 10:24:26 -0700391 if (mKeyguardView != null) {
Jim Miller22dfe722009-10-07 01:30:21 -0700392 final KeyguardViewBase lastView = mKeyguardView;
393 mKeyguardView = null;
Karl Rosaena35d7532009-09-25 10:24:26 -0700394 mKeyguardHost.postDelayed(new Runnable() {
Craig Mautner904732c2012-10-17 15:20:24 -0700395 @Override
Karl Rosaena35d7532009-09-25 10:24:26 -0700396 public void run() {
Dianne Hackbornd7f7deb2009-09-25 17:35:10 -0700397 synchronized (KeyguardViewManager.this) {
Jim Miller22dfe722009-10-07 01:30:21 -0700398 lastView.cleanUp();
Jim Miller8b886fa2011-01-13 17:56:35 -0800399 mKeyguardHost.removeView(lastView);
Dianne Hackbornd7f7deb2009-09-25 17:35:10 -0700400 }
Karl Rosaena35d7532009-09-25 10:24:26 -0700401 }
402 }, 500);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800403 }
404 }
405 }
406
407 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700408 * Dismisses the keyguard by going to the next screen or making it gone.
409 */
410 public synchronized void dismiss() {
411 if (mScreenOn) {
412 mKeyguardView.dismiss();
413 }
414 }
415
416 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800417 * @return Whether the keyguard is showing
418 */
419 public synchronized boolean isShowing() {
420 return (mKeyguardHost != null && mKeyguardHost.getVisibility() == View.VISIBLE);
421 }
Jim Miller4eeb4f62012-11-08 00:04:29 -0800422
423 public void showAssistant() {
424 if (mKeyguardView != null) {
425 mKeyguardView.showAssistant();
426 }
427 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800428}