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 | |
Andres Morales | 38a7ed0 | 2013-11-14 19:02:56 -0800 | [diff] [blame] | 19 | import android.nfc.NfcUnlock; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 20 | |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 21 | import com.android.internal.widget.LockPatternUtils; |
| 22 | import com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
| 23 | import com.android.keyguard.KeyguardUpdateMonitor.DisplayClientState; |
| 24 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 25 | import android.app.Activity; |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 27 | import android.app.ActivityOptions; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 28 | import android.app.SearchManager; |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 30 | import android.appwidget.AppWidgetHost; |
| 31 | import android.appwidget.AppWidgetHostView; |
| 32 | import android.appwidget.AppWidgetManager; |
| 33 | import android.appwidget.AppWidgetProviderInfo; |
Michael Jurka | fc753c0 | 2012-10-30 18:30:52 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
| 37 | import android.content.IntentSender; |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageManager.NameNotFoundException; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 39 | import android.content.pm.UserInfo; |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 40 | import android.content.res.Resources; |
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 | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 43 | import android.os.Bundle; |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 45 | import android.os.Parcel; |
| 46 | import android.os.Parcelable; |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 47 | import android.os.SystemClock; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 48 | import android.os.UserHandle; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 49 | import android.os.UserManager; |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 50 | import android.provider.Settings; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 51 | import android.util.AttributeSet; |
| 52 | import android.util.Log; |
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 | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 56 | import android.widget.RemoteViews.OnClickHandler; |
| 57 | |
Jim Miller | 95b005c | 2012-08-29 16:43:32 -0700 | [diff] [blame] | 58 | import java.io.File; |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 59 | import java.lang.ref.WeakReference; |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 60 | import java.util.List; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 61 | |
| 62 | public class KeyguardHostView extends KeyguardViewBase { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 63 | private static final String TAG = "KeyguardHostView"; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 64 | public static boolean DEBUG = KeyguardViewMediator.DEBUG; |
| 65 | public static boolean DEBUGXPORT = true; // debug music transport control |
Sandeep Siddhartha | eec83dc | 2013-09-04 14:59:59 -0700 | [diff] [blame] | 66 | |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 67 | // Transport control states. |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 68 | static final int TRANSPORT_GONE = 0; |
| 69 | static final int TRANSPORT_INVISIBLE = 1; |
| 70 | static final int TRANSPORT_VISIBLE = 2; |
| 71 | |
| 72 | private int mTransportState = TRANSPORT_GONE; |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 73 | |
Michael Jurka | 192d6d4 | 2012-11-07 01:09:38 -0800 | [diff] [blame] | 74 | // Found in KeyguardAppWidgetPickActivity.java |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 75 | static final int APPWIDGET_HOST_ID = 0x4B455947; |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 76 | private final int MAX_WIDGETS = 5; |
| 77 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 78 | private AppWidgetHost mAppWidgetHost; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 79 | private AppWidgetManager mAppWidgetManager; |
Jim Miller | f2dfc35 | 2012-08-29 18:42:21 -0700 | [diff] [blame] | 80 | private KeyguardWidgetPager mAppWidgetContainer; |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 81 | private KeyguardTransportControlView mTransportControl; |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 82 | private int mAppWidgetToShow; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 83 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 84 | protected int mFailedAttempts; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 85 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 86 | private KeyguardViewStateManager mViewStateManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 87 | |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 88 | private Rect mTempRect = new Rect(); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 89 | private int mDisabledFeatures; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 90 | private boolean mCameraDisabled; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 91 | private boolean mSafeModeEnabled; |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 92 | private boolean mUserSetupCompleted; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 93 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 94 | // User for whom this host view was created. Final because we should never change the |
| 95 | // id without reconstructing an instance of KeyguardHostView. See note below... |
| 96 | private final int mUserId; |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 97 | |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 98 | private KeyguardMultiUserSelectorView mKeyguardMultiUserSelectorView; |
| 99 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 100 | protected int mClientGeneration; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 101 | |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 102 | protected boolean mShowSecurityWhenReturn; |
| 103 | |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 104 | private final Rect mInsets = new Rect(); |
| 105 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 106 | private MyOnClickHandler mOnClickHandler = new MyOnClickHandler(this); |
| 107 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 108 | private Runnable mPostBootCompletedRunnable; |
| 109 | |
Adam Cohen | 24b351a | 2012-09-14 15:02:27 -0700 | [diff] [blame] | 110 | /*package*/ interface UserSwitcherCallback { |
| 111 | void hideSecurityView(int duration); |
| 112 | void showSecurityView(); |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 113 | void showUnlockHint(); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 114 | void userActivity(); |
Adam Cohen | 24b351a | 2012-09-14 15:02:27 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Adam Powell | f889524 | 2013-09-30 16:16:24 -0700 | [diff] [blame] | 117 | interface TransportControlCallback { |
| 118 | void userActivity(); |
| 119 | } |
| 120 | |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 121 | /*package*/ interface OnDismissAction { |
| 122 | /* returns true if the dismiss should be deferred */ |
| 123 | boolean onDismiss(); |
| 124 | } |
| 125 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 126 | public KeyguardHostView(Context context) { |
| 127 | this(context, null); |
| 128 | } |
| 129 | |
| 130 | public KeyguardHostView(Context context, AttributeSet attrs) { |
| 131 | super(context, attrs); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 132 | |
| 133 | if (DEBUG) Log.e(TAG, "KeyguardHostView()"); |
| 134 | |
Jim Miller | 000464a | 2012-09-04 16:45:06 -0700 | [diff] [blame] | 135 | mLockPatternUtils = new LockPatternUtils(context); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 136 | |
| 137 | // Note: This depends on KeyguardHostView getting reconstructed every time the |
| 138 | // user switches, since mUserId will be used for the entire session. |
| 139 | // Once created, keyguard should *never* re-use this instance with another user. |
| 140 | // In other words, mUserId should never change - hence it's marked final. |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 141 | mUserId = mLockPatternUtils.getCurrentUser(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 142 | |
Jim Miller | 105bedd | 2013-02-27 21:35:18 -0800 | [diff] [blame] | 143 | DevicePolicyManager dpm = |
| 144 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 145 | if (dpm != null) { |
| 146 | mDisabledFeatures = getDisabledFeatures(dpm); |
| 147 | mCameraDisabled = dpm.getCameraDisabled(null); |
| 148 | } |
| 149 | |
| 150 | mSafeModeEnabled = LockPatternUtils.isSafeModeEnabled(); |
| 151 | |
| 152 | // These need to be created with the user context... |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 153 | Context userContext = null; |
| 154 | try { |
| 155 | final String packageName = "system"; |
| 156 | userContext = mContext.createPackageContextAsUser(packageName, 0, |
| 157 | new UserHandle(mUserId)); |
| 158 | |
| 159 | } catch (NameNotFoundException e) { |
| 160 | e.printStackTrace(); |
| 161 | // This should never happen, but it's better to have no widgets than to crash. |
| 162 | userContext = context; |
| 163 | } |
| 164 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 165 | mAppWidgetHost = new AppWidgetHost(userContext, APPWIDGET_HOST_ID, mOnClickHandler, |
| 166 | Looper.myLooper()); |
Jim Miller | 105bedd | 2013-02-27 21:35:18 -0800 | [diff] [blame] | 167 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 168 | mAppWidgetManager = AppWidgetManager.getInstance(userContext); |
| 169 | |
Adam Cohen | d6f8960 | 2012-11-06 11:46:25 -0800 | [diff] [blame] | 170 | mViewStateManager = new KeyguardViewStateManager(this); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 171 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 172 | mUserSetupCompleted = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 173 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 174 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 175 | // Ensure we have the current state *before* we call showAppropriateWidgetPage() |
| 176 | getInitialTransportState(); |
| 177 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 178 | if (mSafeModeEnabled) { |
| 179 | Log.v(TAG, "Keyguard widgets disabled by safe mode"); |
| 180 | } |
| 181 | if ((mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0) { |
| 182 | Log.v(TAG, "Keyguard widgets disabled by DPM"); |
| 183 | } |
| 184 | if ((mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0) { |
| 185 | Log.v(TAG, "Keyguard secure camera disabled by DPM"); |
| 186 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 189 | private void getInitialTransportState() { |
| 190 | DisplayClientState dcs = KeyguardUpdateMonitor.getInstance(mContext) |
| 191 | .getCachedDisplayClientState(); |
| 192 | mTransportState = (dcs.clearing ? TRANSPORT_GONE : |
| 193 | (isMusicPlaying(dcs.playbackState) ? TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE)); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 194 | |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 195 | if (DEBUGXPORT) Log.v(TAG, "Initial transport state: " |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 196 | + mTransportState + ", pbstate=" + dcs.playbackState); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 199 | private void cleanupAppWidgetIds() { |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 200 | if (mSafeModeEnabled || widgetsDisabled()) return; |
| 201 | |
| 202 | // Clean up appWidgetIds that are bound to lockscreen, but not actually used |
| 203 | // This is only to clean up after another bug: we used to not call |
| 204 | // deleteAppWidgetId when a user manually deleted a widget in keyguard. This code |
| 205 | // shouldn't have to run more than once per user. AppWidgetProviders rely on callbacks |
| 206 | // that are triggered by deleteAppWidgetId, which is why we're doing this |
| 207 | int[] appWidgetIdsInKeyguardSettings = mLockPatternUtils.getAppWidgets(); |
| 208 | int[] appWidgetIdsBoundToHost = mAppWidgetHost.getAppWidgetIds(); |
| 209 | for (int i = 0; i < appWidgetIdsBoundToHost.length; i++) { |
| 210 | int appWidgetId = appWidgetIdsBoundToHost[i]; |
| 211 | if (!contains(appWidgetIdsInKeyguardSettings, appWidgetId)) { |
| 212 | Log.d(TAG, "Found a appWidgetId that's not being used by keyguard, deleting id " |
| 213 | + appWidgetId); |
| 214 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | private static boolean contains(int[] array, int target) { |
| 220 | for (int value : array) { |
| 221 | if (value == target) { |
| 222 | return true; |
| 223 | } |
| 224 | } |
| 225 | return false; |
| 226 | } |
| 227 | |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 228 | private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks = |
| 229 | new KeyguardUpdateMonitorCallback() { |
| 230 | @Override |
| 231 | public void onBootCompleted() { |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 232 | if (mPostBootCompletedRunnable != null) { |
| 233 | mPostBootCompletedRunnable.run(); |
| 234 | mPostBootCompletedRunnable = null; |
Michael Jurka | 545043e | 2012-11-21 14:02:34 -0800 | [diff] [blame] | 235 | } |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 236 | } |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 237 | @Override |
| 238 | public void onUserSwitchComplete(int userId) { |
| 239 | if (mKeyguardMultiUserSelectorView != null) { |
| 240 | mKeyguardMultiUserSelectorView.finalizeActiveUserView(true); |
| 241 | } |
| 242 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 243 | @Override |
| 244 | void onMusicClientIdChanged( |
| 245 | int clientGeneration, boolean clearing, android.app.PendingIntent intent) { |
| 246 | // Set transport state to invisible until we know music is playing (below) |
| 247 | if (DEBUGXPORT && (mClientGeneration != clientGeneration || clearing)) { |
| 248 | Log.v(TAG, (clearing ? "hide" : "show") + " transport, gen:" + clientGeneration); |
| 249 | } |
| 250 | mClientGeneration = clientGeneration; |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 251 | final int newState = (clearing ? TRANSPORT_GONE |
| 252 | : (mTransportState == TRANSPORT_VISIBLE ? |
| 253 | TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE)); |
| 254 | if (newState != mTransportState) { |
| 255 | mTransportState = newState; |
| 256 | if (DEBUGXPORT) Log.v(TAG, "update widget: transport state changed"); |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 257 | KeyguardHostView.this.post(mSwitchPageRunnable); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 258 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 259 | } |
| 260 | @Override |
| 261 | public void onMusicPlaybackStateChanged(int playbackState, long eventTime) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 262 | if (DEBUGXPORT) Log.v(TAG, "music state changed: " + playbackState); |
| 263 | if (mTransportState != TRANSPORT_GONE) { |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 264 | final int newState = (isMusicPlaying(playbackState) ? |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 265 | TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 266 | if (newState != mTransportState) { |
| 267 | mTransportState = newState; |
| 268 | if (DEBUGXPORT) Log.v(TAG, "update widget: play state changed"); |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 269 | KeyguardHostView.this.post(mSwitchPageRunnable); |
Jim Miller | dfb57cd | 2013-05-30 16:43:53 -0700 | [diff] [blame] | 270 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 271 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 272 | } |
Andres Morales | 38a7ed0 | 2013-11-14 19:02:56 -0800 | [diff] [blame] | 273 | @Override |
| 274 | public void onNfcUnlock() { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 275 | if (NfcUnlock.getPropertyEnabled()) { |
| 276 | dismiss(true); |
| 277 | } |
Andres Morales | 38a7ed0 | 2013-11-14 19:02:56 -0800 | [diff] [blame] | 278 | } |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 279 | }; |
| 280 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 281 | private static final boolean isMusicPlaying(int playbackState) { |
| 282 | // This should agree with the list in AudioService.isPlaystateActive() |
| 283 | switch (playbackState) { |
| 284 | case RemoteControlClient.PLAYSTATE_PLAYING: |
| 285 | case RemoteControlClient.PLAYSTATE_BUFFERING: |
| 286 | case RemoteControlClient.PLAYSTATE_FAST_FORWARDING: |
| 287 | case RemoteControlClient.PLAYSTATE_REWINDING: |
| 288 | case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS: |
| 289 | case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS: |
| 290 | return true; |
| 291 | default: |
| 292 | return false; |
| 293 | } |
| 294 | } |
| 295 | |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 296 | private SlidingChallengeLayout mSlidingChallengeLayout; |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 297 | private MultiPaneChallengeLayout mMultiPaneChallengeLayout; |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 298 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 299 | @Override |
Jim Miller | d2b82f7 | 2012-09-18 20:52:55 -0700 | [diff] [blame] | 300 | public boolean onTouchEvent(MotionEvent ev) { |
| 301 | boolean result = super.onTouchEvent(ev); |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 302 | mTempRect.set(0, 0, 0, 0); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 303 | offsetRectIntoDescendantCoords(getSecurityContainer(), mTempRect); |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 304 | ev.offsetLocation(mTempRect.left, mTempRect.top); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 305 | result = getSecurityContainer().dispatchTouchEvent(ev) || result; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 306 | ev.offsetLocation(-mTempRect.left, -mTempRect.top); |
| 307 | return result; |
| 308 | } |
| 309 | |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 310 | private int getWidgetPosition(int id) { |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 311 | final KeyguardWidgetPager appWidgetContainer = mAppWidgetContainer; |
| 312 | final int children = appWidgetContainer.getChildCount(); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 313 | for (int i = 0; i < children; i++) { |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 314 | final View content = appWidgetContainer.getWidgetPageAt(i).getContent(); |
| 315 | if (content != null && content.getId() == id) { |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 316 | return i; |
Jim Miller | 982d21b | 2013-05-09 14:43:16 -0700 | [diff] [blame] | 317 | } else if (content == null) { |
| 318 | // Attempt to track down bug #8886916 |
| 319 | Log.w(TAG, "*** Null content at " + "i=" + i + ",id=" + id + ",N=" + children); |
Jim Miller | ff2aa0b | 2012-09-06 19:03:52 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | return -1; |
| 323 | } |
| 324 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 325 | @Override |
| 326 | protected void onFinishInflate() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 327 | super.onFinishInflate(); |
| 328 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 329 | // Grab instances of and make any necessary changes to the main layouts. Create |
| 330 | // view state manager and wire up necessary listeners / callbacks. |
Winson Chung | f3b9ec8 | 2012-11-01 14:48:51 -0700 | [diff] [blame] | 331 | View deleteDropTarget = findViewById(R.id.keyguard_widget_pager_delete_target); |
Jim Miller | f2dfc35 | 2012-08-29 18:42:21 -0700 | [diff] [blame] | 332 | mAppWidgetContainer = (KeyguardWidgetPager) findViewById(R.id.app_widget_container); |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 333 | mAppWidgetContainer.setVisibility(VISIBLE); |
| 334 | mAppWidgetContainer.setCallbacks(mWidgetCallbacks); |
Winson Chung | f3b9ec8 | 2012-11-01 14:48:51 -0700 | [diff] [blame] | 335 | mAppWidgetContainer.setDeleteDropTarget(deleteDropTarget); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 336 | mAppWidgetContainer.setMinScale(0.5f); |
| 337 | |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 338 | mSlidingChallengeLayout = (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 339 | if (mSlidingChallengeLayout != null) { |
| 340 | mSlidingChallengeLayout.setOnChallengeScrolledListener(mViewStateManager); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 341 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 342 | mAppWidgetContainer.setViewStateManager(mViewStateManager); |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 343 | mAppWidgetContainer.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 344 | |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 345 | mMultiPaneChallengeLayout = |
| 346 | (MultiPaneChallengeLayout) findViewById(R.id.multi_pane_challenge); |
Jim Miller | 2cacda5 | 2012-11-07 22:40:20 -0800 | [diff] [blame] | 347 | ChallengeLayout challenge = mSlidingChallengeLayout != null ? mSlidingChallengeLayout : |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 348 | mMultiPaneChallengeLayout; |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 349 | challenge.setOnBouncerStateChangedListener(mViewStateManager); |
Winson Chung | 70c2f87 | 2012-11-07 21:47:12 -0800 | [diff] [blame] | 350 | mAppWidgetContainer.setBouncerAnimationDuration(challenge.getBouncerAnimationDuration()); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 351 | mViewStateManager.setPagedView(mAppWidgetContainer); |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 352 | mViewStateManager.setChallengeLayout(challenge); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 353 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 354 | mViewStateManager.setSecurityViewContainer(getSecurityContainer()); |
Jim Miller | 68c2489 | 2012-10-14 05:04:00 -0700 | [diff] [blame] | 355 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 356 | if (KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) { |
| 357 | updateAndAddWidgets(); |
| 358 | } else { |
| 359 | // We can't add widgets until after boot completes because AppWidgetHost may try |
| 360 | // to contact the providers. Do it later. |
| 361 | mPostBootCompletedRunnable = new Runnable() { |
| 362 | @Override |
| 363 | public void run() { |
| 364 | updateAndAddWidgets(); |
| 365 | } |
| 366 | }; |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 367 | } |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 368 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 369 | getSecurityContainer().updateSecurityViews(mViewStateManager.isBouncing()); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 370 | enableUserSelectorIfNecessary(); |
| 371 | } |
| 372 | |
| 373 | private void updateAndAddWidgets() { |
| 374 | cleanupAppWidgetIds(); |
| 375 | addDefaultWidgets(); |
| 376 | addWidgetsFromSettings(); |
| 377 | maybeEnableAddButton(); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 378 | checkAppWidgetConsistency(); |
Jim Miller | 5547b55 | 2013-10-07 19:20:56 -0700 | [diff] [blame] | 379 | |
| 380 | // Don't let the user drag the challenge down if widgets are disabled. |
| 381 | if (mSlidingChallengeLayout != null) { |
| 382 | mSlidingChallengeLayout.setEnableChallengeDragging(!widgetsDisabled()); |
| 383 | } |
| 384 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 385 | // Select the appropriate page |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 386 | mSwitchPageRunnable.run(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 387 | |
Adam Cohen | 45adaa7 | 2012-11-02 22:00:57 -0700 | [diff] [blame] | 388 | // This needs to be called after the pages are all added. |
| 389 | mViewStateManager.showUsabilityHints(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 390 | } |
Adam Cohen | 45adaa7 | 2012-11-02 22:00:57 -0700 | [diff] [blame] | 391 | |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 392 | private void maybeEnableAddButton() { |
| 393 | if (!shouldEnableAddWidget()) { |
| 394 | mAppWidgetContainer.setAddWidgetEnabled(false); |
| 395 | } |
Jim Miller | e46efc0 | 2012-09-07 16:43:51 -0700 | [diff] [blame] | 396 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 397 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 398 | private boolean shouldEnableAddWidget() { |
| 399 | return numWidgets() < MAX_WIDGETS && mUserSetupCompleted; |
| 400 | } |
| 401 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 402 | @Override |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 403 | public boolean dismiss(boolean authenticated) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 404 | boolean finished = super.dismiss(authenticated); |
| 405 | if (!finished) { |
| 406 | mViewStateManager.showBouncer(true); |
| 407 | |
| 408 | // Enter full screen mode if we're in SIM or Account screen |
| 409 | SecurityMode securityMode = getSecurityContainer().getSecurityMode(); |
| 410 | boolean isFullScreen = getResources().getBoolean(R.bool.kg_sim_puk_account_full_screen); |
| 411 | boolean isSimOrAccount = securityMode == SecurityMode.SimPin |
| 412 | || securityMode == SecurityMode.SimPuk |
| 413 | || securityMode == SecurityMode.Account; |
| 414 | mAppWidgetContainer.setVisibility( |
| 415 | isSimOrAccount && isFullScreen ? View.GONE : View.VISIBLE); |
| 416 | |
| 417 | // Don't show camera or search in navbar when SIM or Account screen is showing |
| 418 | setSystemUiVisibility(isSimOrAccount ? |
| 419 | (getSystemUiVisibility() | View.STATUS_BAR_DISABLE_SEARCH) |
| 420 | : (getSystemUiVisibility() & ~View.STATUS_BAR_DISABLE_SEARCH)); |
| 421 | |
| 422 | if (mSlidingChallengeLayout != null) { |
| 423 | mSlidingChallengeLayout.setChallengeInteractive(!isFullScreen); |
| 424 | } |
| 425 | } |
| 426 | return finished; |
| 427 | } |
| 428 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 429 | private int getDisabledFeatures(DevicePolicyManager dpm) { |
| 430 | int disabledFeatures = DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE; |
| 431 | if (dpm != null) { |
| 432 | final int currentUser = mLockPatternUtils.getCurrentUser(); |
| 433 | disabledFeatures = dpm.getKeyguardDisabledFeatures(null, currentUser); |
| 434 | } |
| 435 | return disabledFeatures; |
| 436 | } |
| 437 | |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 438 | private boolean widgetsDisabled() { |
Jim Miller | 461b345 | 2013-09-29 14:00:01 -0700 | [diff] [blame] | 439 | boolean disabledByLowRamDevice = ActivityManager.isLowRamDeviceStatic(); |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 440 | boolean disabledByDpm = |
| 441 | (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; |
| 442 | boolean disabledByUser = !mLockPatternUtils.getWidgetsEnabled(); |
Jim Miller | 461b345 | 2013-09-29 14:00:01 -0700 | [diff] [blame] | 443 | return disabledByLowRamDevice || disabledByDpm || disabledByUser; |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | private boolean cameraDisabledByDpm() { |
| 447 | return mCameraDisabled |
| 448 | || (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0; |
| 449 | } |
| 450 | |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 451 | @Override |
| 452 | protected void setLockPatternUtils(LockPatternUtils utils) { |
| 453 | super.setLockPatternUtils(utils); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 454 | getSecurityContainer().updateSecurityViews(mViewStateManager.isBouncing()); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | @Override |
| 458 | protected void onAttachedToWindow() { |
| 459 | super.onAttachedToWindow(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 460 | mAppWidgetHost.startListening(); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 461 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks); |
Jim Miller | 7221d3a | 2012-10-05 14:34:47 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 464 | @Override |
| 465 | protected void onDetachedFromWindow() { |
| 466 | super.onDetachedFromWindow(); |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 467 | mAppWidgetHost.stopListening(); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 468 | KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 471 | void addWidget(AppWidgetHostView view, int pageIndex) { |
| 472 | mAppWidgetContainer.addWidget(view, pageIndex); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 475 | private KeyguardWidgetPager.Callbacks mWidgetCallbacks |
| 476 | = new KeyguardWidgetPager.Callbacks() { |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 477 | @Override |
| 478 | public void userActivity() { |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 479 | KeyguardHostView.this.userActivity(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public void onUserActivityTimeoutChanged() { |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 484 | KeyguardHostView.this.onUserActivityTimeoutChanged(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 485 | } |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 486 | |
| 487 | @Override |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 488 | public void onAddView(View v) { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 489 | if (!shouldEnableAddWidget()) { |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 490 | mAppWidgetContainer.setAddWidgetEnabled(false); |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 491 | } |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 492 | } |
Winson Chung | 40f8211 | 2012-11-08 11:54:55 -0800 | [diff] [blame] | 493 | |
| 494 | @Override |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 495 | public void onRemoveView(View v, boolean deletePermanently) { |
Michael Jurka | 75b5cfb | 2012-11-15 18:22:47 -0800 | [diff] [blame] | 496 | if (deletePermanently) { |
| 497 | final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId(); |
| 498 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && |
| 499 | appWidgetId != LockPatternUtils.ID_DEFAULT_STATUS_WIDGET) { |
| 500 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 501 | } |
| 502 | } |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 503 | } |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 504 | |
| 505 | @Override |
| 506 | public void onRemoveViewAnimationCompleted() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 507 | if (shouldEnableAddWidget()) { |
Winson Chung | 4752e7d | 2012-11-20 17:06:04 -0800 | [diff] [blame] | 508 | mAppWidgetContainer.setAddWidgetEnabled(true); |
| 509 | } |
| 510 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 511 | }; |
| 512 | |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 513 | @Override |
| 514 | public void onUserSwitching(boolean switching) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 515 | if (!switching && mKeyguardMultiUserSelectorView != null) { |
| 516 | mKeyguardMultiUserSelectorView.finalizeActiveUserView(false); |
| 517 | } |
| 518 | } |
| 519 | |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 520 | public void userActivity() { |
| 521 | if (mViewMediatorCallback != null) { |
| 522 | mViewMediatorCallback.userActivity(); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | public void onUserActivityTimeoutChanged() { |
| 527 | if (mViewMediatorCallback != null) { |
| 528 | mViewMediatorCallback.onUserActivityTimeoutChanged(); |
| 529 | } |
| 530 | } |
| 531 | |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 532 | @Override |
| 533 | public long getUserActivityTimeout() { |
| 534 | // Currently only considering user activity timeouts needed by widgets. |
| 535 | // Could also take into account longer timeouts for certain security views. |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 536 | if (mAppWidgetContainer != null) { |
| 537 | return mAppWidgetContainer.getUserActivityTimeout(); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 538 | } |
| 539 | return -1; |
| 540 | } |
| 541 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 542 | private static class MyOnClickHandler extends OnClickHandler { |
| 543 | |
| 544 | // weak reference to the hostView to avoid keeping a live reference |
| 545 | // due to Binder GC linkages to AppWidgetHost. By the same token, |
| 546 | // this click handler should not keep references to any large |
| 547 | // objects. |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 548 | WeakReference<KeyguardHostView> mKeyguardHostView; |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 549 | |
| 550 | MyOnClickHandler(KeyguardHostView hostView) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 551 | mKeyguardHostView = new WeakReference<KeyguardHostView>(hostView); |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 554 | @Override |
| 555 | public boolean onClickHandler(final View view, |
| 556 | final android.app.PendingIntent pendingIntent, |
| 557 | final Intent fillInIntent) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 558 | KeyguardHostView hostView = mKeyguardHostView.get(); |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 559 | if (hostView == null) { |
| 560 | return false; |
| 561 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 562 | if (pendingIntent.isActivity()) { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 563 | hostView.setOnDismissAction(new OnDismissAction() { |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 564 | public boolean onDismiss() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 565 | try { |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 566 | // TODO: Unregister this handler if PendingIntent.FLAG_ONE_SHOT? |
| 567 | Context context = view.getContext(); |
| 568 | ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, |
| 569 | 0, 0, |
| 570 | view.getMeasuredWidth(), view.getMeasuredHeight()); |
| 571 | context.startIntentSender( |
| 572 | pendingIntent.getIntentSender(), fillInIntent, |
| 573 | Intent.FLAG_ACTIVITY_NEW_TASK, |
| 574 | Intent.FLAG_ACTIVITY_NEW_TASK, 0, opts.toBundle()); |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 575 | } catch (IntentSender.SendIntentException e) { |
| 576 | android.util.Log.e(TAG, "Cannot send pending intent: ", e); |
| 577 | } catch (Exception e) { |
| 578 | android.util.Log.e(TAG, "Cannot send pending intent due to " + |
| 579 | "unknown exception: ", e); |
| 580 | } |
| 581 | return false; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 582 | } |
Jim Miller | 5f75aa1 | 2012-08-29 15:10:34 -0700 | [diff] [blame] | 583 | }); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 584 | |
Chet Haase | 7fc27ea | 2013-10-01 15:34:22 -0700 | [diff] [blame] | 585 | if (hostView.mViewStateManager.isChallengeShowing()) { |
| 586 | hostView.mViewStateManager.showBouncer(true); |
Jim Miller | 0889837 | 2012-11-04 19:08:40 -0800 | [diff] [blame] | 587 | } else { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 588 | hostView.dismiss(); |
Jim Miller | 0889837 | 2012-11-04 19:08:40 -0800 | [diff] [blame] | 589 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 590 | return true; |
| 591 | } else { |
| 592 | return super.onClickHandler(view, pendingIntent, fillInIntent); |
| 593 | } |
| 594 | }; |
| 595 | }; |
| 596 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 597 | @Override |
| 598 | public void onScreenTurnedOn() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 599 | super.onScreenTurnedOn(); |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 600 | if (mViewStateManager != null) { |
| 601 | mViewStateManager.showUsabilityHints(); |
| 602 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public void onScreenTurnedOff() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 607 | super.onScreenTurnedOff(); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 608 | // We use mAppWidgetToShow to show a particular widget after you add it-- once the screen |
| 609 | // turns off we reset that behavior |
| 610 | clearAppWidgetToShow(); |
Jim Miller | 9ccf123 | 2013-10-10 22:23:07 -0700 | [diff] [blame] | 611 | if (KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) { |
| 612 | checkAppWidgetConsistency(); |
| 613 | } |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 614 | CameraWidgetFrame cameraPage = findCameraPage(); |
| 615 | if (cameraPage != null) { |
| 616 | cameraPage.onScreenTurnedOff(); |
| 617 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 620 | public void clearAppWidgetToShow() { |
| 621 | mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 622 | } |
| 623 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 624 | private boolean addWidget(int appId, int pageIndex, boolean updateDbIfFailed) { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 625 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appId); |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 626 | if (appWidgetInfo != null) { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 627 | AppWidgetHostView view = mAppWidgetHost.createView(mContext, appId, appWidgetInfo); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 628 | addWidget(view, pageIndex); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 629 | return true; |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 630 | } else { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 631 | if (updateDbIfFailed) { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 632 | Log.w(TAG, "*** AppWidgetInfo for app widget id " + appId + " was null for user" |
| 633 | + mUserId + ", deleting"); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 634 | mAppWidgetHost.deleteAppWidgetId(appId); |
| 635 | mLockPatternUtils.removeAppWidget(appId); |
| 636 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 637 | return false; |
Jim Miller | 99a3cae | 2012-09-17 20:53:51 -0700 | [diff] [blame] | 638 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 639 | } |
| 640 | |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 641 | private final CameraWidgetFrame.Callbacks mCameraWidgetCallbacks = |
| 642 | new CameraWidgetFrame.Callbacks() { |
| 643 | @Override |
| 644 | public void onLaunchingCamera() { |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 645 | setSliderHandleAlpha(0); |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | @Override |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 649 | public void onCameraLaunchedSuccessfully() { |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 650 | if (mAppWidgetContainer.isCameraPage(mAppWidgetContainer.getCurrentPage())) { |
John Spurlock | 4b976ea | 2012-10-28 12:34:11 -0400 | [diff] [blame] | 651 | mAppWidgetContainer.scrollLeft(); |
| 652 | } |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 653 | setSliderHandleAlpha(1); |
Jim Miller | aaf9b11 | 2012-10-31 19:44:56 -0700 | [diff] [blame] | 654 | mShowSecurityWhenReturn = true; |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 655 | } |
| 656 | |
John Spurlock | 57f928f | 2012-11-02 13:09:25 -0400 | [diff] [blame] | 657 | @Override |
| 658 | public void onCameraLaunchedUnsuccessfully() { |
| 659 | setSliderHandleAlpha(1); |
| 660 | } |
| 661 | |
| 662 | private void setSliderHandleAlpha(float alpha) { |
| 663 | SlidingChallengeLayout slider = |
| 664 | (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 665 | if (slider != null) { |
| 666 | slider.setHandleAlpha(alpha); |
| 667 | } |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 668 | } |
| 669 | }; |
| 670 | |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 671 | private int numWidgets() { |
| 672 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 673 | int widgetCount = 0; |
| 674 | for (int i = 0; i < childCount; i++) { |
| 675 | if (mAppWidgetContainer.isWidgetPage(i)) { |
| 676 | widgetCount++; |
| 677 | } |
| 678 | } |
| 679 | return widgetCount; |
| 680 | } |
| 681 | |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 682 | private void addDefaultWidgets() { |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 683 | if (!mSafeModeEnabled && !widgetsDisabled()) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 684 | LayoutInflater inflater = LayoutInflater.from(mContext); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 685 | View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false); |
Michael Jurka | eb963f0 | 2012-11-08 00:32:29 -0800 | [diff] [blame] | 686 | mAppWidgetContainer.addWidget(addWidget, 0); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 687 | View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view); |
| 688 | addWidgetButton.setOnClickListener(new OnClickListener() { |
| 689 | @Override |
| 690 | public void onClick(View v) { |
Michael Jurka | 192d6d4 | 2012-11-07 01:09:38 -0800 | [diff] [blame] | 691 | // Pass in an invalid widget id... the picker will allocate an ID for us |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 692 | getActivityLauncher().launchWidgetPicker(AppWidgetManager.INVALID_APPWIDGET_ID); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 693 | } |
| 694 | }); |
| 695 | } |
| 696 | |
| 697 | // We currently disable cameras in safe mode because we support loading 3rd party |
| 698 | // cameras we can't trust. TODO: plumb safe mode into camera creation code and only |
| 699 | // inflate system-provided camera? |
John Spurlock | 371f340 | 2012-11-30 09:20:43 -0500 | [diff] [blame] | 700 | if (!mSafeModeEnabled && !cameraDisabledByDpm() && mUserSetupCompleted |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 701 | && mContext.getResources().getBoolean(R.bool.kg_enable_camera_default_widget)) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 702 | View cameraWidget = CameraWidgetFrame.create(mContext, mCameraWidgetCallbacks, |
| 703 | getActivityLauncher()); |
John Spurlock | dcc9681 | 2012-10-25 14:35:19 -0400 | [diff] [blame] | 704 | if (cameraWidget != null) { |
| 705 | mAppWidgetContainer.addWidget(cameraWidget); |
| 706 | } |
John Spurlock | 86b6357 | 2012-10-24 11:24:25 -0400 | [diff] [blame] | 707 | } |
Jim Miller | 7221d3a | 2012-10-05 14:34:47 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 710 | /** |
| 711 | * Create KeyguardTransportControlView on demand. |
| 712 | * @return |
| 713 | */ |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 714 | private KeyguardTransportControlView getOrCreateTransportControl() { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 715 | if (mTransportControl == null) { |
| 716 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 717 | mTransportControl = (KeyguardTransportControlView) |
| 718 | inflater.inflate(R.layout.keyguard_transport_control_view, this, false); |
Adam Powell | f889524 | 2013-09-30 16:16:24 -0700 | [diff] [blame] | 719 | mTransportControl.setTransportControlCallback(new TransportControlCallback() { |
| 720 | public void userActivity() { |
| 721 | mViewMediatorCallback.userActivity(); |
| 722 | } |
| 723 | }); |
Jim Miller | bdca3c0 | 2012-10-29 19:11:50 -0700 | [diff] [blame] | 724 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 725 | return mTransportControl; |
Jim Miller | 4e81bd4 | 2012-10-01 20:21:02 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 728 | private int getInsertPageIndex() { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 729 | View addWidget = mAppWidgetContainer.findViewById(R.id.keyguard_add_widget); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 730 | int insertionIndex = mAppWidgetContainer.indexOfChild(addWidget); |
| 731 | if (insertionIndex < 0) { |
| 732 | insertionIndex = 0; // no add widget page found |
| 733 | } else { |
| 734 | insertionIndex++; // place after add widget |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 735 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 736 | return insertionIndex; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | private void addDefaultStatusWidget(int index) { |
| 740 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 741 | View statusWidget = inflater.inflate(R.layout.keyguard_status_view, null, true); |
| 742 | mAppWidgetContainer.addWidget(statusWidget, index); |
| 743 | } |
| 744 | |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 745 | private void addWidgetsFromSettings() { |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 746 | if (mSafeModeEnabled || widgetsDisabled()) { |
Jim Miller | 2ec4ff4 | 2013-08-28 17:41:16 -0700 | [diff] [blame] | 747 | addDefaultStatusWidget(0); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 748 | return; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 749 | } |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 750 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 751 | int insertionIndex = getInsertPageIndex(); |
Michael Jurka | 20c41d5 | 2012-09-20 19:01:06 -0700 | [diff] [blame] | 752 | |
| 753 | // Add user-selected widget |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 754 | final int[] widgets = mLockPatternUtils.getAppWidgets(); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 755 | |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 756 | if (widgets == null) { |
| 757 | Log.d(TAG, "Problem reading widgets"); |
| 758 | } else { |
| 759 | for (int i = widgets.length -1; i >= 0; i--) { |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 760 | if (widgets[i] == LockPatternUtils.ID_DEFAULT_STATUS_WIDGET) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 761 | addDefaultStatusWidget(insertionIndex); |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 762 | } else { |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 763 | // We add the widgets from left to right, starting after the first page after |
| 764 | // the add page. We count down, since the order will be persisted from right |
| 765 | // to left, starting after camera. |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 766 | addWidget(widgets[i], insertionIndex, true); |
Michael Jurka | aa2859a | 2012-10-24 12:46:49 -0700 | [diff] [blame] | 767 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 768 | } |
| 769 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | private int allocateIdForDefaultAppWidget() { |
| 773 | int appWidgetId; |
| 774 | Resources res = getContext().getResources(); |
| 775 | ComponentName defaultAppWidget = new ComponentName( |
| 776 | res.getString(R.string.widget_default_package_name), |
| 777 | res.getString(R.string.widget_default_class_name)); |
| 778 | |
| 779 | // Note: we don't support configuring the widget |
| 780 | appWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 781 | |
| 782 | try { |
| 783 | mAppWidgetManager.bindAppWidgetId(appWidgetId, defaultAppWidget); |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 784 | } catch (IllegalArgumentException e) { |
| 785 | Log.e(TAG, "Error when trying to bind default AppWidget: " + e); |
| 786 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 787 | appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 788 | } |
| 789 | return appWidgetId; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 790 | } |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 791 | |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 792 | public void checkAppWidgetConsistency() { |
| 793 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 794 | boolean widgetPageExists = false; |
| 795 | for (int i = 0; i < childCount; i++) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 796 | if (mAppWidgetContainer.isWidgetPage(i)) { |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 797 | widgetPageExists = true; |
| 798 | break; |
| 799 | } |
| 800 | } |
| 801 | if (!widgetPageExists) { |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 802 | final int insertPageIndex = getInsertPageIndex(); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 803 | |
Jim Miller | f45bb40 | 2013-08-20 18:58:32 -0700 | [diff] [blame] | 804 | final boolean userAddedWidgetsEnabled = !widgetsDisabled(); |
| 805 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 806 | boolean addedDefaultAppWidget = false; |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 807 | |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 808 | if (!mSafeModeEnabled) { |
| 809 | if (userAddedWidgetsEnabled) { |
| 810 | int appWidgetId = allocateIdForDefaultAppWidget(); |
| 811 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 812 | addedDefaultAppWidget = addWidget(appWidgetId, insertPageIndex, true); |
| 813 | } |
| 814 | } else { |
| 815 | // note: even if widgetsDisabledByDpm() returns true, we still bind/create |
| 816 | // the default appwidget if possible |
| 817 | int appWidgetId = mLockPatternUtils.getFallbackAppWidgetId(); |
| 818 | if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 819 | appWidgetId = allocateIdForDefaultAppWidget(); |
| 820 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 821 | mLockPatternUtils.writeFallbackAppWidgetId(appWidgetId); |
| 822 | } |
| 823 | } |
| 824 | if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 825 | addedDefaultAppWidget = addWidget(appWidgetId, insertPageIndex, false); |
| 826 | if (!addedDefaultAppWidget) { |
| 827 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 828 | mLockPatternUtils.writeFallbackAppWidgetId( |
| 829 | AppWidgetManager.INVALID_APPWIDGET_ID); |
| 830 | } |
| 831 | } |
| 832 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 833 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 834 | |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 835 | // 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] | 836 | if (!addedDefaultAppWidget) { |
| 837 | addDefaultStatusWidget(insertPageIndex); |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 838 | } |
Jim Miller | 5111726 | 2012-11-04 17:58:09 -0800 | [diff] [blame] | 839 | |
| 840 | // trigger DB updates only if user-added widgets are enabled |
| 841 | if (!mSafeModeEnabled && userAddedWidgetsEnabled) { |
| 842 | mAppWidgetContainer.onAddView( |
| 843 | mAppWidgetContainer.getChildAt(insertPageIndex), insertPageIndex); |
| 844 | } |
Michael Jurka | 67a871d | 2012-11-01 18:26:01 -0700 | [diff] [blame] | 845 | } |
Adam Cohen | 0207c09 | 2012-09-30 16:11:00 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 848 | private final Runnable mSwitchPageRunnable = new Runnable() { |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 849 | @Override |
| 850 | public void run() { |
| 851 | showAppropriateWidgetPage(); |
Adam Cohen | 0207c09 | 2012-09-30 16:11:00 -0700 | [diff] [blame] | 852 | } |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | static class SavedState extends BaseSavedState { |
| 856 | int transportState; |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 857 | int appWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 858 | Rect insets = new Rect(); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 859 | |
| 860 | SavedState(Parcelable superState) { |
| 861 | super(superState); |
| 862 | } |
| 863 | |
| 864 | private SavedState(Parcel in) { |
| 865 | super(in); |
| 866 | this.transportState = in.readInt(); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 867 | this.appWidgetToShow = in.readInt(); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 868 | this.insets = in.readParcelable(null); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | @Override |
| 872 | public void writeToParcel(Parcel out, int flags) { |
| 873 | super.writeToParcel(out, flags); |
| 874 | out.writeInt(this.transportState); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 875 | out.writeInt(this.appWidgetToShow); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 876 | out.writeParcelable(insets, 0); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | public static final Parcelable.Creator<SavedState> CREATOR |
| 880 | = new Parcelable.Creator<SavedState>() { |
| 881 | public SavedState createFromParcel(Parcel in) { |
| 882 | return new SavedState(in); |
| 883 | } |
| 884 | |
| 885 | public SavedState[] newArray(int size) { |
| 886 | return new SavedState[size]; |
| 887 | } |
| 888 | }; |
| 889 | } |
| 890 | |
| 891 | @Override |
| 892 | public Parcelable onSaveInstanceState() { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 893 | if (DEBUG) Log.d(TAG, "onSaveInstanceState, tstate=" + mTransportState); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 894 | Parcelable superState = super.onSaveInstanceState(); |
| 895 | SavedState ss = new SavedState(superState); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 896 | // If the transport is showing, force it to show it on restore. |
| 897 | final boolean showing = mTransportControl != null |
| 898 | && mAppWidgetContainer.getWidgetPageIndex(mTransportControl) >= 0; |
| 899 | ss.transportState = showing ? TRANSPORT_VISIBLE : mTransportState; |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 900 | ss.appWidgetToShow = mAppWidgetToShow; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 901 | ss.insets.set(mInsets); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 902 | return ss; |
| 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public void onRestoreInstanceState(Parcelable state) { |
| 907 | if (!(state instanceof SavedState)) { |
| 908 | super.onRestoreInstanceState(state); |
| 909 | return; |
| 910 | } |
| 911 | SavedState ss = (SavedState) state; |
| 912 | super.onRestoreInstanceState(ss.getSuperState()); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 913 | mTransportState = (ss.transportState); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 914 | mAppWidgetToShow = ss.appWidgetToShow; |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 915 | setInsets(ss.insets); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 916 | if (DEBUG) Log.d(TAG, "onRestoreInstanceState, transport=" + mTransportState); |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 917 | mSwitchPageRunnable.run(); |
Jim Miller | 223ce5c | 2012-10-05 19:13:23 -0700 | [diff] [blame] | 918 | } |
| 919 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 920 | @Override |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 921 | protected boolean fitSystemWindows(Rect insets) { |
| 922 | setInsets(insets); |
| 923 | return true; |
| 924 | } |
| 925 | |
| 926 | private void setInsets(Rect insets) { |
| 927 | mInsets.set(insets); |
| 928 | if (mSlidingChallengeLayout != null) mSlidingChallengeLayout.setInsets(mInsets); |
| 929 | if (mMultiPaneChallengeLayout != null) mMultiPaneChallengeLayout.setInsets(mInsets); |
Daniel Sandler | 26b7bf6 | 2013-10-10 12:44:12 -0400 | [diff] [blame] | 930 | |
| 931 | final CameraWidgetFrame cameraWidget = findCameraPage(); |
| 932 | if (cameraWidget != null) cameraWidget.setInsets(mInsets); |
John Spurlock | 256ae67 | 2013-09-26 12:14:33 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | @Override |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 936 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 937 | super.onWindowFocusChanged(hasWindowFocus); |
| 938 | if (DEBUG) Log.d(TAG, "Window is " + (hasWindowFocus ? "focused" : "unfocused")); |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 939 | if (hasWindowFocus && mShowSecurityWhenReturn) { |
Jim Miller | aaf9b11 | 2012-10-31 19:44:56 -0700 | [diff] [blame] | 940 | SlidingChallengeLayout slider = |
| 941 | (SlidingChallengeLayout) findViewById(R.id.sliding_layout); |
| 942 | if (slider != null) { |
| 943 | slider.setHandleAlpha(1); |
| 944 | slider.showChallenge(true); |
| 945 | } |
| 946 | mShowSecurityWhenReturn = false; |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Jim Miller | 4d20ed3 | 2013-10-19 01:00:16 +0000 | [diff] [blame] | 950 | private void showAppropriateWidgetPage() { |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 951 | final int state = mTransportState; |
| 952 | final boolean transportAdded = ensureTransportPresentOrRemoved(state); |
| 953 | final int pageToShow = getAppropriateWidgetPage(state); |
| 954 | if (!transportAdded) { |
| 955 | mAppWidgetContainer.setCurrentPage(pageToShow); |
| 956 | } else if (state == TRANSPORT_VISIBLE) { |
| 957 | // If the transport was just added, we need to wait for layout to happen before |
| 958 | // we can set the current page. |
| 959 | post(new Runnable() { |
| 960 | @Override |
| 961 | public void run() { |
| 962 | mAppWidgetContainer.setCurrentPage(pageToShow); |
| 963 | } |
| 964 | }); |
| 965 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 968 | /** |
| 969 | * Examines the current state and adds the transport to the widget pager when the state changes. |
| 970 | * |
| 971 | * Showing the initial transport and keeping it around is a bit tricky because the signals |
| 972 | * coming from music players aren't always clear. Here's how the states are handled: |
| 973 | * |
| 974 | * {@link TRANSPORT_GONE} means we have no reason to show the transport - remove it if present. |
| 975 | * |
| 976 | * {@link TRANSPORT_INVISIBLE} means we have potential to show the transport because a music |
| 977 | * player is registered but not currently playing music (or we don't know the state yet). The |
| 978 | * code adds it conditionally on play state. |
| 979 | * |
| 980 | * {@link #TRANSPORT_VISIBLE} means a music player is active and transport should be showing. |
| 981 | * |
| 982 | * Once the transport is showing, we always show it until keyguard is dismissed. This state is |
| 983 | * maintained by onSave/RestoreInstanceState(). This state is cleared in |
| 984 | * {@link KeyguardViewManager#hide} when keyguard is dismissed, which causes the transport to be |
| 985 | * gone when keyguard is restarted until we get an update with the current state. |
| 986 | * |
| 987 | * @param state |
| 988 | */ |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 989 | private boolean ensureTransportPresentOrRemoved(int state) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 990 | final boolean showing = getWidgetPosition(R.id.keyguard_transport_control) != -1; |
| 991 | final boolean visible = state == TRANSPORT_VISIBLE; |
| 992 | final boolean shouldBeVisible = state == TRANSPORT_INVISIBLE && isMusicPlaying(state); |
| 993 | if (!showing && (visible || shouldBeVisible)) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 994 | // insert to left of camera if it exists, otherwise after right-most widget |
| 995 | int lastWidget = mAppWidgetContainer.getChildCount() - 1; |
| 996 | int position = 0; // handle no widget case |
| 997 | if (lastWidget >= 0) { |
| 998 | position = mAppWidgetContainer.isCameraPage(lastWidget) ? |
| 999 | lastWidget : lastWidget + 1; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1000 | } |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1001 | if (DEBUGXPORT) Log.v(TAG, "add transport at " + position); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1002 | mAppWidgetContainer.addWidget(getOrCreateTransportControl(), position); |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1003 | return true; |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1004 | } else if (showing && state == TRANSPORT_GONE) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1005 | if (DEBUGXPORT) Log.v(TAG, "remove transport"); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1006 | mAppWidgetContainer.removeWidget(getOrCreateTransportControl()); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1007 | mTransportControl = null; |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 1008 | KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1009 | } |
Jim Miller | 81190be | 2013-11-05 18:17:59 -0800 | [diff] [blame] | 1010 | return false; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1013 | private CameraWidgetFrame findCameraPage() { |
| 1014 | for (int i = mAppWidgetContainer.getChildCount() - 1; i >= 0; i--) { |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1015 | if (mAppWidgetContainer.isCameraPage(i)) { |
John Spurlock | dbe24b7 | 2012-11-01 13:01:05 -0400 | [diff] [blame] | 1016 | return (CameraWidgetFrame) mAppWidgetContainer.getChildAt(i); |
| 1017 | } |
| 1018 | } |
| 1019 | return null; |
| 1020 | } |
| 1021 | |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1022 | boolean isMusicPage(int pageIndex) { |
| 1023 | return pageIndex >= 0 && pageIndex == getWidgetPosition(R.id.keyguard_transport_control); |
| 1024 | } |
| 1025 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1026 | private int getAppropriateWidgetPage(int musicTransportState) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1027 | // assumes at least one widget (besides camera + add) |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1028 | if (mAppWidgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1029 | final int childCount = mAppWidgetContainer.getChildCount(); |
| 1030 | for (int i = 0; i < childCount; i++) { |
| 1031 | if (mAppWidgetContainer.getWidgetPageAt(i).getContentAppWidgetId() |
| 1032 | == mAppWidgetToShow) { |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1033 | return i; |
| 1034 | } |
| 1035 | } |
| 1036 | mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID; |
| 1037 | } |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1038 | // if music playing, show transport |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1039 | if (musicTransportState == TRANSPORT_VISIBLE) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1040 | if (DEBUG) Log.d(TAG, "Music playing, show transport"); |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 1041 | return mAppWidgetContainer.getWidgetPageIndex(getOrCreateTransportControl()); |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1044 | // else show the right-most widget (except for camera) |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1045 | int rightMost = mAppWidgetContainer.getChildCount() - 1; |
Winson Chung | 6cf53bb | 2012-11-05 17:55:42 -0800 | [diff] [blame] | 1046 | if (mAppWidgetContainer.isCameraPage(rightMost)) { |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1047 | rightMost--; |
| 1048 | } |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1049 | if (DEBUG) Log.d(TAG, "Show right-most page " + rightMost); |
John Spurlock | 358148e | 2012-10-26 15:29:59 -0400 | [diff] [blame] | 1050 | return rightMost; |
| 1051 | } |
| 1052 | |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 1053 | private void enableUserSelectorIfNecessary() { |
Jim Miller | 26e6c2e | 2012-10-30 14:12:22 -0700 | [diff] [blame] | 1054 | if (!UserManager.supportsMultipleUsers()) { |
| 1055 | return; // device doesn't support multi-user mode |
| 1056 | } |
Jim Miller | f6ab5f9 | 2012-11-07 16:15:13 -0800 | [diff] [blame] | 1057 | final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1058 | if (um == null) { |
| 1059 | Throwable t = new Throwable(); |
| 1060 | t.fillInStackTrace(); |
| 1061 | Log.e(TAG, "user service is null.", t); |
| 1062 | return; |
| 1063 | } |
Jim Miller | 26e6c2e | 2012-10-30 14:12:22 -0700 | [diff] [blame] | 1064 | |
John Spurlock | 5f050e5 | 2012-10-27 10:44:19 -0400 | [diff] [blame] | 1065 | // 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] | 1066 | final List<UserInfo> users = um.getUsers(true); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1067 | if (users == null) { |
| 1068 | Throwable t = new Throwable(); |
| 1069 | t.fillInStackTrace(); |
| 1070 | Log.e(TAG, "list of users is null.", t); |
| 1071 | return; |
| 1072 | } |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 1073 | |
Jim Miller | f6ab5f9 | 2012-11-07 16:15:13 -0800 | [diff] [blame] | 1074 | final View multiUserView = findViewById(R.id.keyguard_user_selector); |
| 1075 | if (multiUserView == null) { |
| 1076 | Throwable t = new Throwable(); |
| 1077 | t.fillInStackTrace(); |
| 1078 | Log.e(TAG, "can't find user_selector in layout.", t); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1082 | if (users.size() > 1) { |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1083 | if (multiUserView instanceof KeyguardMultiUserSelectorView) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1084 | mKeyguardMultiUserSelectorView = (KeyguardMultiUserSelectorView) multiUserView; |
| 1085 | mKeyguardMultiUserSelectorView.setVisibility(View.VISIBLE); |
| 1086 | mKeyguardMultiUserSelectorView.addUsers(users); |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1087 | UserSwitcherCallback callback = new UserSwitcherCallback() { |
| 1088 | @Override |
| 1089 | public void hideSecurityView(int duration) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 1090 | getSecurityContainer().animate().alpha(0).setDuration(duration); |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 1091 | } |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 1092 | |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1093 | @Override |
| 1094 | public void showSecurityView() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 1095 | getSecurityContainer().setAlpha(1.0f); |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 1096 | } |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1097 | |
| 1098 | @Override |
| 1099 | public void showUnlockHint() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 1100 | if (getSecurityContainer() != null) { |
| 1101 | getSecurityContainer().showUsabilityHint(); |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | @Override |
| 1106 | public void userActivity() { |
| 1107 | if (mViewMediatorCallback != null) { |
| 1108 | mViewMediatorCallback.userActivity(); |
| 1109 | } |
| 1110 | } |
| 1111 | }; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1112 | mKeyguardMultiUserSelectorView.setCallback(callback); |
Chris Wren | d2dec00 | 2012-11-07 16:38:33 -0500 | [diff] [blame] | 1113 | } else { |
| 1114 | Throwable t = new Throwable(); |
| 1115 | t.fillInStackTrace(); |
| 1116 | if (multiUserView == null) { |
| 1117 | Log.e(TAG, "could not find the user_selector.", t); |
| 1118 | } else { |
| 1119 | Log.e(TAG, "user_selector is the wrong type.", t); |
| 1120 | } |
Chris Wren | 91f080c | 2012-11-07 15:20:27 -0500 | [diff] [blame] | 1121 | } |
Adam Cohen | 66b9fb166 | 2012-09-05 16:23:58 -0700 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1125 | @Override |
| 1126 | public void cleanUp() { |
Adam Cohen | 128f276 | 2013-04-18 13:37:05 -0700 | [diff] [blame] | 1127 | // Make sure we let go of all widgets and their package contexts promptly. If we don't do |
| 1128 | // this, and the associated application is uninstalled, it can cause a soft reboot. |
| 1129 | int count = mAppWidgetContainer.getChildCount(); |
| 1130 | for (int i = 0; i < count; i++) { |
| 1131 | KeyguardWidgetFrame frame = mAppWidgetContainer.getWidgetPageAt(i); |
| 1132 | frame.removeAllViews(); |
| 1133 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Michael Jurka | 76017ca | 2012-11-06 16:21:09 -0800 | [diff] [blame] | 1136 | public void goToWidget(int appWidgetId) { |
| 1137 | mAppWidgetToShow = appWidgetId; |
| 1138 | mSwitchPageRunnable.run(); |
| 1139 | } |
| 1140 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 1141 | @Override |
| 1142 | protected void showBouncer(boolean show) { |
| 1143 | super.showBouncer(show); |
| 1144 | mViewStateManager.showBouncer(show); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1145 | } |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1146 | |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 1147 | @Override |
| 1148 | public void onExternalMotionEvent(MotionEvent event) { |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1149 | mAppWidgetContainer.handleExternalCameraEvent(event); |
| 1150 | } |
| 1151 | |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 1152 | @Override |
| 1153 | protected void onCreateOptions(Bundle options) { |
| 1154 | if (options != null) { |
| 1155 | int widgetToShow = options.getInt(LockPatternUtils.KEYGUARD_SHOW_APPWIDGET, |
| 1156 | AppWidgetManager.INVALID_APPWIDGET_ID); |
| 1157 | if (widgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) { |
| 1158 | goToWidget(widgetToShow); |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1163 | } |