The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
| 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
| 18 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 19 | import com.android.internal.policy.IKeyguardShowCallback; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 20 | import com.android.internal.widget.LockPatternUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 21 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 24 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.pm.ActivityInfo; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Jim Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 29 | import android.graphics.PixelFormat; |
Jim Miller | 2b84b81 | 2012-11-30 15:42:18 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 32 | import android.os.IBinder; |
Jim Miller | 6bcd732 | 2012-10-02 16:32:04 -0700 | [diff] [blame] | 33 | import android.os.Parcelable; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 34 | import android.os.RemoteException; |
Jim Miller | 56bacd7 | 2011-09-09 14:12:54 -0700 | [diff] [blame] | 35 | import android.os.SystemProperties; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 36 | import android.util.Log; |
Craig Mautner | 0cbfcff | 2012-09-17 16:40:28 -0700 | [diff] [blame] | 37 | import android.util.Slog; |
Jim Miller | 6bcd732 | 2012-10-02 16:32:04 -0700 | [diff] [blame] | 38 | import android.util.SparseArray; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 39 | import android.view.KeyEvent; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.view.View; |
| 42 | import android.view.ViewGroup; |
| 43 | import android.view.ViewManager; |
| 44 | import android.view.WindowManager; |
| 45 | import android.widget.FrameLayout; |
| 46 | |
| 47 | /** |
| 48 | * Manages creating, showing, hiding and resetting the keyguard. Calls back |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 49 | * via {@link KeyguardViewMediator.ViewMediatorCallback} to poke |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 50 | * 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 53 | public class KeyguardViewManager { |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 54 | private final static boolean DEBUG = KeyguardViewMediator.DEBUG; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 55 | private static String TAG = "KeyguardViewManager"; |
Jim Miller | 3af630c | 2012-09-26 14:29:18 -0700 | [diff] [blame] | 56 | public static boolean USE_UPPER_CASE = true; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 57 | public final static String IS_SWITCHING_USER = "is_switching_user"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 58 | |
Jim Miller | 9cf2c52 | 2012-10-04 22:02:29 -0700 | [diff] [blame] | 59 | // Timeout used for keypresses |
| 60 | static final int DIGIT_PRESS_WAKE_MILLIS = 5000; |
| 61 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 62 | private final Context mContext; |
| 63 | private final ViewManager mViewManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 64 | private final KeyguardViewMediator.ViewMediatorCallback mViewMediatorCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 65 | |
| 66 | private WindowManager.LayoutParams mWindowLayoutParams; |
| 67 | private boolean mNeedsInput = false; |
Jim Miller | 22dfe72 | 2009-10-07 01:30:21 -0700 | [diff] [blame] | 68 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 69 | private FrameLayout mKeyguardHost; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 70 | private KeyguardHostView mKeyguardView; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 71 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 72 | private boolean mScreenOn = false; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 73 | private LockPatternUtils mLockPatternUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 74 | |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 75 | public interface ShowListener { |
| 76 | void onShown(IBinder windowToken); |
| 77 | }; |
| 78 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 79 | /** |
| 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 83 | * @param lockPatternUtils |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | */ |
| 85 | public KeyguardViewManager(Context context, ViewManager viewManager, |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 86 | KeyguardViewMediator.ViewMediatorCallback callback, |
| 87 | LockPatternUtils lockPatternUtils) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 88 | mContext = context; |
| 89 | mViewManager = viewManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 90 | mViewMediatorCallback = callback; |
| 91 | mLockPatternUtils = lockPatternUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Show the keyguard. Will handle creating and attaching to the view manager |
| 96 | * lazily. |
| 97 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 98 | public synchronized void show(Bundle options) { |
Daniel Sandler | 16541e4 | 2009-11-13 17:07:50 -0800 | [diff] [blame] | 99 | if (DEBUG) Log.d(TAG, "show(); mKeyguardView==" + mKeyguardView); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 100 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 101 | boolean enableScreenRotation = shouldEnableScreenRotation(); |
| 102 | |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 103 | maybeCreateKeyguardLocked(enableScreenRotation, false, options); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 104 | maybeEnableScreenRotation(enableScreenRotation); |
| 105 | |
Jim Miller | e23ab8b | 2012-09-16 15:45:44 -0700 | [diff] [blame] | 106 | // 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 Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 111 | if (DEBUG) Log.v(TAG, "show:setSystemUiVisibility(" + Integer.toHexString(visFlags)+")"); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 112 | 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 Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 121 | Resources res = mContext.getResources(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 122 | return SystemProperties.getBoolean("lockscreen.rot_override",false) |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 123 | || res.getBoolean(R.bool.config_enableLockScreenRotation); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | class ViewManagerHost extends FrameLayout { |
| 127 | public ViewManagerHost(Context context) { |
| 128 | super(context); |
Adam Powell | 5da6430 | 2012-11-05 14:16:59 -0800 | [diff] [blame] | 129 | setFitsSystemWindows(true); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
Jim Miller | 2b84b81 | 2012-11-30 15:42:18 -0800 | [diff] [blame] | 133 | protected boolean fitSystemWindows(Rect insets) { |
| 134 | Log.v("TAG", "bug 7643792: fitSystemWindows(" + insets.toShortString() + ")"); |
| 135 | return super.fitSystemWindows(insets); |
| 136 | } |
| 137 | |
| 138 | @Override |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 139 | protected void onConfigurationChanged(Configuration newConfig) { |
| 140 | super.onConfigurationChanged(newConfig); |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 141 | 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 147 | } |
Jim Miller | 0a34d9e | 2012-10-05 17:15:41 -0700 | [diff] [blame] | 148 | |
| 149 | @Override |
| 150 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jim Miller | 42df15e | 2012-12-05 15:15:00 -0800 | [diff] [blame] | 151 | 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 Miller | 0a34d9e | 2012-10-05 17:15:41 -0700 | [diff] [blame] | 163 | return true; |
| 164 | } |
| 165 | } |
| 166 | return super.dispatchKeyEvent(event); |
| 167 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Jim Miller | 6bcd732 | 2012-10-02 16:32:04 -0700 | [diff] [blame] | 170 | SparseArray<Parcelable> mStateContainer = new SparseArray<Parcelable>(); |
| 171 | |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 172 | private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean force, |
| 173 | Bundle options) { |
Jim Miller | 6bcd732 | 2012-10-02 16:32:04 -0700 | [diff] [blame] | 174 | if (mKeyguardHost != null) { |
| 175 | mKeyguardHost.saveHierarchyState(mStateContainer); |
| 176 | } |
| 177 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 178 | if (mKeyguardHost == null) { |
| 179 | if (DEBUG) Log.d(TAG, "keyguard host is null, creating it..."); |
| 180 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 181 | mKeyguardHost = new ViewManagerHost(mContext); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 182 | |
Adam Powell | 5da6430 | 2012-11-05 14:16:59 -0800 | [diff] [blame] | 183 | int flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 184 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Adam Powell | a9fa92e | 2012-11-08 00:03:34 -0800 | [diff] [blame] | 185 | | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN |
Jim Miller | d2b82f7 | 2012-09-18 20:52:55 -0700 | [diff] [blame] | 186 | | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 188 | if (!mNeedsInput) { |
| 189 | flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 190 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 191 | |
| 192 | final int stretch = ViewGroup.LayoutParams.MATCH_PARENT; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 193 | final int type = WindowManager.LayoutParams.TYPE_KEYGUARD; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 194 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 195 | stretch, stretch, type, flags, PixelFormat.TRANSLUCENT); |
Jim Miller | 6b05d58 | 2011-07-18 13:09:59 -0700 | [diff] [blame] | 196 | lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 197 | lp.windowAnimations = R.style.Animation_LockScreen; |
Jim Miller | 8e26cd8 | 2013-03-12 18:45:28 -0700 | [diff] [blame] | 198 | lp.screenOrientation = enableScreenRotation ? |
| 199 | ActivityInfo.SCREEN_ORIENTATION_USER : ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 200 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 201 | if (ActivityManager.isHighEndGfx()) { |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 202 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 203 | lp.privateFlags |= |
| 204 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 205 | } |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 206 | lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY; |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 207 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY; |
Jim Miller | cf182aa | 2013-06-28 16:55:56 -0700 | [diff] [blame] | 208 | lp.setTitle("Keyguard"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 209 | mWindowLayoutParams = lp; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 210 | mViewManager.addView(mKeyguardHost, lp); |
| 211 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 212 | |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 213 | if (force || mKeyguardView == null) { |
| 214 | inflateKeyguardView(options); |
Jim Miller | 147f956 | 2012-12-03 17:55:16 -0800 | [diff] [blame] | 215 | mKeyguardView.requestFocus(); |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 216 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 217 | updateUserActivityTimeoutInWindowLayoutParams(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 218 | mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams); |
Jim Miller | 6bcd732 | 2012-10-02 16:32:04 -0700 | [diff] [blame] | 219 | |
| 220 | mKeyguardHost.restoreHierarchyState(mStateContainer); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 221 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 222 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 223 | private void inflateKeyguardView(Bundle options) { |
Craig Mautner | 00baebe | 2012-09-28 15:22:39 -0700 | [diff] [blame] | 224 | View v = mKeyguardHost.findViewById(R.id.keyguard_host_view); |
| 225 | if (v != null) { |
| 226 | mKeyguardHost.removeView(v); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 227 | } |
| 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 Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 233 | mKeyguardView.initializeSwitchingUserState(options != null && |
| 234 | options.getBoolean(IS_SWITCHING_USER)); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 235 | |
Adam Powell | 70bc9f2 | 2012-10-12 22:02:27 -0700 | [diff] [blame] | 236 | // 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 Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 248 | if (options != null) { |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 249 | 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 Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 254 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 257 | 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 276 | private void maybeEnableScreenRotation(boolean enableScreenRotation) { |
| 277 | // TODO: move this outside |
Jim Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 278 | if (enableScreenRotation) { |
Jim Miller | f344735 | 2011-08-07 14:00:09 -0700 | [diff] [blame] | 279 | if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen On!"); |
Jim Miller | 82f9196 | 2012-07-24 13:33:08 -0700 | [diff] [blame] | 280 | mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER; |
Jim Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 281 | } else { |
Jim Miller | f344735 | 2011-08-07 14:00:09 -0700 | [diff] [blame] | 282 | if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen Off!"); |
Jim Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 283 | mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 284 | } |
Jim Miller | 06cc78a | 2011-06-02 16:10:16 -0700 | [diff] [blame] | 285 | mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 286 | } |
| 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 298 | |
| 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 Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
Jim Miller | 22dfe72 | 2009-10-07 01:30:21 -0700 | [diff] [blame] | 307 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 308 | /** |
| 309 | * Reset the state of the view. |
| 310 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 311 | public synchronized void reset(Bundle options) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 312 | if (DEBUG) Log.d(TAG, "reset()"); |
Amith Yamasani | d979dd7 | 2012-09-11 15:53:37 -0700 | [diff] [blame] | 313 | // 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 Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 315 | maybeCreateKeyguardLocked(shouldEnableScreenRotation(), true, options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | public synchronized void onScreenTurnedOff() { |
| 319 | if (DEBUG) Log.d(TAG, "onScreenTurnedOff()"); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 320 | mScreenOn = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 321 | if (mKeyguardView != null) { |
| 322 | mKeyguardView.onScreenTurnedOff(); |
Brian Colonna | 15ea55a | 2011-09-09 11:48:16 -0400 | [diff] [blame] | 323 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 326 | public synchronized void onScreenTurnedOn(final IKeyguardShowCallback callback) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 327 | if (DEBUG) Log.d(TAG, "onScreenTurnedOn()"); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 328 | mScreenOn = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 329 | if (mKeyguardView != null) { |
| 330 | mKeyguardView.onScreenTurnedOn(); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 331 | |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 332 | // Caller should wait for this window to be shown before turning |
| 333 | // on the screen. |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 334 | if (callback != null) { |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 335 | 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 341 | IBinder token = null; |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 342 | if (mKeyguardHost.getVisibility() == View.VISIBLE) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 343 | token = mKeyguardHost.getWindowToken(); |
| 344 | } |
| 345 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 346 | callback.onShown(token); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 347 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 348 | Slog.w(TAG, "Exception calling onShown():", e); |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 349 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 350 | } |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 351 | }); |
| 352 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 353 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 354 | callback.onShown(null); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 355 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 356 | Slog.w(TAG, "Exception calling onShown():", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 357 | } |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 358 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 359 | } |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 360 | } else if (callback != null) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 361 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 362 | callback.onShown(null); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 363 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 364 | Slog.w(TAG, "Exception calling onShown():", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 365 | } |
Brian Colonna | 15ea55a | 2011-09-09 11:48:16 -0400 | [diff] [blame] | 366 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | public synchronized void verifyUnlock() { |
| 370 | if (DEBUG) Log.d(TAG, "verifyUnlock()"); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 371 | show(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 372 | mKeyguardView.verifyUnlock(); |
| 373 | } |
| 374 | |
| 375 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 376 | * Hides the keyguard view |
| 377 | */ |
| 378 | public synchronized void hide() { |
| 379 | if (DEBUG) Log.d(TAG, "hide()"); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 380 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 381 | if (mKeyguardHost != null) { |
| 382 | mKeyguardHost.setVisibility(View.GONE); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 383 | |
| 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 Rosaen | a35d753 | 2009-09-25 10:24:26 -0700 | [diff] [blame] | 389 | // Don't do this right away, so we can let the view continue to animate |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 390 | // as it goes away. |
Karl Rosaen | a35d753 | 2009-09-25 10:24:26 -0700 | [diff] [blame] | 391 | if (mKeyguardView != null) { |
Jim Miller | 22dfe72 | 2009-10-07 01:30:21 -0700 | [diff] [blame] | 392 | final KeyguardViewBase lastView = mKeyguardView; |
| 393 | mKeyguardView = null; |
Karl Rosaen | a35d753 | 2009-09-25 10:24:26 -0700 | [diff] [blame] | 394 | mKeyguardHost.postDelayed(new Runnable() { |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 395 | @Override |
Karl Rosaen | a35d753 | 2009-09-25 10:24:26 -0700 | [diff] [blame] | 396 | public void run() { |
Dianne Hackborn | d7f7deb | 2009-09-25 17:35:10 -0700 | [diff] [blame] | 397 | synchronized (KeyguardViewManager.this) { |
Jim Miller | 22dfe72 | 2009-10-07 01:30:21 -0700 | [diff] [blame] | 398 | lastView.cleanUp(); |
Jim Miller | 8b886fa | 2011-01-13 17:56:35 -0800 | [diff] [blame] | 399 | mKeyguardHost.removeView(lastView); |
Dianne Hackborn | d7f7deb | 2009-09-25 17:35:10 -0700 | [diff] [blame] | 400 | } |
Karl Rosaen | a35d753 | 2009-09-25 10:24:26 -0700 | [diff] [blame] | 401 | } |
| 402 | }, 500); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 408 | * 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 Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 417 | * @return Whether the keyguard is showing |
| 418 | */ |
| 419 | public synchronized boolean isShowing() { |
| 420 | return (mKeyguardHost != null && mKeyguardHost.getVisibility() == View.VISIBLE); |
| 421 | } |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 422 | |
| 423 | public void showAssistant() { |
| 424 | if (mKeyguardView != null) { |
| 425 | mKeyguardView.showAssistant(); |
| 426 | } |
| 427 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 428 | } |