Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 19 | import com.android.internal.widget.LockPatternUtils; |
| 20 | import com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
| 21 | import com.android.keyguard.KeyguardUpdateMonitor.DisplayClientState; |
| 22 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 23 | import android.app.Activity; |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 25 | import android.app.ActivityOptions; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 26 | import android.app.AlertDialog; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 27 | import android.app.SearchManager; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 28 | import android.app.admin.DevicePolicyManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 29 | import android.appwidget.AppWidgetHost; |
| 30 | import android.appwidget.AppWidgetHostView; |
| 31 | import android.appwidget.AppWidgetManager; |
| 32 | import android.appwidget.AppWidgetProviderInfo; |
Michael Jurka | fc753c0 | 2012-10-30 18:30:52 -0700 | [diff] [blame] | 33 | import android.content.ComponentName; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
| 36 | import android.content.IntentSender; |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageManager.NameNotFoundException; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 38 | import android.content.pm.UserInfo; |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 39 | import android.content.res.Resources; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 40 | import android.graphics.Canvas; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 41 | import android.graphics.Rect; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 42 | import android.media.RemoteControlClient; |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 43 | import android.os.Looper; |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 44 | import android.os.Parcel; |
| 45 | import android.os.Parcelable; |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 46 | import android.os.SystemClock; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 47 | import android.os.UserHandle; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 48 | import android.os.UserManager; |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 49 | import android.provider.Settings; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 50 | import android.util.AttributeSet; |
| 51 | import android.util.Log; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 52 | import android.util.Slog; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 53 | import android.view.LayoutInflater; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 54 | import android.view.MotionEvent; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 55 | import android.view.View; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 56 | import android.view.WindowManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 57 | import android.widget.RemoteViews.OnClickHandler; |
| 58 | |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 59 | import java.io.File; |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 60 | import java.lang.ref.WeakReference; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 61 | import java.util.List; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 62 | |
| 63 | public class KeyguardHostView extends KeyguardViewBase { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 64 | private static final String TAG = "KeyguardHostView"; |
Sandeep Siddhartha | eec83dc | 2013-09-04 14:59:59 -0700 | [diff] [blame] | 65 | |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 66 | // Transport control states. |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 67 | static final int TRANSPORT_GONE = 0; |
| 68 | static final int TRANSPORT_INVISIBLE = 1; |
| 69 | static final int TRANSPORT_VISIBLE = 2; |
| 70 | |
| 71 | private int mTransportState = TRANSPORT_GONE; |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 72 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 73 | // Use this to debug all of keyguard |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 74 | public static boolean DEBUG = KeyguardViewMediator.DEBUG; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 75 | public static boolean DEBUGXPORT = true; // debug music transport control |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 76 | |
Michael Jurka | 192d6d4 | 2012-11-07 01:09:38 -0800 | [diff] [blame] | 77 | // Found in KeyguardAppWidgetPickActivity.java |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 78 | static final int APPWIDGET_HOST_ID = 0x4B455947; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 79 | |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 80 | private final int MAX_WIDGETS = 5; |
| 81 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 82 | private AppWidgetHost mAppWidgetHost; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 83 | private AppWidgetManager mAppWidgetManager; |
Jim Miller | f2dfc35 | 2012-08-29 18:42:21 -0700 | [diff] [blame] | 84 | private KeyguardWidgetPager mAppWidgetContainer; |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 85 | private KeyguardSecurityViewFlipper mSecurityViewContainer; |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 86 | private KeyguardSelectorView mKeyguardSelectorView; |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 87 | private KeyguardTransportControlView mTransportControl; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 88 | private boolean mIsVerifyUnlockOnly; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 89 | private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 90 | private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid; |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 91 | private int mAppWidgetToShow; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 92 | |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 93 | protected OnDismissAction mDismissAction; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 94 | |
| 95 | protected int mFailedAttempts; |
| 96 | private LockPatternUtils mLockPatternUtils; |
| 97 | |
| 98 | private KeyguardSecurityModel mSecurityModel; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 99 | private KeyguardViewStateManager mViewStateManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 100 | |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 101 | private Rect mTempRect = new Rect(); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 102 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 103 | private int mDisabledFeatures; |
| 104 | |
| 105 | private boolean mCameraDisabled; |
| 106 | |
| 107 | private boolean mSafeModeEnabled; |
| 108 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 109 | private boolean mUserSetupCompleted; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 110 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 111 | // User for whom this host view was created. Final because we should never change the |
| 112 | // id without reconstructing an instance of KeyguardHostView. See note below... |
| 113 | private final int mUserId; |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 114 | |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 115 | private KeyguardMultiUserSelectorView mKeyguardMultiUserSelectorView; |
| 116 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 117 | protected int mClientGeneration; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 118 | |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 119 | protected boolean mShowSecurityWhenReturn; |
| 120 | |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 121 | private final Rect mInsets = new Rect(); |
| 122 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 123 | private MyOnClickHandler mOnClickHandler = new MyOnClickHandler(this); |
| 124 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 125 | private Runnable mPostBootCompletedRunnable; |
| 126 | |
Adam Cohen | 24b351a | 2012-09-14 15:02:27 -0700 | [diff] [blame] | 127 | /*package*/ interface UserSwitcherCallback { |
| 128 | void hideSecurityView(int duration); |
| 129 | void showSecurityView(); |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 130 | void showUnlockHint(); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 131 | void userActivity(); |
Adam Cohen | 24b351a | 2012-09-14 15:02:27 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Adam Powell | f889524 | 2013-09-30 16:16:24 -0700 | [diff] [blame] | 134 | interface TransportControlCallback { |
| 135 | void userActivity(); |
| 136 | } |
| 137 | |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 138 | /*package*/ interface OnDismissAction { |
| 139 | /* returns true if the dismiss should be deferred */ |
| 140 | boolean onDismiss(); |
| 141 | } |
| 142 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 143 | public KeyguardHostView(Context context) { |
| 144 | this(context, null); |
| 145 | } |
| 146 | |
| 147 | public KeyguardHostView(Context context, AttributeSet attrs) { |
| 148 | super(context, attrs); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 149 | |
| 150 | if (DEBUG) Log.e(TAG, "KeyguardHostView()"); |
| 151 | |
Jim Miller | 000464a | 2012-09-04 16:45:06 -0700 | [diff] [blame] | 152 | mLockPatternUtils = new LockPatternUtils(context); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 153 | |
| 154 | // Note: This depends on KeyguardHostView getting reconstructed every time the |
| 155 | // user switches, since mUserId will be used for the entire session. |
| 156 | // Once created, keyguard should *never* re-use this instance with another user. |
| 157 | // In other words, mUserId should never change - hence it's marked final. |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 158 | mUserId = mLockPatternUtils.getCurrentUser(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 159 | |
Jim Miller | 105bedd | 2013-02-27 21:35:18 -0800 | [diff] [blame] | 160 | DevicePolicyManager dpm = |
| 161 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 162 | if (dpm != null) { |
| 163 | mDisabledFeatures = getDisabledFeatures(dpm); |
| 164 | mCameraDisabled = dpm.getCameraDisabled(null); |
| 165 | } |
| 166 | |
| 167 | mSafeModeEnabled = LockPatternUtils.isSafeModeEnabled(); |
| 168 | |
| 169 | // These need to be created with the user context... |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 170 | Context userContext = null; |
| 171 | try { |
| 172 | final String packageName = "system"; |
| 173 | userContext = mContext.createPackageContextAsUser(packageName, 0, |
| 174 | new UserHandle(mUserId)); |
| 175 | |
| 176 | } catch (NameNotFoundException e) { |
| 177 | e.printStackTrace(); |
| 178 | // This should never happen, but it's better to have no widgets than to crash. |
| 179 | userContext = context; |
| 180 | } |
| 181 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 182 | mAppWidgetHost = new AppWidgetHost(userContext, APPWIDGET_HOST_ID, mOnClickHandler, |
| 183 | Looper.myLooper()); |
Jim Miller | 105bedd | 2013-02-27 21:35:18 -0800 | [diff] [blame] | 184 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 185 | mAppWidgetManager = AppWidgetManager.getInstance(userContext); |
| 186 | |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 187 | mSecurityModel = new KeyguardSecurityModel(context); |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 188 | |
Adam Cohen | d6f8960 | 2012-11-06 11:46:25 -0800 | [diff] [blame] | 189 | mViewStateManager = new KeyguardViewStateManager(this); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 190 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 191 | mUserSetupCompleted = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 192 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 193 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 194 | // Ensure we have the current state *before* we call showAppropriateWidgetPage() |
| 195 | getInitialTransportState(); |
| 196 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 197 | if (mSafeModeEnabled) { |
| 198 | Log.v(TAG, "Keyguard widgets disabled by safe mode"); |
| 199 | } |
| 200 | if ((mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0) { |
| 201 | Log.v(TAG, "Keyguard widgets disabled by DPM"); |
| 202 | } |
| 203 | if ((mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0) { |
| 204 | Log.v(TAG, "Keyguard secure camera disabled by DPM"); |
| 205 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 208 | public void announceCurrentSecurityMethod() { |
| 209 | View v = (View) getSecurityView(mCurrentSecuritySelection); |
| 210 | if (v != null) { |
| 211 | v.announceForAccessibility(v.getContentDescription()); |
| 212 | } |
| 213 | } |
| 214 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 215 | private void getInitialTransportState() { |
| 216 | DisplayClientState dcs = KeyguardUpdateMonitor.getInstance(mContext) |
| 217 | .getCachedDisplayClientState(); |
| 218 | mTransportState = (dcs.clearing ? TRANSPORT_GONE : |
| 219 | (isMusicPlaying(dcs.playbackState) ? TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE)); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 220 | |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 221 | if (DEBUGXPORT) Log.v(TAG, "Initial transport state: " |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 222 | + mTransportState + ", pbstate=" + dcs.playbackState); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 225 | private void cleanupAppWidgetIds() { |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 226 | if (mSafeModeEnabled || widgetsDisabled()) return; |
| 227 | |
| 228 | // Clean up appWidgetIds that are bound to lockscreen, but not actually used |
| 229 | // This is only to clean up after another bug: we used to not call |
| 230 | // deleteAppWidgetId when a user manually deleted a widget in keyguard. This code |
| 231 | // shouldn't have to run more than once per user. AppWidgetProviders rely on callbacks |
| 232 | // that are triggered by deleteAppWidgetId, which is why we're doing this |
| 233 | int[] appWidgetIdsInKeyguardSettings = mLockPatternUtils.getAppWidgets(); |
| 234 | int[] appWidgetIdsBoundToHost = mAppWidgetHost.getAppWidgetIds(); |
| 235 | for (int i = 0; i < appWidgetIdsBoundToHost.length; i++) { |
| 236 | int appWidgetId = appWidgetIdsBoundToHost[i]; |
| 237 | if (!contains(appWidgetIdsInKeyguardSettings, appWidgetId)) { |
| 238 | Log.d(TAG, "Found a appWidgetId that's not being used by keyguard, deleting id " |
| 239 | + appWidgetId); |
| 240 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | private static boolean contains(int[] array, int target) { |
| 246 | for (int value : array) { |
| 247 | if (value == target) { |
| 248 | return true; |
| 249 | } |
| 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 254 | private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks = |
| 255 | new KeyguardUpdateMonitorCallback() { |
| 256 | @Override |
| 257 | public void onBootCompleted() { |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 258 | if (mPostBootCompletedRunnable != null) { |
| 259 | mPostBootCompletedRunnable.run(); |
| 260 | mPostBootCompletedRunnable = null; |
Michael Jurka | 545043e | 2012-11-21 14:02:34 -0800 | [diff] [blame] | 261 | } |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 262 | } |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 263 | @Override |
| 264 | public void onUserSwitchComplete(int userId) { |
| 265 | if (mKeyguardMultiUserSelectorView != null) { |
| 266 | mKeyguardMultiUserSelectorView.finalizeActiveUserView(true); |
| 267 | } |
| 268 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 269 | @Override |
| 270 | void onMusicClientIdChanged( |
| 271 | int clientGeneration, boolean clearing, android.app.PendingIntent intent) { |
| 272 | // Set transport state to invisible until we know music is playing (below) |
| 273 | if (DEBUGXPORT && (mClientGeneration != clientGeneration || clearing)) { |
| 274 | Log.v(TAG, (clearing ? "hide" : "show") + " transport, gen:" + clientGeneration); |
| 275 | } |
| 276 | mClientGeneration = clientGeneration; |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 277 | final int newState = (clearing ? TRANSPORT_GONE |
| 278 | : (mTransportState == TRANSPORT_VISIBLE ? |
| 279 | TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE)); |
| 280 | if (newState != mTransportState) { |
| 281 | mTransportState = newState; |
| 282 | if (DEBUGXPORT) Log.v(TAG, "update widget: transport state changed"); |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 283 | KeyguardHostView.this.post(mSwitchPageRunnable); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 284 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 285 | } |
| 286 | @Override |
| 287 | public void onMusicPlaybackStateChanged(int playbackState, long eventTime) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 288 | if (DEBUGXPORT) Log.v(TAG, "music state changed: " + playbackState); |
| 289 | if (mTransportState != TRANSPORT_GONE) { |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 290 | final int newState = (isMusicPlaying(playbackState) ? |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 291 | TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 292 | if (newState != mTransportState) { |
| 293 | mTransportState = newState; |
| 294 | if (DEBUGXPORT) Log.v(TAG, "update widget: play state changed"); |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 295 | KeyguardHostView.this.post(mSwitchPageRunnable); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 296 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 297 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 298 | } |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 299 | }; |
| 300 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 301 | private static final boolean isMusicPlaying(int playbackState) { |
| 302 | // This should agree with the list in AudioService.isPlaystateActive() |
| 303 | switch (playbackState) { |
| 304 | case RemoteControlClient.PLAYSTATE_PLAYING: |
| 305 | case RemoteControlClient.PLAYSTATE_BUFFERING: |
| 306 | case RemoteControlClient.PLAYSTATE_FAST_FORWARDING: |
| 307 | case RemoteControlClient.PLAYSTATE_REWINDING: |
| 308 | case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS: |
| 309 | case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS: |
| 310 | return true; |
| 311 | default: |
| 312 | return false; |
| 313 | } |
| 314 | } |
| 315 | |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 316 | private SlidingChallengeLayout mSlidingChallengeLayout; |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 317 | private MultiPaneChallengeLayout mMultiPaneChallengeLayout; |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 318 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 319 | @Override |
Jim Miller | d2b82f7 | 2012-09-18 20:52:55 -0700 | [diff] [blame] | 320 | public boolean onTouchEvent(MotionEvent ev) { |
| 321 | boolean result = super.onTouchEvent(ev); |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 322 | mTempRect.set(0, 0, 0, 0); |
| 323 | offsetRectIntoDescendantCoords(mSecurityViewContainer, mTempRect); |
| 324 | ev.offsetLocation(mTempRect.left, mTempRect.top); |
| 325 | result = mSecurityViewContainer.dispatchTouchEvent(ev) || result; |
| 326 | ev.offsetLocation(-mTempRect.left, -mTempRect.top); |
| 327 | return result; |
| 328 | } |
| 329 | |
| 330 | @Override |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 331 | protected void dispatchDraw(Canvas canvas) { |
| 332 | super.dispatchDraw(canvas); |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 333 | if (mViewMediatorCallback != null) { |
| 334 | mViewMediatorCallback.keyguardDoneDrawing(); |
| 335 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 338 | private int getWidgetPosition(int id) { |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 339 | final KeyguardWidgetPager appWidgetContainer = mAppWidgetContainer; |
| 340 | final int children = appWidgetContainer.getChildCount(); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 341 | for (int i = 0; i < children; i++) { |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 342 | final View content = appWidgetContainer.getWidgetPageAt(i).getContent(); |
| 343 | if (content != null && content.getId() == id) { |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 344 | return i; |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 345 | } else if (content == null) { |
| 346 | // Attempt to track down bug #8886916 |
| 347 | Log.w(TAG, "*** Null content at " + "i=" + i + ",id=" + id + ",N=" + children); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | return -1; |
| 351 | } |
| 352 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 353 | @Override |
| 354 | protected void onFinishInflate() { |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 355 | // Grab instances of and make any necessary changes to the main layouts. Create |
| 356 | // view state manager and wire up necessary listeners / callbacks. |
Winson Chung | f3b9ec8 | 2012-11-01 14:48:51 -0700 | [diff] [blame] | 357 | View deleteDropTarget = findViewById(R.id.keyguard_widget_pager_delete_target); |
Jim Miller | f2dfc35 | 2012-08-29 18:42:21 -0700 | [diff] [blame] | 358 | mAppWidgetContainer = (KeyguardWidgetPager) findViewById(R.id.app_widget_container); |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 359 | mAppWidgetContainer.setVisibility(VISIBLE); |
| 360 | mAppWidgetContainer.setCallbacks(mWidgetCallbacks); |
Winson Chung | f3b9ec8 | 2012-11-01 14:48:51 -0700 | [diff] [blame] | 361 | mAppWidgetContainer.setDeleteDropTarget(deleteDropTarget); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 362 | mAppWidgetContainer.setMinScale(0.5f); |
| 363 | |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 364 | mSlidingChallengeLayout = (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 365 | if (mSlidingChallengeLayout != null) { |
| 366 | mSlidingChallengeLayout.setOnChallengeScrolledListener(mViewStateManager); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 367 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 368 | mAppWidgetContainer.setViewStateManager(mViewStateManager); |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 369 | mAppWidgetContainer.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 370 | |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 371 | mMultiPaneChallengeLayout = |
| 372 | (MultiPaneChallengeLayout) findViewById(R.id.multi_pane_challenge); |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 373 | ChallengeLayout challenge = mSlidingChallengeLayout != null ? mSlidingChallengeLayout : |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 374 | mMultiPaneChallengeLayout; |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 375 | challenge.setOnBouncerStateChangedListener(mViewStateManager); |
Winson Chung | 70c2f87 | 2012-11-07 21:47:12 -0800 | [diff] [blame] | 376 | mAppWidgetContainer.setBouncerAnimationDuration(challenge.getBouncerAnimationDuration()); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 377 | mViewStateManager.setPagedView(mAppWidgetContainer); |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 378 | mViewStateManager.setChallengeLayout(challenge); |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 379 | mSecurityViewContainer = (KeyguardSecurityViewFlipper) findViewById(R.id.view_flipper); |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 380 | mKeyguardSelectorView = (KeyguardSelectorView) findViewById(R.id.keyguard_selector_view); |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 381 | mViewStateManager.setSecurityViewContainer(mSecurityViewContainer); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 382 | |
John Spurlock | 03eca85 | 2013-03-14 14:21:04 -0400 | [diff] [blame] | 383 | setBackButtonEnabled(false); |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 384 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 385 | if (KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) { |
| 386 | updateAndAddWidgets(); |
| 387 | } else { |
| 388 | // We can't add widgets until after boot completes because AppWidgetHost may try |
| 389 | // to contact the providers. Do it later. |
| 390 | mPostBootCompletedRunnable = new Runnable() { |
| 391 | @Override |
| 392 | public void run() { |
| 393 | updateAndAddWidgets(); |
| 394 | } |
| 395 | }; |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 396 | } |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 397 | |
| 398 | showPrimarySecurityScreen(false); |
| 399 | updateSecurityViews(); |
| 400 | enableUserSelectorIfNecessary(); |
| 401 | } |
| 402 | |
| 403 | private void updateAndAddWidgets() { |
| 404 | cleanupAppWidgetIds(); |
| 405 | addDefaultWidgets(); |
| 406 | addWidgetsFromSettings(); |
| 407 | maybeEnableAddButton(); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 408 | checkAppWidgetConsistency(); |
Jim Miller | 5547b55 | 2013-10-07 19:20:56 -0700 | [diff] [blame] | 409 | |
| 410 | // Don't let the user drag the challenge down if widgets are disabled. |
| 411 | if (mSlidingChallengeLayout != null) { |
| 412 | mSlidingChallengeLayout.setEnableChallengeDragging(!widgetsDisabled()); |
| 413 | } |
| 414 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 415 | // Select the appropriate page |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 416 | mSwitchPageRunnable.run(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 417 | |
Adam Cohen | 45adaa7 | 2012-11-02 22:00:57 -0700 | [diff] [blame] | 418 | // This needs to be called after the pages are all added. |
| 419 | mViewStateManager.showUsabilityHints(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 420 | } |
Adam Cohen | 45adaa7 | 2012-11-02 22:00:57 -0700 | [diff] [blame] | 421 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 422 | private void maybeEnableAddButton() { |
| 423 | if (!shouldEnableAddWidget()) { |
| 424 | mAppWidgetContainer.setAddWidgetEnabled(false); |
| 425 | } |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 426 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 427 | |
John Spurlock | 03eca85 | 2013-03-14 14:21:04 -0400 | [diff] [blame] | 428 | private void setBackButtonEnabled(boolean enabled) { |
| 429 | if (mContext instanceof Activity) return; // always enabled in activity mode |
| 430 | setSystemUiVisibility(enabled ? |
| 431 | getSystemUiVisibility() & ~View.STATUS_BAR_DISABLE_BACK : |
| 432 | getSystemUiVisibility() | View.STATUS_BAR_DISABLE_BACK); |
| 433 | } |
| 434 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 435 | private boolean shouldEnableAddWidget() { |
| 436 | return numWidgets() < MAX_WIDGETS && mUserSetupCompleted; |
| 437 | } |
| 438 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 439 | private int getDisabledFeatures(DevicePolicyManager dpm) { |
| 440 | int disabledFeatures = DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE; |
| 441 | if (dpm != null) { |
| 442 | final int currentUser = mLockPatternUtils.getCurrentUser(); |
| 443 | disabledFeatures = dpm.getKeyguardDisabledFeatures(null, currentUser); |
| 444 | } |
| 445 | return disabledFeatures; |
| 446 | } |
| 447 | |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 448 | private boolean widgetsDisabled() { |
Jim Miller | 461b345 | 2013-09-29 14:00:01 -0700 | [diff] [blame] | 449 | boolean disabledByLowRamDevice = ActivityManager.isLowRamDeviceStatic(); |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 450 | boolean disabledByDpm = |
| 451 | (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; |
| 452 | boolean disabledByUser = !mLockPatternUtils.getWidgetsEnabled(); |
Jim Miller | 461b345 | 2013-09-29 14:00:01 -0700 | [diff] [blame] | 453 | return disabledByLowRamDevice || disabledByDpm || disabledByUser; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | private boolean cameraDisabledByDpm() { |
| 457 | return mCameraDisabled |
| 458 | || (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0; |
| 459 | } |
| 460 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 461 | private void updateSecurityViews() { |
| 462 | int children = mSecurityViewContainer.getChildCount(); |
| 463 | for (int i = 0; i < children; i++) { |
| 464 | updateSecurityView(mSecurityViewContainer.getChildAt(i)); |
| 465 | } |
| 466 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 467 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 468 | private void updateSecurityView(View view) { |
| 469 | if (view instanceof KeyguardSecurityView) { |
| 470 | KeyguardSecurityView ksv = (KeyguardSecurityView) view; |
| 471 | ksv.setKeyguardCallback(mCallback); |
| 472 | ksv.setLockPatternUtils(mLockPatternUtils); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 473 | if (mViewStateManager.isBouncing()) { |
| 474 | ksv.showBouncer(0); |
| 475 | } else { |
| 476 | ksv.hideBouncer(0); |
| 477 | } |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 478 | } else { |
| 479 | Log.w(TAG, "View " + view + " is not a KeyguardSecurityView"); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 480 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void setLockPatternUtils(LockPatternUtils utils) { |
| 484 | mSecurityModel.setLockPatternUtils(utils); |
| 485 | mLockPatternUtils = utils; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 486 | updateSecurityViews(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | @Override |
| 490 | protected void onAttachedToWindow() { |
| 491 | super.onAttachedToWindow(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 492 | mAppWidgetHost.startListening(); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 493 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks); |
Jim Miller | 7221d3a | 2012-10-05 14:34:47 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 496 | @Override |
| 497 | protected void onDetachedFromWindow() { |
| 498 | super.onDetachedFromWindow(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 499 | mAppWidgetHost.stopListening(); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 500 | KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 503 | void addWidget(AppWidgetHostView view, int pageIndex) { |
| 504 | mAppWidgetContainer.addWidget(view, pageIndex); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 507 | private KeyguardWidgetPager.Callbacks mWidgetCallbacks |
| 508 | = new KeyguardWidgetPager.Callbacks() { |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 509 | @Override |
| 510 | public void userActivity() { |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 511 | KeyguardHostView.this.userActivity(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | @Override |
| 515 | public void onUserActivityTimeoutChanged() { |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 516 | KeyguardHostView.this.onUserActivityTimeoutChanged(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 517 | } |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 518 | |
| 519 | @Override |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 520 | public void onAddView(View v) { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 521 | if (!shouldEnableAddWidget()) { |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 522 | mAppWidgetContainer.setAddWidgetEnabled(false); |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 523 | } |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 524 | } |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 525 | |
| 526 | @Override |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 527 | public void onRemoveView(View v, boolean deletePermanently) { |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 528 | if (deletePermanently) { |
| 529 | final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId(); |
| 530 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && |
| 531 | appWidgetId != LockPatternUtils.ID_DEFAULT_STATUS_WIDGET) { |
| 532 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 533 | } |
| 534 | } |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 535 | } |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 536 | |
| 537 | @Override |
| 538 | public void onRemoveViewAnimationCompleted() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 539 | if (shouldEnableAddWidget()) { |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 540 | mAppWidgetContainer.setAddWidgetEnabled(true); |
| 541 | } |
| 542 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 543 | }; |
| 544 | |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 545 | public void initializeSwitchingUserState(boolean switching) { |
| 546 | if (!switching && mKeyguardMultiUserSelectorView != null) { |
| 547 | mKeyguardMultiUserSelectorView.finalizeActiveUserView(false); |
| 548 | } |
| 549 | } |
| 550 | |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 551 | public void userActivity() { |
| 552 | if (mViewMediatorCallback != null) { |
| 553 | mViewMediatorCallback.userActivity(); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | public void onUserActivityTimeoutChanged() { |
| 558 | if (mViewMediatorCallback != null) { |
| 559 | mViewMediatorCallback.onUserActivityTimeoutChanged(); |
| 560 | } |
| 561 | } |
| 562 | |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 563 | @Override |
| 564 | public long getUserActivityTimeout() { |
| 565 | // Currently only considering user activity timeouts needed by widgets. |
| 566 | // Could also take into account longer timeouts for certain security views. |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 567 | if (mAppWidgetContainer != null) { |
| 568 | return mAppWidgetContainer.getUserActivityTimeout(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 569 | } |
| 570 | return -1; |
| 571 | } |
| 572 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 573 | private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() { |
| 574 | |
| 575 | public void userActivity(long timeout) { |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 576 | if (mViewMediatorCallback != null) { |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 577 | mViewMediatorCallback.userActivity(timeout); |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 578 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | public void dismiss(boolean authenticated) { |
| 582 | showNextSecurityScreenOrFinish(authenticated); |
| 583 | } |
| 584 | |
| 585 | public boolean isVerifyUnlockOnly() { |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 586 | return mIsVerifyUnlockOnly; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | public void reportSuccessfulUnlockAttempt() { |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 590 | KeyguardUpdateMonitor.getInstance(mContext).clearFailedUnlockAttempts(); |
Jim Miller | 7641506 | 2012-09-24 18:38:08 -0700 | [diff] [blame] | 591 | mLockPatternUtils.reportSuccessfulPasswordAttempt(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | public void reportFailedUnlockAttempt() { |
Jim Miller | 7641506 | 2012-09-24 18:38:08 -0700 | [diff] [blame] | 595 | if (mCurrentSecuritySelection == SecurityMode.Biometric) { |
| 596 | KeyguardUpdateMonitor.getInstance(mContext).reportFailedBiometricUnlockAttempt(); |
| 597 | } else { |
| 598 | KeyguardHostView.this.reportFailedUnlockAttempt(); |
| 599 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | public int getFailedAttempts() { |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 603 | return KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 606 | @Override |
| 607 | public void showBackupSecurity() { |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 608 | KeyguardHostView.this.showBackupSecurityScreen(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 611 | @Override |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 612 | public void setOnDismissAction(OnDismissAction action) { |
| 613 | KeyguardHostView.this.setOnDismissAction(action); |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 616 | }; |
| 617 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 618 | private void showDialog(String title, String message) { |
| 619 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 620 | .setTitle(title) |
| 621 | .setMessage(message) |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 622 | .setNeutralButton(R.string.ok, null) |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 623 | .create(); |
| 624 | if (!(mContext instanceof Activity)) { |
| 625 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
| 626 | } |
| 627 | dialog.show(); |
| 628 | } |
| 629 | |
| 630 | private void showTimeoutDialog() { |
| 631 | int timeoutInSeconds = (int) LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS / 1000; |
| 632 | int messageId = 0; |
| 633 | |
| 634 | switch (mSecurityModel.getSecurityMode()) { |
| 635 | case Pattern: |
| 636 | messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message; |
| 637 | break; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 638 | case PIN: |
| 639 | messageId = R.string.kg_too_many_failed_pin_attempts_dialog_message; |
| 640 | break; |
| 641 | case Password: |
| 642 | messageId = R.string.kg_too_many_failed_password_attempts_dialog_message; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 643 | break; |
| 644 | } |
| 645 | |
| 646 | if (messageId != 0) { |
| 647 | final String message = mContext.getString(messageId, |
| 648 | KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(), |
| 649 | timeoutInSeconds); |
| 650 | showDialog(null, message); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | private void showAlmostAtWipeDialog(int attempts, int remaining) { |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 655 | String message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe, |
| 656 | attempts, remaining); |
| 657 | showDialog(null, message); |
| 658 | } |
| 659 | |
| 660 | private void showWipeDialog(int attempts) { |
| 661 | String message = mContext.getString(R.string.kg_failed_attempts_now_wiping, attempts); |
| 662 | showDialog(null, message); |
| 663 | } |
| 664 | |
| 665 | private void showAlmostAtAccountLoginDialog() { |
| 666 | final int timeoutInSeconds = (int) LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS / 1000; |
| 667 | final int count = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET |
| 668 | - LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT; |
| 669 | String message = mContext.getString(R.string.kg_failed_attempts_almost_at_login, |
| 670 | count, LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT, timeoutInSeconds); |
| 671 | showDialog(null, message); |
| 672 | } |
| 673 | |
| 674 | private void reportFailedUnlockAttempt() { |
| 675 | final KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 676 | final int failedAttempts = monitor.getFailedUnlockAttempts() + 1; // +1 for this time |
| 677 | |
| 678 | if (DEBUG) Log.d(TAG, "reportFailedPatternAttempt: #" + failedAttempts); |
| 679 | |
| 680 | SecurityMode mode = mSecurityModel.getSecurityMode(); |
| 681 | final boolean usingPattern = mode == KeyguardSecurityModel.SecurityMode.Pattern; |
| 682 | |
| 683 | final int failedAttemptsBeforeWipe = mLockPatternUtils.getDevicePolicyManager() |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 684 | .getMaximumFailedPasswordsForWipe(null, mLockPatternUtils.getCurrentUser()); |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 685 | |
| 686 | final int failedAttemptWarning = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET |
| 687 | - LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT; |
| 688 | |
| 689 | final int remainingBeforeWipe = failedAttemptsBeforeWipe > 0 ? |
| 690 | (failedAttemptsBeforeWipe - failedAttempts) |
| 691 | : Integer.MAX_VALUE; // because DPM returns 0 if no restriction |
| 692 | |
Jim Miller | 08b2b6b | 2012-09-14 19:12:40 -0700 | [diff] [blame] | 693 | boolean showTimeout = false; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 694 | if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) { |
| 695 | // If we reach this code, it means the user has installed a DevicePolicyManager |
| 696 | // that requests device wipe after N attempts. Once we get below the grace |
| 697 | // period, we'll post this dialog every time as a clear warning until the |
| 698 | // bombshell hits and the device is wiped. |
| 699 | if (remainingBeforeWipe > 0) { |
| 700 | showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe); |
| 701 | } else { |
| 702 | // Too many attempts. The device will be wiped shortly. |
| 703 | Slog.i(TAG, "Too many unlock attempts; device will be wiped!"); |
| 704 | showWipeDialog(failedAttempts); |
| 705 | } |
| 706 | } else { |
Jim Miller | 08b2b6b | 2012-09-14 19:12:40 -0700 | [diff] [blame] | 707 | showTimeout = |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 708 | (failedAttempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) == 0; |
| 709 | if (usingPattern && mEnableFallback) { |
| 710 | if (failedAttempts == failedAttemptWarning) { |
| 711 | showAlmostAtAccountLoginDialog(); |
| 712 | showTimeout = false; // don't show both dialogs |
| 713 | } else if (failedAttempts >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET) { |
| 714 | mLockPatternUtils.setPermanentlyLocked(true); |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 715 | showSecurityScreen(SecurityMode.Account); |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 716 | // don't show timeout dialog because we show account unlock screen next |
| 717 | showTimeout = false; |
| 718 | } |
| 719 | } |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 720 | } |
| 721 | monitor.reportFailedUnlockAttempt(); |
| 722 | mLockPatternUtils.reportFailedPasswordAttempt(); |
Jim Miller | 08b2b6b | 2012-09-14 19:12:40 -0700 | [diff] [blame] | 723 | if (showTimeout) { |
| 724 | showTimeoutDialog(); |
| 725 | } |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 729 | * Shows the primary security screen for the user. This will be either the multi-selector |
| 730 | * or the user's security method. |
| 731 | * @param turningOff true if the device is being turned off |
| 732 | */ |
| 733 | void showPrimarySecurityScreen(boolean turningOff) { |
| 734 | SecurityMode securityMode = mSecurityModel.getSecurityMode(); |
| 735 | if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")"); |
Brian Colonna | 078f591 | 2012-10-31 20:03:18 -0400 | [diff] [blame] | 736 | if (!turningOff && |
| 737 | KeyguardUpdateMonitor.getInstance(mContext).isAlternateUnlockEnabled()) { |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 738 | // If we're not turning off, then allow biometric alternate. |
| 739 | // We'll reload it when the device comes back on. |
| 740 | securityMode = mSecurityModel.getAlternateFor(securityMode); |
| 741 | } |
| 742 | showSecurityScreen(securityMode); |
| 743 | } |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 744 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 745 | /** |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 746 | * Shows the backup security screen for the current security mode. This could be used for |
| 747 | * password recovery screens but is currently only used for pattern unlock to show the |
| 748 | * account unlock screen and biometric unlock to show the user's normal unlock. |
| 749 | */ |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 750 | private void showBackupSecurityScreen() { |
Danielle Millett | 61413b5 | 2012-10-09 18:07:02 -0400 | [diff] [blame] | 751 | if (DEBUG) Log.d(TAG, "showBackupSecurity()"); |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 752 | SecurityMode backup = mSecurityModel.getBackupSecurityMode(mCurrentSecuritySelection); |
| 753 | showSecurityScreen(backup); |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 756 | public boolean showNextSecurityScreenIfPresent() { |
| 757 | SecurityMode securityMode = mSecurityModel.getSecurityMode(); |
| 758 | // Allow an alternate, such as biometric unlock |
| 759 | securityMode = mSecurityModel.getAlternateFor(securityMode); |
| 760 | if (SecurityMode.None == securityMode) { |
| 761 | return false; |
| 762 | } else { |
| 763 | showSecurityScreen(securityMode); // switch to the alternate security view |
| 764 | return true; |
| 765 | } |
| 766 | } |
| 767 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 768 | private void showNextSecurityScreenOrFinish(boolean authenticated) { |
Danielle Millett | 61413b5 | 2012-10-09 18:07:02 -0400 | [diff] [blame] | 769 | if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")"); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 770 | boolean finish = false; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 771 | if (SecurityMode.None == mCurrentSecuritySelection) { |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 772 | SecurityMode securityMode = mSecurityModel.getSecurityMode(); |
| 773 | // Allow an alternate, such as biometric unlock |
Jim Miller | 000464a | 2012-09-04 16:45:06 -0700 | [diff] [blame] | 774 | securityMode = mSecurityModel.getAlternateFor(securityMode); |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 775 | if (SecurityMode.None == securityMode) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 776 | finish = true; // no security required |
| 777 | } else { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 778 | showSecurityScreen(securityMode); // switch to the alternate security view |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 779 | } |
| 780 | } else if (authenticated) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 781 | switch (mCurrentSecuritySelection) { |
| 782 | case Pattern: |
| 783 | case Password: |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 784 | case PIN: |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 785 | case Account: |
| 786 | case Biometric: |
Jim Miller | 4b09dd3 | 2012-09-04 14:27:25 -0700 | [diff] [blame] | 787 | finish = true; |
| 788 | break; |
| 789 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 790 | case SimPin: |
| 791 | case SimPuk: |
Jim Miller | 4b09dd3 | 2012-09-04 14:27:25 -0700 | [diff] [blame] | 792 | // Shortcut for SIM PIN/PUK to go to directly to user's security screen or home |
| 793 | SecurityMode securityMode = mSecurityModel.getSecurityMode(); |
| 794 | if (securityMode != SecurityMode.None) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 795 | showSecurityScreen(securityMode); |
Jim Miller | 4b09dd3 | 2012-09-04 14:27:25 -0700 | [diff] [blame] | 796 | } else { |
| 797 | finish = true; |
| 798 | } |
| 799 | break; |
| 800 | |
| 801 | default: |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 802 | Log.v(TAG, "Bad security screen " + mCurrentSecuritySelection + ", fail safe"); |
| 803 | showPrimarySecurityScreen(false); |
Jim Miller | 4b09dd3 | 2012-09-04 14:27:25 -0700 | [diff] [blame] | 804 | break; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 805 | } |
| 806 | } else { |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 807 | showPrimarySecurityScreen(false); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 808 | } |
| 809 | if (finish) { |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 810 | // If the alternate unlock was suppressed, it can now be safely |
| 811 | // enabled because the user has left keyguard. |
| 812 | KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 813 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 814 | // If there's a pending runnable because the user interacted with a widget |
| 815 | // and we're leaving keyguard, then run it. |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 816 | boolean deferKeyguardDone = false; |
| 817 | if (mDismissAction != null) { |
| 818 | deferKeyguardDone = mDismissAction.onDismiss(); |
| 819 | mDismissAction = null; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 820 | } |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 821 | if (mViewMediatorCallback != null) { |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 822 | if (deferKeyguardDone) { |
| 823 | mViewMediatorCallback.keyguardDonePending(); |
| 824 | } else { |
| 825 | mViewMediatorCallback.keyguardDone(true); |
| 826 | } |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 827 | } |
Jim Miller | b5f3b70 | 2012-10-21 19:09:23 -0700 | [diff] [blame] | 828 | } else { |
| 829 | mViewStateManager.showBouncer(true); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 833 | private static class MyOnClickHandler extends OnClickHandler { |
| 834 | |
| 835 | // weak reference to the hostView to avoid keeping a live reference |
| 836 | // due to Binder GC linkages to AppWidgetHost. By the same token, |
| 837 | // this click handler should not keep references to any large |
| 838 | // objects. |
| 839 | WeakReference<KeyguardHostView> mThis; |
| 840 | |
| 841 | MyOnClickHandler(KeyguardHostView hostView) { |
| 842 | mThis = new WeakReference<KeyguardHostView>(hostView); |
| 843 | } |
| 844 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 845 | @Override |
| 846 | public boolean onClickHandler(final View view, |
| 847 | final android.app.PendingIntent pendingIntent, |
| 848 | final Intent fillInIntent) { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 849 | KeyguardHostView hostView = mThis.get(); |
| 850 | if (hostView == null) { |
| 851 | return false; |
| 852 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 853 | if (pendingIntent.isActivity()) { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 854 | hostView.setOnDismissAction(new OnDismissAction() { |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 855 | public boolean onDismiss() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 856 | try { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 857 | // TODO: Unregister this handler if PendingIntent.FLAG_ONE_SHOT? |
| 858 | Context context = view.getContext(); |
| 859 | ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, |
| 860 | 0, 0, |
| 861 | view.getMeasuredWidth(), view.getMeasuredHeight()); |
| 862 | context.startIntentSender( |
| 863 | pendingIntent.getIntentSender(), fillInIntent, |
| 864 | Intent.FLAG_ACTIVITY_NEW_TASK, |
| 865 | Intent.FLAG_ACTIVITY_NEW_TASK, 0, opts.toBundle()); |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 866 | } catch (IntentSender.SendIntentException e) { |
| 867 | android.util.Log.e(TAG, "Cannot send pending intent: ", e); |
| 868 | } catch (Exception e) { |
| 869 | android.util.Log.e(TAG, "Cannot send pending intent due to " + |
| 870 | "unknown exception: ", e); |
| 871 | } |
| 872 | return false; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 873 | } |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 874 | }); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 875 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 876 | if (hostView.mViewStateManager.isChallengeShowing()) { |
| 877 | hostView.mViewStateManager.showBouncer(true); |
Jim Miller | 0889837 | 2012-11-04 19:08:40 -0800 | [diff] [blame] | 878 | } else { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 879 | hostView.mCallback.dismiss(false); |
Jim Miller | 0889837 | 2012-11-04 19:08:40 -0800 | [diff] [blame] | 880 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 881 | return true; |
| 882 | } else { |
| 883 | return super.onClickHandler(view, pendingIntent, fillInIntent); |
| 884 | } |
| 885 | }; |
| 886 | }; |
| 887 | |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 888 | // Used to ignore callbacks from methods that are no longer current (e.g. face unlock). |
| 889 | // This avoids unwanted asynchronous events from messing with the state. |
| 890 | private KeyguardSecurityCallback mNullCallback = new KeyguardSecurityCallback() { |
| 891 | |
| 892 | @Override |
| 893 | public void userActivity(long timeout) { |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public void showBackupSecurity() { |
| 898 | } |
| 899 | |
| 900 | @Override |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 901 | public void setOnDismissAction(OnDismissAction action) { |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | @Override |
| 905 | public void reportSuccessfulUnlockAttempt() { |
| 906 | } |
| 907 | |
| 908 | @Override |
| 909 | public void reportFailedUnlockAttempt() { |
| 910 | } |
| 911 | |
| 912 | @Override |
| 913 | public boolean isVerifyUnlockOnly() { |
| 914 | return false; |
| 915 | } |
| 916 | |
| 917 | @Override |
| 918 | public int getFailedAttempts() { |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | @Override |
| 923 | public void dismiss(boolean securityVerified) { |
| 924 | } |
| 925 | }; |
| 926 | |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 927 | /** |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 928 | * Sets an action to perform when keyguard is dismissed. |
| 929 | * @param action |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 930 | */ |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 931 | protected void setOnDismissAction(OnDismissAction action) { |
| 932 | mDismissAction = action; |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 935 | private KeyguardSecurityView getSecurityView(SecurityMode securityMode) { |
| 936 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
| 937 | KeyguardSecurityView view = null; |
| 938 | final int children = mSecurityViewContainer.getChildCount(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 939 | for (int child = 0; child < children; child++) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 940 | if (mSecurityViewContainer.getChildAt(child).getId() == securityViewIdForMode) { |
| 941 | view = ((KeyguardSecurityView)mSecurityViewContainer.getChildAt(child)); |
| 942 | break; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 943 | } |
| 944 | } |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 945 | int layoutId = getLayoutIdFor(securityMode); |
| 946 | if (view == null && layoutId != 0) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 947 | final LayoutInflater inflater = LayoutInflater.from(mContext); |
Jim Miller | bdffd5c | 2012-10-15 22:11:52 -0700 | [diff] [blame] | 948 | if (DEBUG) Log.v(TAG, "inflating id = " + layoutId); |
Adam Powell | 9799714 | 2012-11-06 21:32:42 -0800 | [diff] [blame] | 949 | View v = inflater.inflate(layoutId, mSecurityViewContainer, false); |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 950 | mSecurityViewContainer.addView(v); |
| 951 | updateSecurityView(v); |
Jim Miller | 0b72824 | 2012-10-28 19:42:30 -0700 | [diff] [blame] | 952 | view = (KeyguardSecurityView)v; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 953 | } |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 954 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 955 | if (view instanceof KeyguardSelectorView) { |
| 956 | KeyguardSelectorView selectorView = (KeyguardSelectorView) view; |
| 957 | View carrierText = selectorView.findViewById(R.id.keyguard_selector_fade_container); |
| 958 | selectorView.setCarrierArea(carrierText); |
| 959 | } |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 960 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 961 | return view; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 964 | /** |
| 965 | * Switches to the given security view unless it's already being shown, in which case |
| 966 | * this is a no-op. |
| 967 | * |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 968 | * @param securityMode |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 969 | */ |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 970 | private void showSecurityScreen(SecurityMode securityMode) { |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 971 | if (DEBUG) Log.d(TAG, "showSecurityScreen(" + securityMode + ")"); |
| 972 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 973 | if (securityMode == mCurrentSecuritySelection) return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 974 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 975 | KeyguardSecurityView oldView = getSecurityView(mCurrentSecuritySelection); |
| 976 | KeyguardSecurityView newView = getSecurityView(securityMode); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 977 | |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 978 | // Enter full screen mode if we're in SIM or Account screen |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 979 | boolean fullScreenEnabled = getResources().getBoolean(R.bool.kg_sim_puk_account_full_screen); |
Jim Miller | a71984f | 2012-10-24 22:08:49 -0700 | [diff] [blame] | 980 | boolean isSimOrAccount = securityMode == SecurityMode.SimPin |
| 981 | || securityMode == SecurityMode.SimPuk |
| 982 | || securityMode == SecurityMode.Account; |
| 983 | mAppWidgetContainer.setVisibility( |
| 984 | isSimOrAccount && fullScreenEnabled ? View.GONE : View.VISIBLE); |
| 985 | |
Jim Miller | 9c993bd | 2013-10-07 17:12:27 -0700 | [diff] [blame] | 986 | // Don't show camera or search in navbar when SIM or Account screen is showing |
| 987 | setSystemUiVisibility(isSimOrAccount ? |
| 988 | (getSystemUiVisibility() | View.STATUS_BAR_DISABLE_SEARCH) |
| 989 | : (getSystemUiVisibility() & ~View.STATUS_BAR_DISABLE_SEARCH)); |
| 990 | |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 991 | if (mSlidingChallengeLayout != null) { |
| 992 | mSlidingChallengeLayout.setChallengeInteractive(!fullScreenEnabled); |
| 993 | } |
| 994 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 995 | // Emulate Activity life cycle |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 996 | if (oldView != null) { |
| 997 | oldView.onPause(); |
| 998 | oldView.setKeyguardCallback(mNullCallback); // ignore requests from old view |
| 999 | } |
Chris Wren | a042ac9 | 2012-11-07 11:37:06 -0500 | [diff] [blame] | 1000 | newView.onResume(KeyguardSecurityView.VIEW_REVEALED); |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 1001 | newView.setKeyguardCallback(mCallback); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1002 | |
Craig Mautner | cd03a26 | 2012-09-28 11:54:09 -0700 | [diff] [blame] | 1003 | final boolean needsInput = newView.needsInput(); |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 1004 | if (mViewMediatorCallback != null) { |
Craig Mautner | cd03a26 | 2012-09-28 11:54:09 -0700 | [diff] [blame] | 1005 | mViewMediatorCallback.setNeedsInput(needsInput); |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 1006 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1007 | |
| 1008 | // Find and show this child. |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1009 | final int childCount = mSecurityViewContainer.getChildCount(); |
Jim Miller | 4b09dd3 | 2012-09-04 14:27:25 -0700 | [diff] [blame] | 1010 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1011 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1012 | for (int i = 0; i < childCount; i++) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1013 | if (mSecurityViewContainer.getChildAt(i).getId() == securityViewIdForMode) { |
| 1014 | mSecurityViewContainer.setDisplayedChild(i); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | } |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 1018 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1019 | if (securityMode == SecurityMode.None) { |
Jim Miller | e23ab8b | 2012-09-16 15:45:44 -0700 | [diff] [blame] | 1020 | // Discard current runnable if we're switching back to the selector view |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 1021 | setOnDismissAction(null); |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 1022 | } |
John Spurlock | 03eca85 | 2013-03-14 14:21:04 -0400 | [diff] [blame] | 1023 | if (securityMode == SecurityMode.Account && !mLockPatternUtils.isPermanentlyLocked()) { |
| 1024 | // we're showing account as a backup, provide a way to get back to primary |
| 1025 | setBackButtonEnabled(true); |
| 1026 | } |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1027 | mCurrentSecuritySelection = securityMode; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | @Override |
| 1031 | public void onScreenTurnedOn() { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1032 | if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode())); |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 1033 | showPrimarySecurityScreen(false); |
Chris Wren | a042ac9 | 2012-11-07 11:37:06 -0500 | [diff] [blame] | 1034 | getSecurityView(mCurrentSecuritySelection).onResume(KeyguardSecurityView.SCREEN_ON); |
Jim Miller | d03a555 | 2012-09-10 20:46:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | // This is a an attempt to fix bug 7137389 where the device comes back on but the entire |
| 1037 | // layout is blank but forcing a layout causes it to reappear (e.g. with with |
| 1038 | // hierarchyviewer). |
| 1039 | requestLayout(); |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 1040 | |
| 1041 | if (mViewStateManager != null) { |
| 1042 | mViewStateManager.showUsabilityHints(); |
| 1043 | } |
Sandeep Siddhartha | eec83dc | 2013-09-04 14:59:59 -0700 | [diff] [blame] | 1044 | |
Jim Miller | 147f956 | 2012-12-03 17:55:16 -0800 | [diff] [blame] | 1045 | requestFocus(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public void onScreenTurnedOff() { |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1050 | if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s", |
| 1051 | Integer.toHexString(hashCode()), SystemClock.uptimeMillis())); |
Brian Colonna | 078f591 | 2012-10-31 20:03:18 -0400 | [diff] [blame] | 1052 | // Once the screen turns off, we no longer consider this to be first boot and we want the |
| 1053 | // biometric unlock to start next time keyguard is shown. |
| 1054 | KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1055 | // We use mAppWidgetToShow to show a particular widget after you add it-- once the screen |
| 1056 | // turns off we reset that behavior |
| 1057 | clearAppWidgetToShow(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 1058 | if (KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) { |
| 1059 | checkAppWidgetConsistency(); |
| 1060 | } |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 1061 | showPrimarySecurityScreen(true); |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1062 | getSecurityView(mCurrentSecuritySelection).onPause(); |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1063 | CameraWidgetFrame cameraPage = findCameraPage(); |
| 1064 | if (cameraPage != null) { |
| 1065 | cameraPage.onScreenTurnedOff(); |
| 1066 | } |
Sandeep Siddhartha | eec83dc | 2013-09-04 14:59:59 -0700 | [diff] [blame] | 1067 | |
Jim Miller | 147f956 | 2012-12-03 17:55:16 -0800 | [diff] [blame] | 1068 | clearFocus(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1071 | public void clearAppWidgetToShow() { |
| 1072 | mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 1073 | } |
| 1074 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1075 | @Override |
| 1076 | public void show() { |
Jim Miller | 0869770 | 2012-10-22 16:49:52 -0700 | [diff] [blame] | 1077 | if (DEBUG) Log.d(TAG, "show()"); |
| 1078 | showPrimarySecurityScreen(false); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1081 | @Override |
| 1082 | public void verifyUnlock() { |
| 1083 | SecurityMode securityMode = mSecurityModel.getSecurityMode(); |
| 1084 | if (securityMode == KeyguardSecurityModel.SecurityMode.None) { |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 1085 | if (mViewMediatorCallback != null) { |
| 1086 | mViewMediatorCallback.keyguardDone(true); |
| 1087 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1088 | } else if (securityMode != KeyguardSecurityModel.SecurityMode.Pattern |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 1089 | && securityMode != KeyguardSecurityModel.SecurityMode.PIN |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1090 | && securityMode != KeyguardSecurityModel.SecurityMode.Password) { |
| 1091 | // can only verify unlock when in pattern/password mode |
Craig Mautner | 7def1db | 2012-09-28 10:27:56 -0700 | [diff] [blame] | 1092 | if (mViewMediatorCallback != null) { |
| 1093 | mViewMediatorCallback.keyguardDone(false); |
| 1094 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | // otherwise, go to the unlock screen, see if they can verify it |
| 1097 | mIsVerifyUnlockOnly = true; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1098 | showSecurityScreen(securityMode); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | private int getSecurityViewIdForMode(SecurityMode securityMode) { |
| 1103 | switch (securityMode) { |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1104 | case None: return R.id.keyguard_selector_view; |
| 1105 | case Pattern: return R.id.keyguard_pattern_view; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 1106 | case PIN: return R.id.keyguard_pin_view; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1107 | case Password: return R.id.keyguard_password_view; |
| 1108 | case Biometric: return R.id.keyguard_face_unlock_view; |
| 1109 | case Account: return R.id.keyguard_account_view; |
| 1110 | case SimPin: return R.id.keyguard_sim_pin_view; |
| 1111 | case SimPuk: return R.id.keyguard_sim_puk_view; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1112 | } |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1116 | private int getLayoutIdFor(SecurityMode securityMode) { |
| 1117 | switch (securityMode) { |
| 1118 | case None: return R.layout.keyguard_selector_view; |
| 1119 | case Pattern: return R.layout.keyguard_pattern_view; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 1120 | case PIN: return R.layout.keyguard_pin_view; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1121 | case Password: return R.layout.keyguard_password_view; |
| 1122 | case Biometric: return R.layout.keyguard_face_unlock_view; |
| 1123 | case Account: return R.layout.keyguard_account_view; |
| 1124 | case SimPin: return R.layout.keyguard_sim_pin_view; |
| 1125 | case SimPuk: return R.layout.keyguard_sim_puk_view; |
| 1126 | default: |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 1127 | return 0; |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1131 | private boolean addWidget(int appId, int pageIndex, boolean updateDbIfFailed) { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1132 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appId); |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 1133 | if (appWidgetInfo != null) { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 1134 | AppWidgetHostView view = mAppWidgetHost.createView(mContext, appId, appWidgetInfo); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 1135 | addWidget(view, pageIndex); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1136 | return true; |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 1137 | } else { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1138 | if (updateDbIfFailed) { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 1139 | Log.w(TAG, "*** AppWidgetInfo for app widget id " + appId + " was null for user" |
| 1140 | + mUserId + ", deleting"); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1141 | mAppWidgetHost.deleteAppWidgetId(appId); |
| 1142 | mLockPatternUtils.removeAppWidget(appId); |
| 1143 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1144 | return false; |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 1145 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1148 | private final CameraWidgetFrame.Callbacks mCameraWidgetCallbacks = |
| 1149 | new CameraWidgetFrame.Callbacks() { |
| 1150 | @Override |
| 1151 | public void onLaunchingCamera() { |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 1152 | setSliderHandleAlpha(0); |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | @Override |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 1156 | public void onCameraLaunchedSuccessfully() { |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1157 | if (mAppWidgetContainer.isCameraPage(mAppWidgetContainer.getCurrentPage())) { |
John Spurlock | 4b976ea | 2012-10-28 12:34:11 -0400 | [diff] [blame] | 1158 | mAppWidgetContainer.scrollLeft(); |
| 1159 | } |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 1160 | setSliderHandleAlpha(1); |
Jim Miller | aaf9b11 | 2012-10-31 19:44:56 -0700 | [diff] [blame] | 1161 | mShowSecurityWhenReturn = true; |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 1164 | @Override |
| 1165 | public void onCameraLaunchedUnsuccessfully() { |
| 1166 | setSliderHandleAlpha(1); |
| 1167 | } |
| 1168 | |
| 1169 | private void setSliderHandleAlpha(float alpha) { |
| 1170 | SlidingChallengeLayout slider = |
| 1171 | (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 1172 | if (slider != null) { |
| 1173 | slider.setHandleAlpha(alpha); |
| 1174 | } |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1175 | } |
| 1176 | }; |
| 1177 | |
| 1178 | private final KeyguardActivityLauncher mActivityLauncher = new KeyguardActivityLauncher() { |
| 1179 | @Override |
| 1180 | Context getContext() { |
| 1181 | return mContext; |
| 1182 | } |
| 1183 | |
| 1184 | @Override |
| 1185 | KeyguardSecurityCallback getCallback() { |
| 1186 | return mCallback; |
| 1187 | } |
| 1188 | |
| 1189 | @Override |
| 1190 | LockPatternUtils getLockPatternUtils() { |
| 1191 | return mLockPatternUtils; |
Jim Miller | bdca3c0 | 2012-10-29 19:11:50 -0700 | [diff] [blame] | 1192 | } |
| 1193 | }; |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1194 | |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 1195 | private int numWidgets() { |
| 1196 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 1197 | int widgetCount = 0; |
| 1198 | for (int i = 0; i < childCount; i++) { |
| 1199 | if (mAppWidgetContainer.isWidgetPage(i)) { |
| 1200 | widgetCount++; |
| 1201 | } |
| 1202 | } |
| 1203 | return widgetCount; |
| 1204 | } |
| 1205 | |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 1206 | private void addDefaultWidgets() { |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 1207 | if (!mSafeModeEnabled && !widgetsDisabled()) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1208 | LayoutInflater inflater = LayoutInflater.from(mContext); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1209 | View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false); |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 1210 | mAppWidgetContainer.addWidget(addWidget, 0); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1211 | View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view); |
| 1212 | addWidgetButton.setOnClickListener(new OnClickListener() { |
| 1213 | @Override |
| 1214 | public void onClick(View v) { |
Michael Jurka | 192d6d4 | 2012-11-07 01:09:38 -0800 | [diff] [blame] | 1215 | // Pass in an invalid widget id... the picker will allocate an ID for us |
| 1216 | mActivityLauncher.launchWidgetPicker(AppWidgetManager.INVALID_APPWIDGET_ID); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1217 | } |
| 1218 | }); |
| 1219 | } |
| 1220 | |
| 1221 | // We currently disable cameras in safe mode because we support loading 3rd party |
| 1222 | // cameras we can't trust. TODO: plumb safe mode into camera creation code and only |
| 1223 | // inflate system-provided camera? |
John Spurlock | 371f340 | 2012-11-30 09:20:43 -0500 | [diff] [blame] | 1224 | if (!mSafeModeEnabled && !cameraDisabledByDpm() && mUserSetupCompleted |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1225 | && mContext.getResources().getBoolean(R.bool.kg_enable_camera_default_widget)) { |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 1226 | View cameraWidget = |
| 1227 | CameraWidgetFrame.create(mContext, mCameraWidgetCallbacks, mActivityLauncher); |
| 1228 | if (cameraWidget != null) { |
| 1229 | mAppWidgetContainer.addWidget(cameraWidget); |
| 1230 | } |
John Spurlock | 86b6357 | 2012-10-24 11:24:25 -0400 | [diff] [blame] | 1231 | } |
Jim Miller | 7221d3a | 2012-10-05 14:34:47 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1234 | /** |
| 1235 | * Create KeyguardTransportControlView on demand. |
| 1236 | * @return |
| 1237 | */ |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1238 | private KeyguardTransportControlView getOrCreateTransportControl() { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1239 | if (mTransportControl == null) { |
| 1240 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 1241 | mTransportControl = (KeyguardTransportControlView) |
| 1242 | inflater.inflate(R.layout.keyguard_transport_control_view, this, false); |
Adam Powell | f889524 | 2013-09-30 16:16:24 -0700 | [diff] [blame] | 1243 | mTransportControl.setTransportControlCallback(new TransportControlCallback() { |
| 1244 | public void userActivity() { |
| 1245 | mViewMediatorCallback.userActivity(); |
| 1246 | } |
| 1247 | }); |
Jim Miller | bdca3c0 | 2012-10-29 19:11:50 -0700 | [diff] [blame] | 1248 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1249 | return mTransportControl; |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1252 | private int getInsertPageIndex() { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1253 | View addWidget = mAppWidgetContainer.findViewById(R.id.keyguard_add_widget); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1254 | int insertionIndex = mAppWidgetContainer.indexOfChild(addWidget); |
| 1255 | if (insertionIndex < 0) { |
| 1256 | insertionIndex = 0; // no add widget page found |
| 1257 | } else { |
| 1258 | insertionIndex++; // place after add widget |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1259 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1260 | return insertionIndex; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | private void addDefaultStatusWidget(int index) { |
| 1264 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 1265 | View statusWidget = inflater.inflate(R.layout.keyguard_status_view, null, true); |
| 1266 | mAppWidgetContainer.addWidget(statusWidget, index); |
| 1267 | } |
| 1268 | |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 1269 | private void addWidgetsFromSettings() { |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 1270 | if (mSafeModeEnabled || widgetsDisabled()) { |
Jim Miller | 2ec4ff4 | 2013-08-28 17:41:16 -0700 | [diff] [blame] | 1271 | addDefaultStatusWidget(0); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1272 | return; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1273 | } |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 1274 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1275 | int insertionIndex = getInsertPageIndex(); |
Michael Jurka | 20c41d5 | 2012-09-20 19:01:06 -0700 | [diff] [blame] | 1276 | |
| 1277 | // Add user-selected widget |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 1278 | final int[] widgets = mLockPatternUtils.getAppWidgets(); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1279 | |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 1280 | if (widgets == null) { |
| 1281 | Log.d(TAG, "Problem reading widgets"); |
| 1282 | } else { |
| 1283 | for (int i = widgets.length -1; i >= 0; i--) { |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 1284 | if (widgets[i] == LockPatternUtils.ID_DEFAULT_STATUS_WIDGET) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1285 | addDefaultStatusWidget(insertionIndex); |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 1286 | } else { |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 1287 | // We add the widgets from left to right, starting after the first page after |
| 1288 | // the add page. We count down, since the order will be persisted from right |
| 1289 | // to left, starting after camera. |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1290 | addWidget(widgets[i], insertionIndex, true); |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 1291 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1292 | } |
| 1293 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | private int allocateIdForDefaultAppWidget() { |
| 1297 | int appWidgetId; |
| 1298 | Resources res = getContext().getResources(); |
| 1299 | ComponentName defaultAppWidget = new ComponentName( |
| 1300 | res.getString(R.string.widget_default_package_name), |
| 1301 | res.getString(R.string.widget_default_class_name)); |
| 1302 | |
| 1303 | // Note: we don't support configuring the widget |
| 1304 | appWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 1305 | |
| 1306 | try { |
| 1307 | mAppWidgetManager.bindAppWidgetId(appWidgetId, defaultAppWidget); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1308 | } catch (IllegalArgumentException e) { |
| 1309 | Log.e(TAG, "Error when trying to bind default AppWidget: " + e); |
| 1310 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1311 | appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 1312 | } |
| 1313 | return appWidgetId; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1314 | } |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 1315 | |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1316 | public void checkAppWidgetConsistency() { |
| 1317 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 1318 | boolean widgetPageExists = false; |
| 1319 | for (int i = 0; i < childCount; i++) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1320 | if (mAppWidgetContainer.isWidgetPage(i)) { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1321 | widgetPageExists = true; |
| 1322 | break; |
| 1323 | } |
| 1324 | } |
| 1325 | if (!widgetPageExists) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1326 | final int insertPageIndex = getInsertPageIndex(); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1327 | |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 1328 | final boolean userAddedWidgetsEnabled = !widgetsDisabled(); |
| 1329 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1330 | boolean addedDefaultAppWidget = false; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1331 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1332 | if (!mSafeModeEnabled) { |
| 1333 | if (userAddedWidgetsEnabled) { |
| 1334 | int appWidgetId = allocateIdForDefaultAppWidget(); |
| 1335 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1336 | addedDefaultAppWidget = addWidget(appWidgetId, insertPageIndex, true); |
| 1337 | } |
| 1338 | } else { |
| 1339 | // note: even if widgetsDisabledByDpm() returns true, we still bind/create |
| 1340 | // the default appwidget if possible |
| 1341 | int appWidgetId = mLockPatternUtils.getFallbackAppWidgetId(); |
| 1342 | if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1343 | appWidgetId = allocateIdForDefaultAppWidget(); |
| 1344 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1345 | mLockPatternUtils.writeFallbackAppWidgetId(appWidgetId); |
| 1346 | } |
| 1347 | } |
| 1348 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1349 | addedDefaultAppWidget = addWidget(appWidgetId, insertPageIndex, false); |
| 1350 | if (!addedDefaultAppWidget) { |
| 1351 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1352 | mLockPatternUtils.writeFallbackAppWidgetId( |
| 1353 | AppWidgetManager.INVALID_APPWIDGET_ID); |
| 1354 | } |
| 1355 | } |
| 1356 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1357 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1358 | |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1359 | // Use the built-in status/clock view if we can't inflate the default widget |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1360 | if (!addedDefaultAppWidget) { |
| 1361 | addDefaultStatusWidget(insertPageIndex); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1362 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 1363 | |
| 1364 | // trigger DB updates only if user-added widgets are enabled |
| 1365 | if (!mSafeModeEnabled && userAddedWidgetsEnabled) { |
| 1366 | mAppWidgetContainer.onAddView( |
| 1367 | mAppWidgetContainer.getChildAt(insertPageIndex), insertPageIndex); |
| 1368 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 1369 | } |
Adam Cohen | 0207c09 | 2012-09-30 16:11:00 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1372 | private final Runnable mSwitchPageRunnable = new Runnable() { |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1373 | @Override |
| 1374 | public void run() { |
| 1375 | showAppropriateWidgetPage(); |
Adam Cohen | 0207c09 | 2012-09-30 16:11:00 -0700 | [diff] [blame] | 1376 | } |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1377 | }; |
| 1378 | |
| 1379 | static class SavedState extends BaseSavedState { |
| 1380 | int transportState; |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1381 | int appWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1382 | Rect insets = new Rect(); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1383 | |
| 1384 | SavedState(Parcelable superState) { |
| 1385 | super(superState); |
| 1386 | } |
| 1387 | |
| 1388 | private SavedState(Parcel in) { |
| 1389 | super(in); |
| 1390 | this.transportState = in.readInt(); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1391 | this.appWidgetToShow = in.readInt(); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1392 | this.insets = in.readParcelable(null); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | @Override |
| 1396 | public void writeToParcel(Parcel out, int flags) { |
| 1397 | super.writeToParcel(out, flags); |
| 1398 | out.writeInt(this.transportState); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1399 | out.writeInt(this.appWidgetToShow); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1400 | out.writeParcelable(insets, 0); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | public static final Parcelable.Creator<SavedState> CREATOR |
| 1404 | = new Parcelable.Creator<SavedState>() { |
| 1405 | public SavedState createFromParcel(Parcel in) { |
| 1406 | return new SavedState(in); |
| 1407 | } |
| 1408 | |
| 1409 | public SavedState[] newArray(int size) { |
| 1410 | return new SavedState[size]; |
| 1411 | } |
| 1412 | }; |
| 1413 | } |
| 1414 | |
| 1415 | @Override |
| 1416 | public Parcelable onSaveInstanceState() { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1417 | if (DEBUG) Log.d(TAG, "onSaveInstanceState, tstate=" + mTransportState); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1418 | Parcelable superState = super.onSaveInstanceState(); |
| 1419 | SavedState ss = new SavedState(superState); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1420 | // If the transport is showing, force it to show it on restore. |
| 1421 | final boolean showing = mTransportControl != null |
| 1422 | && mAppWidgetContainer.getWidgetPageIndex(mTransportControl) >= 0; |
| 1423 | ss.transportState = showing ? TRANSPORT_VISIBLE : mTransportState; |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1424 | ss.appWidgetToShow = mAppWidgetToShow; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1425 | ss.insets.set(mInsets); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1426 | return ss; |
| 1427 | } |
| 1428 | |
| 1429 | @Override |
| 1430 | public void onRestoreInstanceState(Parcelable state) { |
| 1431 | if (!(state instanceof SavedState)) { |
| 1432 | super.onRestoreInstanceState(state); |
| 1433 | return; |
| 1434 | } |
| 1435 | SavedState ss = (SavedState) state; |
| 1436 | super.onRestoreInstanceState(ss.getSuperState()); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1437 | mTransportState = (ss.transportState); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 1438 | mAppWidgetToShow = ss.appWidgetToShow; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1439 | setInsets(ss.insets); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1440 | if (DEBUG) Log.d(TAG, "onRestoreInstanceState, transport=" + mTransportState); |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1441 | mSwitchPageRunnable.run(); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1444 | @Override |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1445 | protected boolean fitSystemWindows(Rect insets) { |
| 1446 | setInsets(insets); |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | private void setInsets(Rect insets) { |
| 1451 | mInsets.set(insets); |
| 1452 | if (mSlidingChallengeLayout != null) mSlidingChallengeLayout.setInsets(mInsets); |
| 1453 | if (mMultiPaneChallengeLayout != null) mMultiPaneChallengeLayout.setInsets(mInsets); |
Daniel Sandler | 26b7bf6 | 2013-10-10 12:44:12 -0400 | [diff] [blame] | 1454 | |
| 1455 | final CameraWidgetFrame cameraWidget = findCameraPage(); |
| 1456 | if (cameraWidget != null) cameraWidget.setInsets(mInsets); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | @Override |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1460 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 1461 | super.onWindowFocusChanged(hasWindowFocus); |
| 1462 | if (DEBUG) Log.d(TAG, "Window is " + (hasWindowFocus ? "focused" : "unfocused")); |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1463 | if (hasWindowFocus && mShowSecurityWhenReturn) { |
Jim Miller | aaf9b11 | 2012-10-31 19:44:56 -0700 | [diff] [blame] | 1464 | SlidingChallengeLayout slider = |
| 1465 | (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 1466 | if (slider != null) { |
| 1467 | slider.setHandleAlpha(1); |
| 1468 | slider.showChallenge(true); |
| 1469 | } |
| 1470 | mShowSecurityWhenReturn = false; |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 1474 | private void showAppropriateWidgetPage() { |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1475 | final int state = mTransportState; |
| 1476 | final boolean transportAdded = ensureTransportPresentOrRemoved(state); |
| 1477 | final int pageToShow = getAppropriateWidgetPage(state); |
| 1478 | if (!transportAdded) { |
| 1479 | mAppWidgetContainer.setCurrentPage(pageToShow); |
| 1480 | } else if (state == TRANSPORT_VISIBLE) { |
| 1481 | // If the transport was just added, we need to wait for layout to happen before |
| 1482 | // we can set the current page. |
| 1483 | post(new Runnable() { |
| 1484 | @Override |
| 1485 | public void run() { |
| 1486 | mAppWidgetContainer.setCurrentPage(pageToShow); |
| 1487 | } |
| 1488 | }); |
| 1489 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1492 | /** |
| 1493 | * Examines the current state and adds the transport to the widget pager when the state changes. |
| 1494 | * |
| 1495 | * Showing the initial transport and keeping it around is a bit tricky because the signals |
| 1496 | * coming from music players aren't always clear. Here's how the states are handled: |
| 1497 | * |
| 1498 | * {@link TRANSPORT_GONE} means we have no reason to show the transport - remove it if present. |
| 1499 | * |
| 1500 | * {@link TRANSPORT_INVISIBLE} means we have potential to show the transport because a music |
| 1501 | * player is registered but not currently playing music (or we don't know the state yet). The |
| 1502 | * code adds it conditionally on play state. |
| 1503 | * |
| 1504 | * {@link #TRANSPORT_VISIBLE} means a music player is active and transport should be showing. |
| 1505 | * |
| 1506 | * Once the transport is showing, we always show it until keyguard is dismissed. This state is |
| 1507 | * maintained by onSave/RestoreInstanceState(). This state is cleared in |
| 1508 | * {@link KeyguardViewManager#hide} when keyguard is dismissed, which causes the transport to be |
| 1509 | * gone when keyguard is restarted until we get an update with the current state. |
| 1510 | * |
| 1511 | * @param state |
| 1512 | */ |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1513 | private boolean ensureTransportPresentOrRemoved(int state) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1514 | final boolean showing = getWidgetPosition(R.id.keyguard_transport_control) != -1; |
| 1515 | final boolean visible = state == TRANSPORT_VISIBLE; |
| 1516 | final boolean shouldBeVisible = state == TRANSPORT_INVISIBLE && isMusicPlaying(state); |
| 1517 | if (!showing && (visible || shouldBeVisible)) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1518 | // insert to left of camera if it exists, otherwise after right-most widget |
| 1519 | int lastWidget = mAppWidgetContainer.getChildCount() - 1; |
| 1520 | int position = 0; // handle no widget case |
| 1521 | if (lastWidget >= 0) { |
| 1522 | position = mAppWidgetContainer.isCameraPage(lastWidget) ? |
| 1523 | lastWidget : lastWidget + 1; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1524 | } |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1525 | if (DEBUGXPORT) Log.v(TAG, "add transport at " + position); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1526 | mAppWidgetContainer.addWidget(getOrCreateTransportControl(), position); |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1527 | return true; |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1528 | } else if (showing && state == TRANSPORT_GONE) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1529 | if (DEBUGXPORT) Log.v(TAG, "remove transport"); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1530 | mAppWidgetContainer.removeWidget(getOrCreateTransportControl()); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1531 | mTransportControl = null; |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 1532 | KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1533 | } |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1534 | return false; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1537 | private CameraWidgetFrame findCameraPage() { |
| 1538 | for (int i = mAppWidgetContainer.getChildCount() - 1; i >= 0; i--) { |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1539 | if (mAppWidgetContainer.isCameraPage(i)) { |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1540 | return (CameraWidgetFrame) mAppWidgetContainer.getChildAt(i); |
| 1541 | } |
| 1542 | } |
| 1543 | return null; |
| 1544 | } |
| 1545 | |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1546 | boolean isMusicPage(int pageIndex) { |
| 1547 | return pageIndex >= 0 && pageIndex == getWidgetPosition(R.id.keyguard_transport_control); |
| 1548 | } |
| 1549 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1550 | private int getAppropriateWidgetPage(int musicTransportState) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1551 | // assumes at least one widget (besides camera + add) |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1552 | if (mAppWidgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1553 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 1554 | for (int i = 0; i < childCount; i++) { |
| 1555 | if (mAppWidgetContainer.getWidgetPageAt(i).getContentAppWidgetId() |
| 1556 | == mAppWidgetToShow) { |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1557 | return i; |
| 1558 | } |
| 1559 | } |
| 1560 | mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 1561 | } |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1562 | // if music playing, show transport |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1563 | if (musicTransportState == TRANSPORT_VISIBLE) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1564 | if (DEBUG) Log.d(TAG, "Music playing, show transport"); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1565 | return mAppWidgetContainer.getWidgetPageIndex(getOrCreateTransportControl()); |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1568 | // else show the right-most widget (except for camera) |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1569 | int rightMost = mAppWidgetContainer.getChildCount() - 1; |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1570 | if (mAppWidgetContainer.isCameraPage(rightMost)) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1571 | rightMost--; |
| 1572 | } |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1573 | if (DEBUG) Log.d(TAG, "Show right-most page " + rightMost); |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1574 | return rightMost; |
| 1575 | } |
| 1576 | |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 1577 | private void enableUserSelectorIfNecessary() { |
Jim Miller | 26e6c2e | 2012-10-30 14:12:22 -0700 | [diff] [blame] | 1578 | if (!UserManager.supportsMultipleUsers()) { |
| 1579 | return; // device doesn't support multi-user mode |
| 1580 | } |
Jim Miller | f6ab5f9 | 2012-11-07 16:15:13 -0800 | [diff] [blame] | 1581 | final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1582 | if (um == null) { |
| 1583 | Throwable t = new Throwable(); |
| 1584 | t.fillInStackTrace(); |
| 1585 | Log.e(TAG, "user service is null.", t); |
| 1586 | return; |
| 1587 | } |
Jim Miller | 26e6c2e | 2012-10-30 14:12:22 -0700 | [diff] [blame] | 1588 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1589 | // if there are multiple users, we need to enable to multi-user switcher |
Jim Miller | f6ab5f9 | 2012-11-07 16:15:13 -0800 | [diff] [blame] | 1590 | final List<UserInfo> users = um.getUsers(true); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1591 | if (users == null) { |
| 1592 | Throwable t = new Throwable(); |
| 1593 | t.fillInStackTrace(); |
| 1594 | Log.e(TAG, "list of users is null.", t); |
| 1595 | return; |
| 1596 | } |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 1597 | |
Jim Miller | f6ab5f9 | 2012-11-07 16:15:13 -0800 | [diff] [blame] | 1598 | final View multiUserView = findViewById(R.id.keyguard_user_selector); |
| 1599 | if (multiUserView == null) { |
| 1600 | Throwable t = new Throwable(); |
| 1601 | t.fillInStackTrace(); |
| 1602 | Log.e(TAG, "can't find user_selector in layout.", t); |
| 1603 | return; |
| 1604 | } |
| 1605 | |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1606 | if (users.size() > 1) { |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1607 | if (multiUserView instanceof KeyguardMultiUserSelectorView) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1608 | mKeyguardMultiUserSelectorView = (KeyguardMultiUserSelectorView) multiUserView; |
| 1609 | mKeyguardMultiUserSelectorView.setVisibility(View.VISIBLE); |
| 1610 | mKeyguardMultiUserSelectorView.addUsers(users); |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1611 | UserSwitcherCallback callback = new UserSwitcherCallback() { |
| 1612 | @Override |
| 1613 | public void hideSecurityView(int duration) { |
| 1614 | mSecurityViewContainer.animate().alpha(0).setDuration(duration); |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 1615 | } |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 1616 | |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1617 | @Override |
| 1618 | public void showSecurityView() { |
| 1619 | mSecurityViewContainer.setAlpha(1.0f); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 1620 | } |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1621 | |
| 1622 | @Override |
| 1623 | public void showUnlockHint() { |
| 1624 | if (mKeyguardSelectorView != null) { |
| 1625 | mKeyguardSelectorView.showUsabilityHint(); |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | @Override |
| 1630 | public void userActivity() { |
| 1631 | if (mViewMediatorCallback != null) { |
| 1632 | mViewMediatorCallback.userActivity(); |
| 1633 | } |
| 1634 | } |
| 1635 | }; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1636 | mKeyguardMultiUserSelectorView.setCallback(callback); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1637 | } else { |
| 1638 | Throwable t = new Throwable(); |
| 1639 | t.fillInStackTrace(); |
| 1640 | if (multiUserView == null) { |
| 1641 | Log.e(TAG, "could not find the user_selector.", t); |
| 1642 | } else { |
| 1643 | Log.e(TAG, "user_selector is the wrong type.", t); |
| 1644 | } |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1645 | } |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1649 | @Override |
| 1650 | public void cleanUp() { |
Adam Cohen | 128f276 | 2013-04-18 13:37:05 -0700 | [diff] [blame] | 1651 | // Make sure we let go of all widgets and their package contexts promptly. If we don't do |
| 1652 | // this, and the associated application is uninstalled, it can cause a soft reboot. |
| 1653 | int count = mAppWidgetContainer.getChildCount(); |
| 1654 | for (int i = 0; i < count; i++) { |
| 1655 | KeyguardWidgetFrame frame = mAppWidgetContainer.getWidgetPageAt(i); |
| 1656 | frame.removeAllViews(); |
| 1657 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 1660 | /** |
| 1661 | * In general, we enable unlocking the insecure keyguard with the menu key. However, there are |
| 1662 | * some cases where we wish to disable it, notably when the menu button placement or technology |
| 1663 | * is prone to false positives. |
| 1664 | * |
| 1665 | * @return true if the menu key should be enabled |
| 1666 | */ |
| 1667 | private static final String ENABLE_MENU_KEY_FILE = "/data/local/enable_menu_key"; |
| 1668 | private boolean shouldEnableMenuKey() { |
| 1669 | final Resources res = getResources(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1670 | final boolean configDisabled = res.getBoolean(R.bool.config_disableMenuKeyInLockScreen); |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 1671 | final boolean isTestHarness = ActivityManager.isRunningInTestHarness(); |
| 1672 | final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists(); |
| 1673 | return !configDisabled || isTestHarness || fileOverride; |
| 1674 | } |
| 1675 | |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1676 | public void goToWidget(int appWidgetId) { |
| 1677 | mAppWidgetToShow = appWidgetId; |
| 1678 | mSwitchPageRunnable.run(); |
| 1679 | } |
| 1680 | |
Jim Miller | 75931e0 | 2012-11-02 16:39:22 -0700 | [diff] [blame] | 1681 | public boolean handleMenuKey() { |
| 1682 | // The following enables the MENU key to work for testing automation |
| 1683 | if (shouldEnableMenuKey()) { |
| 1684 | showNextSecurityScreenOrFinish(false); |
| 1685 | return true; |
| 1686 | } |
| 1687 | return false; |
| 1688 | } |
| 1689 | |
Jim Miller | 0a34d9e | 2012-10-05 17:15:41 -0700 | [diff] [blame] | 1690 | public boolean handleBackKey() { |
John Spurlock | 03eca85 | 2013-03-14 14:21:04 -0400 | [diff] [blame] | 1691 | if (mCurrentSecuritySelection == SecurityMode.Account) { |
| 1692 | // go back to primary screen and re-disable back |
| 1693 | setBackButtonEnabled(false); |
| 1694 | showPrimarySecurityScreen(false /*turningOff*/); |
| 1695 | return true; |
| 1696 | } |
Jim Miller | 0a34d9e | 2012-10-05 17:15:41 -0700 | [diff] [blame] | 1697 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 1698 | mCallback.dismiss(false); |
| 1699 | return true; |
| 1700 | } |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 1704 | /** |
| 1705 | * Dismisses the keyguard by going to the next screen or making it gone. |
| 1706 | */ |
| 1707 | public void dismiss() { |
| 1708 | showNextSecurityScreenOrFinish(false); |
| 1709 | } |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1710 | |
| 1711 | public void showAssistant() { |
| 1712 | final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1713 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1714 | |
| 1715 | if (intent == null) return; |
| 1716 | |
| 1717 | final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, |
| 1718 | R.anim.keyguard_action_assist_enter, R.anim.keyguard_action_assist_exit, |
| 1719 | getHandler(), null); |
| 1720 | |
| 1721 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1722 | |
Daniel Sandler | 6ed3fca | 2012-11-08 09:58:27 -0500 | [diff] [blame] | 1723 | mActivityLauncher.launchActivityWithAnimation( |
| 1724 | intent, false, opts.toBundle(), null, null); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1725 | } |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1726 | |
| 1727 | public void dispatch(MotionEvent event) { |
| 1728 | mAppWidgetContainer.handleExternalCameraEvent(event); |
| 1729 | } |
| 1730 | |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 1731 | public void launchCamera() { |
| 1732 | mActivityLauncher.launchCamera(getHandler(), null); |
| 1733 | } |
| 1734 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1735 | } |