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