The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
| 20 | import android.app.IUserSwitchObserver; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
| 26 | import android.content.IntentFilter; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.database.ContentObserver; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
| 29 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import static android.os.BatteryManager.BATTERY_STATUS_FULL; |
| 31 | import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 32 | import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; |
| 33 | import static android.os.BatteryManager.EXTRA_STATUS; |
| 34 | import static android.os.BatteryManager.EXTRA_PLUGGED; |
| 35 | import static android.os.BatteryManager.EXTRA_LEVEL; |
| 36 | import static android.os.BatteryManager.EXTRA_HEALTH; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 37 | import android.media.AudioManager; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 38 | import android.media.IRemoteControlDisplay; |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 39 | import android.os.BatteryManager; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 40 | import android.os.Bundle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.os.Handler; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 42 | import android.os.IRemoteCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.os.Message; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 44 | import android.os.RemoteException; |
Amith Yamasani | e8e93a1 | 2013-05-09 18:12:30 -0700 | [diff] [blame] | 45 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.provider.Settings; |
Dianne Hackborn | b7e787f | 2009-05-07 15:55:42 -0700 | [diff] [blame] | 47 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 48 | import com.android.internal.telephony.IccCardConstants; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 49 | import com.android.internal.telephony.TelephonyIntents; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 50 | |
| 51 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 52 | import android.util.Log; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import com.google.android.collect.Lists; |
| 54 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 55 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import java.util.ArrayList; |
| 57 | |
| 58 | /** |
| 59 | * Watches for updates that may be interesting to the keyguard, and provides |
| 60 | * the up to date information as well as a registration for callbacks that care |
| 61 | * to be updated. |
| 62 | * |
| 63 | * Note: under time crunch, this has been extended to include some stuff that |
| 64 | * doesn't really belong here. see {@link #handleBatteryUpdate} where it shutdowns |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 65 | * the device, and {@link #getFailedUnlockAttempts()}, {@link #reportFailedAttempt()} |
| 66 | * and {@link #clearFailedUnlockAttempts()}. Maybe we should rename this 'KeyguardContext'... |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 67 | */ |
| 68 | public class KeyguardUpdateMonitor { |
| 69 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 70 | private static final String TAG = "KeyguardUpdateMonitor"; |
| 71 | private static final boolean DEBUG = false; |
| 72 | private static final boolean DEBUG_SIM_STATES = DEBUG || false; |
Uriel Rodriguez | aa24906 | 2012-06-13 17:30:13 -0400 | [diff] [blame] | 73 | private static final int FAILED_BIOMETRIC_UNLOCK_ATTEMPTS_BEFORE_BACKUP = 3; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 74 | private static final int LOW_BATTERY_THRESHOLD = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 75 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 76 | // Callback messages |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 77 | private static final int MSG_TIME_UPDATE = 301; |
| 78 | private static final int MSG_BATTERY_UPDATE = 302; |
| 79 | private static final int MSG_CARRIER_INFO_UPDATE = 303; |
| 80 | private static final int MSG_SIM_STATE_CHANGE = 304; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 81 | private static final int MSG_RINGER_MODE_CHANGED = 305; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 82 | private static final int MSG_PHONE_STATE_CHANGED = 306; |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 83 | private static final int MSG_CLOCK_VISIBILITY_CHANGED = 307; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 84 | private static final int MSG_DEVICE_PROVISIONED = 308; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 85 | private static final int MSG_DPM_STATE_CHANGED = 309; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 86 | private static final int MSG_USER_SWITCHING = 310; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 87 | private static final int MSG_USER_REMOVED = 311; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 88 | private static final int MSG_KEYGUARD_VISIBILITY_CHANGED = 312; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 89 | protected static final int MSG_BOOT_COMPLETED = 313; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 90 | private static final int MSG_USER_SWITCH_COMPLETE = 314; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 91 | private static final int MSG_SET_CURRENT_CLIENT_ID = 315; |
| 92 | protected static final int MSG_SET_PLAYBACK_STATE = 316; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 93 | protected static final int MSG_USER_INFO_CHANGED = 317; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 94 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 95 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 96 | private static KeyguardUpdateMonitor sInstance; |
| 97 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 98 | private final Context mContext; |
| 99 | |
| 100 | // Telephony state |
| 101 | private IccCardConstants.State mSimState = IccCardConstants.State.READY; |
| 102 | private CharSequence mTelephonyPlmn; |
| 103 | private CharSequence mTelephonySpn; |
| 104 | private int mRingMode; |
| 105 | private int mPhoneState; |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 106 | private boolean mKeyguardIsVisible; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 107 | private boolean mBootCompleted; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 108 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 109 | // Device provisioning state |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 110 | private boolean mDeviceProvisioned; |
| 111 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 112 | // Battery status |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 113 | private BatteryStatus mBatteryStatus; |
| 114 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 115 | // Password attempts |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 116 | private int mFailedAttempts = 0; |
| 117 | private int mFailedBiometricUnlockAttempts = 0; |
| 118 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 119 | private boolean mAlternateUnlockEnabled; |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 120 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 121 | private boolean mClockVisible; |
| 122 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 123 | private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>> |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 124 | mCallbacks = Lists.newArrayList(); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 125 | private ContentObserver mDeviceProvisionedObserver; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 126 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 127 | private boolean mSwitchingUser; |
| 128 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 129 | private final Handler mHandler = new Handler() { |
| 130 | @Override |
| 131 | public void handleMessage(Message msg) { |
| 132 | switch (msg.what) { |
| 133 | case MSG_TIME_UPDATE: |
| 134 | handleTimeUpdate(); |
| 135 | break; |
| 136 | case MSG_BATTERY_UPDATE: |
| 137 | handleBatteryUpdate((BatteryStatus) msg.obj); |
| 138 | break; |
| 139 | case MSG_CARRIER_INFO_UPDATE: |
| 140 | handleCarrierInfoUpdate(); |
| 141 | break; |
| 142 | case MSG_SIM_STATE_CHANGE: |
| 143 | handleSimStateChange((SimArgs) msg.obj); |
| 144 | break; |
| 145 | case MSG_RINGER_MODE_CHANGED: |
| 146 | handleRingerModeChange(msg.arg1); |
| 147 | break; |
| 148 | case MSG_PHONE_STATE_CHANGED: |
| 149 | handlePhoneStateChanged((String)msg.obj); |
| 150 | break; |
| 151 | case MSG_CLOCK_VISIBILITY_CHANGED: |
| 152 | handleClockVisibilityChanged(); |
| 153 | break; |
| 154 | case MSG_DEVICE_PROVISIONED: |
| 155 | handleDeviceProvisioned(); |
| 156 | break; |
| 157 | case MSG_DPM_STATE_CHANGED: |
| 158 | handleDevicePolicyManagerStateChanged(); |
| 159 | break; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 160 | case MSG_USER_SWITCHING: |
| 161 | handleUserSwitching(msg.arg1, (IRemoteCallback)msg.obj); |
| 162 | break; |
| 163 | case MSG_USER_SWITCH_COMPLETE: |
| 164 | handleUserSwitchComplete(msg.arg1); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 165 | break; |
| 166 | case MSG_USER_REMOVED: |
| 167 | handleUserRemoved(msg.arg1); |
| 168 | break; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 169 | case MSG_KEYGUARD_VISIBILITY_CHANGED: |
| 170 | handleKeyguardVisibilityChanged(msg.arg1); |
| 171 | break; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 172 | case MSG_BOOT_COMPLETED: |
| 173 | handleBootCompleted(); |
| 174 | break; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 175 | case MSG_SET_CURRENT_CLIENT_ID: |
| 176 | handleSetGenerationId(msg.arg1, msg.arg2 != 0, (PendingIntent) msg.obj); |
| 177 | break; |
| 178 | case MSG_SET_PLAYBACK_STATE: |
| 179 | handleSetPlaybackState(msg.arg1, msg.arg2, (Long) msg.obj); |
| 180 | break; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 181 | case MSG_USER_INFO_CHANGED: |
| 182 | handleUserInfoChanged(msg.arg1); |
| 183 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | }; |
| 187 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 188 | private AudioManager mAudioManager; |
| 189 | |
| 190 | static class DisplayClientState { |
| 191 | public int clientGeneration; |
| 192 | public boolean clearing; |
| 193 | public PendingIntent intent; |
| 194 | public int playbackState; |
| 195 | public long playbackEventTime; |
| 196 | } |
| 197 | |
| 198 | private DisplayClientState mDisplayClientState = new DisplayClientState(); |
| 199 | |
| 200 | /** |
| 201 | * This currently implements the bare minimum required to enable showing and hiding |
| 202 | * KeyguardTransportControl. There's a lot of client state to maintain which is why |
| 203 | * KeyguardTransportControl maintains an independent connection while it's showing. |
| 204 | */ |
| 205 | private final IRemoteControlDisplay.Stub mRemoteControlDisplay = |
| 206 | new IRemoteControlDisplay.Stub() { |
| 207 | |
Jean-Michel Trivi | bc43b4c | 2013-03-22 09:30:50 -0700 | [diff] [blame] | 208 | public void setPlaybackState(int generationId, int state, long stateChangeTimeMs, |
| 209 | long currentPosMs, float speed) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 210 | Message msg = mHandler.obtainMessage(MSG_SET_PLAYBACK_STATE, |
| 211 | generationId, state, stateChangeTimeMs); |
| 212 | mHandler.sendMessage(msg); |
| 213 | } |
| 214 | |
| 215 | public void setMetadata(int generationId, Bundle metadata) { |
| 216 | |
| 217 | } |
| 218 | |
Jean-Michel Trivi | 3261b53 | 2013-04-01 14:59:39 -0700 | [diff] [blame] | 219 | public void setTransportControlInfo(int generationId, int flags, int posCapabilities) { |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 220 | |
| 221 | } |
| 222 | |
| 223 | public void setArtwork(int generationId, Bitmap bitmap) { |
| 224 | |
| 225 | } |
| 226 | |
| 227 | public void setAllMetadata(int generationId, Bundle metadata, Bitmap bitmap) { |
| 228 | |
| 229 | } |
| 230 | |
| 231 | public void setCurrentClientId(int clientGeneration, PendingIntent mediaIntent, |
| 232 | boolean clearing) throws RemoteException { |
| 233 | Message msg = mHandler.obtainMessage(MSG_SET_CURRENT_CLIENT_ID, |
| 234 | clientGeneration, (clearing ? 1 : 0), mediaIntent); |
| 235 | mHandler.sendMessage(msg); |
| 236 | } |
| 237 | }; |
| 238 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 239 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 240 | |
| 241 | public void onReceive(Context context, Intent intent) { |
| 242 | final String action = intent.getAction(); |
| 243 | if (DEBUG) Log.d(TAG, "received broadcast " + action); |
| 244 | |
| 245 | if (Intent.ACTION_TIME_TICK.equals(action) |
| 246 | || Intent.ACTION_TIME_CHANGED.equals(action) |
| 247 | || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { |
| 248 | mHandler.sendMessage(mHandler.obtainMessage(MSG_TIME_UPDATE)); |
| 249 | } else if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)) { |
| 250 | mTelephonyPlmn = getTelephonyPlmnFrom(intent); |
| 251 | mTelephonySpn = getTelephonySpnFrom(intent); |
| 252 | mHandler.sendMessage(mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE)); |
| 253 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 254 | final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); |
| 255 | final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); |
| 256 | final int level = intent.getIntExtra(EXTRA_LEVEL, 0); |
| 257 | final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); |
| 258 | final Message msg = mHandler.obtainMessage( |
| 259 | MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health)); |
| 260 | mHandler.sendMessage(msg); |
| 261 | } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { |
| 262 | if (DEBUG_SIM_STATES) { |
| 263 | Log.v(TAG, "action " + action + " state" + |
| 264 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)); |
| 265 | } |
| 266 | mHandler.sendMessage(mHandler.obtainMessage( |
| 267 | MSG_SIM_STATE_CHANGE, SimArgs.fromIntent(intent))); |
| 268 | } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 269 | mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, |
| 270 | intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); |
| 271 | } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { |
| 272 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); |
| 273 | mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); |
| 274 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 275 | .equals(action)) { |
| 276 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DPM_STATE_CHANGED)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 277 | } else if (Intent.ACTION_USER_REMOVED.equals(action)) { |
| 278 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED, |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 279 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0)); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 280 | } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
| 281 | mHandler.sendMessage(mHandler.obtainMessage(MSG_BOOT_COMPLETED)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | }; |
Jim Miller | 2de5ee8 | 2012-06-14 22:22:50 -0700 | [diff] [blame] | 285 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 286 | private final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() { |
| 287 | |
| 288 | public void onReceive(Context context, Intent intent) { |
| 289 | final String action = intent.getAction(); |
| 290 | if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
| 291 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED, |
| 292 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0)); |
| 293 | } |
| 294 | } |
| 295 | }; |
| 296 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 297 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 298 | * When we receive a |
| 299 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 300 | * and then pass a result via our handler to {@link KeyguardUpdateMonitor#handleSimStateChange}, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 301 | * we need a single object to pass to the handler. This class helps decode |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 302 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 303 | */ |
| 304 | private static class SimArgs { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 305 | public final IccCardConstants.State simState; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 306 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 307 | SimArgs(IccCardConstants.State state) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 308 | simState = state; |
| 309 | } |
| 310 | |
| 311 | static SimArgs fromIntent(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 312 | IccCardConstants.State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 313 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 314 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 315 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 316 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 317 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 318 | final String absentReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 319 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 320 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 321 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 322 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 323 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 324 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 325 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 326 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 327 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 328 | state = IccCardConstants.State.READY; |
| 329 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 330 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 331 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 332 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 333 | state = IccCardConstants.State.PIN_REQUIRED; |
| 334 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 335 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 336 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 337 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 338 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 339 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 340 | state = IccCardConstants.State.NETWORK_LOCKED; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 341 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
| 342 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
| 343 | // This is required because telephony doesn't return to "READY" after |
| 344 | // these state transitions. See bug 7197471. |
| 345 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 346 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 347 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 348 | } |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 349 | return new SimArgs(state); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | public String toString() { |
| 353 | return simState.toString(); |
| 354 | } |
| 355 | } |
| 356 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 357 | /* package */ static class BatteryStatus { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 358 | public final int status; |
| 359 | public final int level; |
| 360 | public final int plugged; |
| 361 | public final int health; |
| 362 | public BatteryStatus(int status, int level, int plugged, int health) { |
| 363 | this.status = status; |
| 364 | this.level = level; |
| 365 | this.plugged = plugged; |
| 366 | this.health = health; |
| 367 | } |
| 368 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 369 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 370 | * Determine whether the device is plugged in (USB, power, or wireless). |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 371 | * @return true if the device is plugged in. |
| 372 | */ |
| 373 | boolean isPluggedIn() { |
| 374 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 375 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 376 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 381 | * battery level, so this allows either battery level or status to determine if the |
| 382 | * battery is charged. |
| 383 | * @return true if the device is charged |
| 384 | */ |
| 385 | public boolean isCharged() { |
| 386 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Whether battery is low and needs to be charged. |
| 391 | * @return true if battery is low |
| 392 | */ |
| 393 | public boolean isBatteryLow() { |
| 394 | return level < LOW_BATTERY_THRESHOLD; |
| 395 | } |
| 396 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 399 | public static KeyguardUpdateMonitor getInstance(Context context) { |
| 400 | if (sInstance == null) { |
| 401 | sInstance = new KeyguardUpdateMonitor(context); |
| 402 | } |
| 403 | return sInstance; |
| 404 | } |
| 405 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 406 | protected void handleSetGenerationId(int clientGeneration, boolean clearing, PendingIntent p) { |
| 407 | mDisplayClientState.clientGeneration = clientGeneration; |
| 408 | mDisplayClientState.clearing = clearing; |
| 409 | mDisplayClientState.intent = p; |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 410 | if (DEBUG) |
| 411 | Log.v(TAG, "handleSetGenerationId(g=" + clientGeneration + ", clear=" + clearing + ")"); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 412 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 413 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 414 | if (cb != null) { |
| 415 | cb.onMusicClientIdChanged(clientGeneration, clearing, p); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | protected void handleSetPlaybackState(int generationId, int playbackState, long eventTime) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 421 | if (DEBUG) |
| 422 | Log.v(TAG, "handleSetPlaybackState(gen=" + generationId |
| 423 | + ", state=" + playbackState + ", t=" + eventTime + ")"); |
| 424 | mDisplayClientState.playbackState = playbackState; |
| 425 | mDisplayClientState.playbackEventTime = eventTime; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 426 | if (generationId == mDisplayClientState.clientGeneration) { |
| 427 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 428 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 429 | if (cb != null) { |
| 430 | cb.onMusicPlaybackStateChanged(playbackState, eventTime); |
| 431 | } |
| 432 | } |
| 433 | } else { |
| 434 | Log.w(TAG, "Ignoring generation id " + generationId + " because it's not current"); |
| 435 | } |
| 436 | } |
| 437 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 438 | private void handleUserInfoChanged(int userId) { |
| 439 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 440 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 441 | if (cb != null) { |
| 442 | cb.onUserInfoChanged(userId); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 447 | private KeyguardUpdateMonitor(Context context) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 448 | mContext = context; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 449 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 450 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 451 | // Since device can't be un-provisioned, we only need to register a content observer |
| 452 | // to update mDeviceProvisioned when we are... |
| 453 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 454 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 455 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 456 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 457 | // Take a guess at initial SIM state, battery status and PLMN until we get an update |
| 458 | mSimState = IccCardConstants.State.NOT_READY; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 459 | mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 460 | mTelephonyPlmn = getDefaultPlmn(); |
| 461 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 462 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 463 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 464 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 465 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 466 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 467 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
| 468 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 469 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 470 | filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 471 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 472 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 473 | filter.addAction(Intent.ACTION_USER_REMOVED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 474 | context.registerReceiver(mBroadcastReceiver, filter); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 475 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 476 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 477 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 478 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 479 | context.registerReceiver(mBroadcastReceiver, bootCompleteFilter); |
| 480 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 481 | final IntentFilter userInfoFilter = new IntentFilter(Intent.ACTION_USER_INFO_CHANGED); |
| 482 | context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, userInfoFilter, |
| 483 | null, null); |
| 484 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 485 | try { |
| 486 | ActivityManagerNative.getDefault().registerUserSwitchObserver( |
| 487 | new IUserSwitchObserver.Stub() { |
| 488 | @Override |
| 489 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 490 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 491 | newUserId, 0, reply)); |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 492 | mSwitchingUser = true; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 493 | } |
| 494 | @Override |
| 495 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 496 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
| 497 | newUserId)); |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 498 | mSwitchingUser = false; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 499 | } |
| 500 | }); |
| 501 | } catch (RemoteException e) { |
| 502 | // TODO Auto-generated catch block |
| 503 | e.printStackTrace(); |
| 504 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 505 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 506 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 507 | private boolean isDeviceProvisionedInSettingsDb() { |
| 508 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 509 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 510 | } |
| 511 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 512 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 513 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 514 | @Override |
| 515 | public void onChange(boolean selfChange) { |
| 516 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 517 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 518 | if (mDeviceProvisioned) { |
| 519 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 520 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 521 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 522 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 523 | }; |
| 524 | |
| 525 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 526 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 527 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 528 | |
| 529 | // prevent a race condition between where we check the flag and where we register the |
| 530 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 531 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 532 | if (provisioned != mDeviceProvisioned) { |
| 533 | mDeviceProvisioned = provisioned; |
| 534 | if (mDeviceProvisioned) { |
| 535 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED)); |
| 536 | } |
| 537 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 542 | */ |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 543 | protected void handleDevicePolicyManagerStateChanged() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 544 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 545 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 546 | if (cb != null) { |
| 547 | cb.onDevicePolicyManagerStateChanged(); |
| 548 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 552 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 553 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 554 | */ |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 555 | protected void handleUserSwitching(int userId, IRemoteCallback reply) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 556 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 557 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 558 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 559 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 560 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 561 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 562 | try { |
| 563 | reply.sendResult(null); |
| 564 | } catch (RemoteException e) { |
| 565 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 568 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 569 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 570 | */ |
| 571 | protected void handleUserSwitchComplete(int userId) { |
| 572 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 573 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 574 | if (cb != null) { |
| 575 | cb.onUserSwitchComplete(userId); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 581 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 582 | */ |
| 583 | protected void handleBootCompleted() { |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 584 | mBootCompleted = true; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 585 | mAudioManager = new AudioManager(mContext); |
| 586 | mAudioManager.registerRemoteControlDisplay(mRemoteControlDisplay); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 587 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 588 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 589 | if (cb != null) { |
| 590 | cb.onBootCompleted(); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 596 | * We need to store this state in the KeyguardUpdateMonitor since this class will not be |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 597 | * destroyed. |
| 598 | */ |
| 599 | public boolean hasBootCompleted() { |
| 600 | return mBootCompleted; |
| 601 | } |
| 602 | |
| 603 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 604 | * Handle {@link #MSG_USER_REMOVED} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 605 | */ |
| 606 | protected void handleUserRemoved(int userId) { |
| 607 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 608 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 609 | if (cb != null) { |
| 610 | cb.onUserRemoved(userId); |
| 611 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 617 | */ |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 618 | protected void handleDeviceProvisioned() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 619 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 620 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 621 | if (cb != null) { |
| 622 | cb.onDeviceProvisioned(); |
| 623 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 624 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 625 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 626 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 627 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 628 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 634 | */ |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 635 | protected void handlePhoneStateChanged(String newState) { |
| 636 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 637 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 638 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 639 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 640 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 641 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 642 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 643 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 644 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 645 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 646 | if (cb != null) { |
| 647 | cb.onPhoneStateChanged(mPhoneState); |
| 648 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 652 | /** |
| 653 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 654 | */ |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 655 | protected void handleRingerModeChange(int mode) { |
| 656 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 657 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 658 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 659 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 660 | if (cb != null) { |
| 661 | cb.onRingerModeChanged(mode); |
| 662 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 666 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 667 | * Handle {@link #MSG_TIME_UPDATE} |
| 668 | */ |
| 669 | private void handleTimeUpdate() { |
| 670 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 671 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 672 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 673 | if (cb != null) { |
| 674 | cb.onTimeChanged(); |
| 675 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 681 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 682 | private void handleBatteryUpdate(BatteryStatus status) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 683 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 684 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 685 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 686 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 687 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 688 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 689 | if (cb != null) { |
| 690 | cb.onRefreshBatteryInfo(status); |
| 691 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Handle {@link #MSG_CARRIER_INFO_UPDATE} |
| 698 | */ |
| 699 | private void handleCarrierInfoUpdate() { |
| 700 | if (DEBUG) Log.d(TAG, "handleCarrierInfoUpdate: plmn = " + mTelephonyPlmn |
| 701 | + ", spn = " + mTelephonySpn); |
| 702 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 703 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 704 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 705 | if (cb != null) { |
| 706 | cb.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn); |
| 707 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 713 | */ |
| 714 | private void handleSimStateChange(SimArgs simArgs) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 715 | final IccCardConstants.State state = simArgs.simState; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 716 | |
| 717 | if (DEBUG) { |
| 718 | Log.d(TAG, "handleSimStateChange: intentValue = " + simArgs + " " |
| 719 | + "state resolved to " + state.toString()); |
| 720 | } |
| 721 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 722 | if (state != IccCardConstants.State.UNKNOWN && state != mSimState) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | mSimState = state; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 724 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 725 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 726 | if (cb != null) { |
| 727 | cb.onSimStateChanged(state); |
| 728 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 733 | /** |
| 734 | * Handle {@link #MSG_CLOCK_VISIBILITY_CHANGED} |
| 735 | */ |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 736 | private void handleClockVisibilityChanged() { |
| 737 | if (DEBUG) Log.d(TAG, "handleClockVisibilityChanged()"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 738 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 739 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 740 | if (cb != null) { |
| 741 | cb.onClockVisibilityChanged(); |
| 742 | } |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 746 | /** |
| 747 | * Handle {@link #MSG_KEYGUARD_VISIBILITY_CHANGED} |
| 748 | */ |
| 749 | private void handleKeyguardVisibilityChanged(int showing) { |
| 750 | if (DEBUG) Log.d(TAG, "handleKeyguardVisibilityChanged(" + showing + ")"); |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 751 | boolean isShowing = (showing == 1); |
| 752 | mKeyguardIsVisible = isShowing; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 753 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 754 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 755 | if (cb != null) { |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 756 | cb.onKeyguardVisibilityChanged(isShowing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 761 | public boolean isKeyguardVisible() { |
| 762 | return mKeyguardIsVisible; |
| 763 | } |
| 764 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 765 | public boolean isSwitchingUser() { |
| 766 | return mSwitchingUser; |
| 767 | } |
| 768 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 769 | private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 770 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 771 | final boolean wasPluggedIn = old.isPluggedIn(); |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 772 | final boolean stateChangedWhilePluggedIn = |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 773 | wasPluggedIn == true && nowPluggedIn == true |
| 774 | && (old.status != current.status); |
| 775 | |
| 776 | // change in plug state is always interesting |
| 777 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 778 | return true; |
| 779 | } |
| 780 | |
| 781 | // change in battery level while plugged in |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 782 | if (nowPluggedIn && old.level != current.level) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 783 | return true; |
| 784 | } |
| 785 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 786 | // change where battery needs charging |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 787 | if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 788 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 789 | } |
| 790 | return false; |
| 791 | } |
| 792 | |
| 793 | /** |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 794 | * @param intent The intent with action {@link TelephonyIntents#SPN_STRINGS_UPDATED_ACTION} |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 795 | * @return The string to use for the plmn, or null if it should not be shown. |
| 796 | */ |
| 797 | private CharSequence getTelephonyPlmnFrom(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 798 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) { |
| 799 | final String plmn = intent.getStringExtra(TelephonyIntents.EXTRA_PLMN); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 800 | return (plmn != null) ? plmn : getDefaultPlmn(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 801 | } |
| 802 | return null; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * @return The default plmn (no service) |
| 807 | */ |
| 808 | private CharSequence getDefaultPlmn() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 809 | return mContext.getResources().getText(R.string.keyguard_carrier_default); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /** |
| 813 | * @param intent The intent with action {@link Telephony.Intents#SPN_STRINGS_UPDATED_ACTION} |
| 814 | * @return The string to use for the plmn, or null if it should not be shown. |
| 815 | */ |
| 816 | private CharSequence getTelephonySpnFrom(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 817 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) { |
| 818 | final String spn = intent.getStringExtra(TelephonyIntents.EXTRA_SPN); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 819 | if (spn != null) { |
| 820 | return spn; |
| 821 | } |
| 822 | } |
| 823 | return null; |
| 824 | } |
| 825 | |
| 826 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 827 | * Remove the given observer's callback. |
| 828 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 829 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 830 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 831 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
| 832 | if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback); |
| 833 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 834 | if (mCallbacks.get(i).get() == callback) { |
| 835 | mCallbacks.remove(i); |
| 836 | } |
| 837 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 841 | * Register to receive notifications about general keyguard information |
| 842 | * (see {@link InfoCallback}. |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 843 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 844 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 845 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 846 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 847 | // Prevent adding duplicate callbacks |
| 848 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 849 | if (mCallbacks.get(i).get() == callback) { |
| 850 | if (DEBUG) Log.e(TAG, "Object tried to add another callback", |
| 851 | new Exception("Called by")); |
| 852 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 855 | mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback)); |
| 856 | removeCallback(null); // remove unused references |
| 857 | sendUpdates(callback); |
| 858 | } |
| 859 | |
| 860 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 861 | // Notify listener of the current state |
| 862 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 863 | callback.onTimeChanged(); |
| 864 | callback.onRingerModeChanged(mRingMode); |
| 865 | callback.onPhoneStateChanged(mPhoneState); |
| 866 | callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn); |
| 867 | callback.onClockVisibilityChanged(); |
| 868 | callback.onSimStateChanged(mSimState); |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 869 | callback.onMusicClientIdChanged( |
| 870 | mDisplayClientState.clientGeneration, |
| 871 | mDisplayClientState.clearing, |
| 872 | mDisplayClientState.intent); |
| 873 | callback.onMusicPlaybackStateChanged(mDisplayClientState.playbackState, |
| 874 | mDisplayClientState.playbackEventTime); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 877 | public void sendKeyguardVisibilityChanged(boolean showing) { |
| 878 | if (DEBUG) Log.d(TAG, "sendKeyguardVisibilityChanged(" + showing + ")"); |
| 879 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_VISIBILITY_CHANGED); |
| 880 | message.arg1 = showing ? 1 : 0; |
| 881 | message.sendToTarget(); |
| 882 | } |
| 883 | |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 884 | public void reportClockVisible(boolean visible) { |
| 885 | mClockVisible = visible; |
| 886 | mHandler.obtainMessage(MSG_CLOCK_VISIBILITY_CHANGED).sendToTarget(); |
| 887 | } |
| 888 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 889 | public IccCardConstants.State getSimState() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 890 | return mSimState; |
| 891 | } |
| 892 | |
| 893 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 894 | * Report that the user successfully entered the SIM PIN or PUK/SIM PIN so we |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 895 | * have the information earlier than waiting for the intent |
| 896 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 897 | * |
| 898 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 899 | * through mHandler, this *must* be called from the UI thread. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 900 | */ |
John Wang | 0f7b3f8 | 2011-05-31 11:20:55 -0700 | [diff] [blame] | 901 | public void reportSimUnlocked() { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 902 | handleSimStateChange(new SimArgs(IccCardConstants.State.READY)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 903 | } |
| 904 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 905 | public CharSequence getTelephonyPlmn() { |
| 906 | return mTelephonyPlmn; |
| 907 | } |
| 908 | |
| 909 | public CharSequence getTelephonySpn() { |
| 910 | return mTelephonySpn; |
| 911 | } |
| 912 | |
| 913 | /** |
| 914 | * @return Whether the device is provisioned (whether they have gone through |
| 915 | * the setup wizard) |
| 916 | */ |
| 917 | public boolean isDeviceProvisioned() { |
| 918 | return mDeviceProvisioned; |
| 919 | } |
| 920 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 921 | public int getFailedUnlockAttempts() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 922 | return mFailedAttempts; |
| 923 | } |
| 924 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 925 | public void clearFailedUnlockAttempts() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 926 | mFailedAttempts = 0; |
Brian Colonna | ea8441e | 2012-04-25 17:51:49 -0400 | [diff] [blame] | 927 | mFailedBiometricUnlockAttempts = 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 928 | } |
| 929 | |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 930 | public void reportFailedUnlockAttempt() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 931 | mFailedAttempts++; |
| 932 | } |
Jim Miller | 1c18828 | 2011-08-08 22:27:58 -0700 | [diff] [blame] | 933 | |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 934 | public boolean isClockVisible() { |
| 935 | return mClockVisible; |
| 936 | } |
| 937 | |
Brian Colonna | 267cb2b | 2011-09-26 13:52:25 -0400 | [diff] [blame] | 938 | public int getPhoneState() { |
| 939 | return mPhoneState; |
| 940 | } |
Steven Ross | b9430d2 | 2011-11-23 07:54:09 -0500 | [diff] [blame] | 941 | |
Brian Colonna | ea8441e | 2012-04-25 17:51:49 -0400 | [diff] [blame] | 942 | public void reportFailedBiometricUnlockAttempt() { |
| 943 | mFailedBiometricUnlockAttempts++; |
Steven Ross | b9430d2 | 2011-11-23 07:54:09 -0500 | [diff] [blame] | 944 | } |
| 945 | |
Brian Colonna | ea8441e | 2012-04-25 17:51:49 -0400 | [diff] [blame] | 946 | public boolean getMaxBiometricUnlockAttemptsReached() { |
| 947 | return mFailedBiometricUnlockAttempts >= FAILED_BIOMETRIC_UNLOCK_ATTEMPTS_BEFORE_BACKUP; |
Steven Ross | b9430d2 | 2011-11-23 07:54:09 -0500 | [diff] [blame] | 948 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 949 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 950 | public boolean isAlternateUnlockEnabled() { |
| 951 | return mAlternateUnlockEnabled; |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 954 | public void setAlternateUnlockEnabled(boolean enabled) { |
| 955 | mAlternateUnlockEnabled = enabled; |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 956 | } |
| 957 | |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 958 | public boolean isSimLocked() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 959 | return isSimLocked(mSimState); |
| 960 | } |
| 961 | |
| 962 | public static boolean isSimLocked(IccCardConstants.State state) { |
| 963 | return state == IccCardConstants.State.PIN_REQUIRED |
| 964 | || state == IccCardConstants.State.PUK_REQUIRED |
| 965 | || state == IccCardConstants.State.PERM_DISABLED; |
| 966 | } |
| 967 | |
| 968 | public boolean isSimPinSecure() { |
| 969 | return isSimPinSecure(mSimState); |
| 970 | } |
| 971 | |
| 972 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
| 973 | final IccCardConstants.State simState = state; |
| 974 | return (simState == IccCardConstants.State.PIN_REQUIRED |
| 975 | || simState == IccCardConstants.State.PUK_REQUIRED |
| 976 | || simState == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 977 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 978 | |
| 979 | public DisplayClientState getCachedDisplayClientState() { |
| 980 | return mDisplayClientState; |
| 981 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 982 | } |