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