Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.KeyguardManager; |
| 21 | import android.app.PendingIntent; |
| 22 | import android.app.ProgressDialog; |
Yorke Lee | ca6ec3b | 2013-08-29 14:21:43 -0700 | [diff] [blame] | 23 | import android.app.TaskStackBuilder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.bluetooth.BluetoothAdapter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.bluetooth.IBluetoothHeadsetPhone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
| 27 | import android.content.ComponentName; |
| 28 | import android.content.ContentResolver; |
| 29 | import android.content.Context; |
| 30 | import android.content.ContextWrapper; |
| 31 | import android.content.Intent; |
| 32 | import android.content.IntentFilter; |
| 33 | import android.content.ServiceConnection; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.media.AudioManager; |
| 35 | import android.net.Uri; |
| 36 | import android.os.AsyncResult; |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 37 | import android.os.Bundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
| 39 | import android.os.IBinder; |
| 40 | import android.os.IPowerManager; |
| 41 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.os.PowerManager; |
| 44 | import android.os.RemoteException; |
| 45 | import android.os.ServiceManager; |
| 46 | import android.os.SystemClock; |
| 47 | import android.os.SystemProperties; |
| 48 | import android.os.UpdateLock; |
| 49 | import android.os.UserHandle; |
| 50 | import android.preference.PreferenceManager; |
| 51 | import android.provider.Settings.System; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 52 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.telephony.ServiceState; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 54 | import android.telephony.SubscriptionInfo; |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 55 | import android.telephony.SubscriptionManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.util.Log; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | |
| 58 | import com.android.internal.telephony.Call; |
| 59 | import com.android.internal.telephony.CallManager; |
| 60 | import com.android.internal.telephony.IccCard; |
| 61 | import com.android.internal.telephony.IccCardConstants; |
| 62 | import com.android.internal.telephony.MmiCode; |
| 63 | import com.android.internal.telephony.Phone; |
| 64 | import com.android.internal.telephony.PhoneConstants; |
| 65 | import com.android.internal.telephony.PhoneFactory; |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 66 | import com.android.internal.telephony.SubscriptionController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.TelephonyCapabilities; |
| 68 | import com.android.internal.telephony.TelephonyIntents; |
Santos Cordon | 352ff65 | 2014-05-30 01:41:45 -0700 | [diff] [blame] | 69 | import com.android.phone.common.CallLogAsync; |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 70 | import com.android.phone.settings.SettingsConstants; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | import com.android.server.sip.SipService; |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 72 | import com.android.services.telephony.activation.SimActivationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 74 | import java.util.ArrayList; |
| 75 | import java.util.List; |
| 76 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Global state for the telephony subsystem when running in the primary |
| 79 | * phone process. |
| 80 | */ |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 81 | public class PhoneGlobals extends ContextWrapper { |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 82 | public static final String LOG_TAG = "PhoneApp"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Phone app-wide debug level: |
| 86 | * 0 - no debug logging |
| 87 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 88 | * "eng" and "userdebug" builds but not "user" builds) |
| 89 | * 2 - ultra-verbose debug logging |
| 90 | * |
| 91 | * Most individual classes in the phone app have a local DBG constant, |
| 92 | * typically set to |
| 93 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 94 | * or else |
| 95 | * (PhoneApp.DBG_LEVEL >= 2) |
| 96 | * depending on the desired verbosity. |
| 97 | * |
| 98 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 99 | */ |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 100 | public static final int DBG_LEVEL = 0; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 101 | |
| 102 | private static final boolean DBG = |
| 103 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 104 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 105 | |
| 106 | // Message codes; see mHandler below. |
| 107 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; |
| 110 | private static final int EVENT_DATA_ROAMING_OK = 11; |
| 111 | private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; |
Bryce Lee | 5ccda61 | 2015-12-04 15:44:16 -0800 | [diff] [blame^] | 112 | private static final int EVENT_START_SIP_SERVICE = 13; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | |
| 114 | // The MMI codes are also used by the InCallScreen. |
| 115 | public static final int MMI_INITIATE = 51; |
| 116 | public static final int MMI_COMPLETE = 52; |
| 117 | public static final int MMI_CANCEL = 53; |
| 118 | // Don't use message codes larger than 99 here; those are reserved for |
| 119 | // the individual Activities of the Phone UI. |
| 120 | |
| 121 | /** |
| 122 | * Allowable values for the wake lock code. |
| 123 | * SLEEP means the device can be put to sleep. |
| 124 | * PARTIAL means wake the processor, but we display can be kept off. |
| 125 | * FULL means wake both the processor and the display. |
| 126 | */ |
| 127 | public enum WakeState { |
| 128 | SLEEP, |
| 129 | PARTIAL, |
| 130 | FULL |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Intent Action used for hanging up the current call from Notification bar. This will |
| 135 | * choose first ringing call, first active call, or first background call (typically in |
| 136 | * HOLDING state). |
| 137 | */ |
| 138 | public static final String ACTION_HANG_UP_ONGOING_CALL = |
| 139 | "com.android.phone.ACTION_HANG_UP_ONGOING_CALL"; |
| 140 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | private static PhoneGlobals sMe; |
| 142 | |
| 143 | // A few important fields we expose to the rest of the package |
| 144 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | CallController callController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 147 | CallNotifier notifier; |
| 148 | CallerInfoCache callerInfoCache; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 149 | NotificationMgr notificationMgr; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 150 | public PhoneInterfaceManager phoneMgr; |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 151 | public SimActivationManager simActivationManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 152 | CarrierConfigLoader configLoader; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 153 | |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 154 | private CallGatewayManager callGatewayManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 155 | private CallStateMonitor callStateMonitor; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 156 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | static boolean sVoiceCapable = true; |
| 158 | |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 159 | // TODO: Remove, no longer used. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | CdmaPhoneCallState cdmaPhoneCallState; |
| 161 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | // The currently-active PUK entry activity and progress dialog. |
| 163 | // Normally, these are the Emergency Dialer and the subsequent |
| 164 | // progress dialog. null if there is are no such objects in |
| 165 | // the foreground. |
| 166 | private Activity mPUKEntryActivity; |
| 167 | private ProgressDialog mPUKEntryProgressDialog; |
| 168 | |
| 169 | private boolean mIsSimPinEnabled; |
| 170 | private String mCachedSimPin; |
| 171 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | // True if we are beginning a call, but the phone state has not changed yet |
| 173 | private boolean mBeginningCall; |
Yorke Lee | 4d2db1c | 2014-11-06 11:37:09 -0800 | [diff] [blame] | 174 | private boolean mDataDisconnectedDueToRoaming = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | |
| 176 | // Last phone state seen by updatePhoneState() |
| 177 | private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE; |
| 178 | |
| 179 | private WakeState mWakeState = WakeState.SLEEP; |
| 180 | |
| 181 | private PowerManager mPowerManager; |
| 182 | private IPowerManager mPowerManagerService; |
| 183 | private PowerManager.WakeLock mWakeLock; |
| 184 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | |
| 187 | private UpdateLock mUpdateLock; |
| 188 | |
| 189 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 190 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 191 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | /** boolean indicating restoring mute state on InCallScreen.onResume() */ |
| 193 | private boolean mShouldRestoreMuteOnInCallResume; |
| 194 | |
| 195 | /** |
| 196 | * The singleton OtaUtils instance used for OTASP calls. |
| 197 | * |
| 198 | * The OtaUtils instance is created lazily the first time we need to |
| 199 | * make an OTASP call, regardless of whether it's an interactive or |
| 200 | * non-interactive OTASP call. |
| 201 | */ |
| 202 | public OtaUtils otaUtils; |
| 203 | |
| 204 | // Following are the CDMA OTA information Objects used during OTA Call. |
| 205 | // cdmaOtaProvisionData object store static OTA information that needs |
| 206 | // to be maintained even during Slider open/close scenarios. |
| 207 | // cdmaOtaConfigData object stores configuration info to control visiblity |
| 208 | // of each OTA Screens. |
| 209 | // cdmaOtaScreenState object store OTA Screen State information. |
| 210 | public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; |
| 211 | public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; |
| 212 | public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; |
| 213 | public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState; |
| 214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Set the restore mute state flag. Used when we are setting the mute state |
| 217 | * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)} |
| 218 | */ |
| 219 | /*package*/void setRestoreMuteOnInCallResume (boolean mode) { |
| 220 | mShouldRestoreMuteOnInCallResume = mode; |
| 221 | } |
| 222 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 223 | Handler mHandler = new Handler() { |
| 224 | @Override |
| 225 | public void handleMessage(Message msg) { |
| 226 | PhoneConstants.State phoneState; |
| 227 | switch (msg.what) { |
| 228 | // Starts the SIP service. It's a no-op if SIP API is not supported |
| 229 | // on the deivce. |
| 230 | // TODO: Having the phone process host the SIP service is only |
| 231 | // temporary. Will move it to a persistent communication process |
| 232 | // later. |
| 233 | case EVENT_START_SIP_SERVICE: |
| 234 | SipService.start(getApplicationContext()); |
| 235 | break; |
| 236 | |
| 237 | // TODO: This event should be handled by the lock screen, just |
| 238 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 239 | case EVENT_SIM_NETWORK_LOCKED: |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 240 | if (getCarrierConfig().getBoolean( |
| 241 | CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 242 | // Some products don't have the concept of a "SIM network lock" |
| 243 | Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " |
| 244 | + "not showing 'SIM network unlock' PIN entry screen"); |
| 245 | } else { |
| 246 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 247 | // The user won't be able to do anything else until |
| 248 | // they enter a valid SIM network PIN. |
| 249 | Log.i(LOG_TAG, "show sim depersonal panel"); |
Tyler Gunn | 52a3707 | 2015-08-24 14:23:19 -0700 | [diff] [blame] | 250 | IccNetworkDepersonalizationPanel.showDialog(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | } |
| 252 | break; |
| 253 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | case EVENT_DATA_ROAMING_DISCONNECTED: |
| 255 | notificationMgr.showDataDisconnectedRoaming(); |
| 256 | break; |
| 257 | |
| 258 | case EVENT_DATA_ROAMING_OK: |
| 259 | notificationMgr.hideDataDisconnectedRoaming(); |
| 260 | break; |
| 261 | |
| 262 | case MMI_COMPLETE: |
| 263 | onMMIComplete((AsyncResult) msg.obj); |
| 264 | break; |
| 265 | |
| 266 | case MMI_CANCEL: |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 267 | PhoneUtils.cancelMmiCode(mCM.getFgPhone()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 268 | break; |
| 269 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | case EVENT_SIM_STATE_CHANGED: |
| 271 | // Marks the event where the SIM goes into ready state. |
| 272 | // Right now, this is only used for the PUK-unlocking |
| 273 | // process. |
| 274 | if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) { |
| 275 | // when the right event is triggered and there |
| 276 | // are UI objects in the foreground, we close |
| 277 | // them to display the lock panel. |
| 278 | if (mPUKEntryActivity != null) { |
| 279 | mPUKEntryActivity.finish(); |
| 280 | mPUKEntryActivity = null; |
| 281 | } |
| 282 | if (mPUKEntryProgressDialog != null) { |
| 283 | mPUKEntryProgressDialog.dismiss(); |
| 284 | mPUKEntryProgressDialog = null; |
| 285 | } |
| 286 | } |
| 287 | break; |
| 288 | |
| 289 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 290 | //TODO: handle message here; |
| 291 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | }; |
| 295 | |
| 296 | public PhoneGlobals(Context context) { |
| 297 | super(context); |
| 298 | sMe = this; |
| 299 | } |
| 300 | |
| 301 | public void onCreate() { |
| 302 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 303 | |
| 304 | ContentResolver resolver = getContentResolver(); |
| 305 | |
| 306 | // Cache the "voice capable" flag. |
| 307 | // This flag currently comes from a resource (which is |
| 308 | // overrideable on a per-product basis): |
| 309 | sVoiceCapable = |
| 310 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 311 | // ...but this might eventually become a PackageManager "system |
| 312 | // feature" instead, in which case we'd do something like: |
| 313 | // sVoiceCapable = |
| 314 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 315 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 316 | if (mCM == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 317 | // Initialize the telephony framework |
| 318 | PhoneFactory.makeDefaultPhones(this); |
| 319 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 320 | // Start TelephonyDebugService After the default phone is created. |
| 321 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 322 | startService(intent); |
| 323 | |
| 324 | mCM = CallManager.getInstance(); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 325 | for (Phone phone : PhoneFactory.getPhones()) { |
| 326 | mCM.registerPhone(phone); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 328 | |
| 329 | // Create the NotificationMgr singleton, which is used to display |
| 330 | // status bar icons and control other status bar behavior. |
| 331 | notificationMgr = NotificationMgr.init(this); |
| 332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE); |
| 334 | |
Anthony Lee | 03ebdfc | 2015-07-27 08:12:02 -0700 | [diff] [blame] | 335 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 336 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 337 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | // before registering for phone state changes |
| 340 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 341 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 342 | // lock used to keep the processor awake, when we don't care for the display. |
| 343 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 344 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | |
| 346 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 347 | |
| 348 | // get a handle to the service so that we can use it later when we |
| 349 | // want to set the poke lock. |
| 350 | mPowerManagerService = IPowerManager.Stub.asInterface( |
| 351 | ServiceManager.getService("power")); |
| 352 | |
| 353 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 354 | // during phone calls. |
| 355 | mUpdateLock = new UpdateLock("phone"); |
| 356 | |
| 357 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 358 | |
| 359 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 360 | |
Jay Shrauner | 21a7534 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 361 | callGatewayManager = CallGatewayManager.getInstance(); |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 362 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | // Create the CallController singleton, which is the interface |
| 364 | // to the telephony layer for user-initiated telephony functionality |
| 365 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 366 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 369 | // send-to-voicemail settings. |
| 370 | // |
| 371 | // The asynchronous caching will start just after this call. |
| 372 | callerInfoCache = CallerInfoCache.init(this); |
| 373 | |
| 374 | // Monitors call activity from the telephony layer |
| 375 | callStateMonitor = new CallStateMonitor(mCM); |
| 376 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 377 | phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone()); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 378 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 379 | configLoader = CarrierConfigLoader.init(this); |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | // Create the CallNotifer singleton, which handles |
| 382 | // asynchronous events from the telephony layer (like |
| 383 | // launching the incoming-call UI when an incoming call comes |
| 384 | // in.) |
Bryce Lee | 5ccda61 | 2015-12-04 15:44:16 -0800 | [diff] [blame^] | 385 | notifier = CallNotifier.init(this, callLogger, callStateMonitor); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 387 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | |
| 389 | // register for MMI/USSD |
| 390 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 391 | |
| 392 | // register connection tracking to PhoneUtils |
| 393 | PhoneUtils.initializeConnectionHandler(mCM); |
| 394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | // Register for misc other intent broadcasts. |
| 396 | IntentFilter intentFilter = |
| 397 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 400 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 401 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 402 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | registerReceiver(mReceiver, intentFilter); |
| 404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | //set the default values for the preferences in the phone. |
| 406 | PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); |
| 407 | |
| 408 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 409 | |
| 410 | // Make sure the audio mode (along with some |
| 411 | // audio-mode-related state of our own) is initialized |
| 412 | // correctly, given the current state of the phone. |
| 413 | PhoneUtils.setAudioMode(mCM); |
| 414 | } |
| 415 | |
Santos Cordon | 52bc81b | 2014-10-07 19:55:12 -0700 | [diff] [blame] | 416 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 417 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 418 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 419 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 420 | |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 421 | simActivationManager = new SimActivationManager(); |
| 422 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | // XXX pre-load the SimProvider so that it's ready |
| 424 | resolver.getType(Uri.parse("content://icc/adn")); |
| 425 | |
| 426 | // start with the default value to set the mute state. |
| 427 | mShouldRestoreMuteOnInCallResume = false; |
| 428 | |
| 429 | // TODO: Register for Cdma Information Records |
| 430 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 431 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | // Read HAC settings and configure audio hardware |
| 433 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 434 | int hac = android.provider.Settings.System.getInt( |
| 435 | getContentResolver(), |
| 436 | android.provider.Settings.System.HEARING_AID, |
| 437 | 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 439 | audioManager.setParameter(SettingsConstants.HAC_KEY, |
| 440 | hac == SettingsConstants.HAC_ENABLED |
| 441 | ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | } |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 443 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | /** |
| 446 | * Returns the singleton instance of the PhoneApp. |
| 447 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 448 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | if (sMe == null) { |
| 450 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 451 | } |
| 452 | return sMe; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Returns the singleton instance of the PhoneApp if running as the |
| 457 | * primary user, otherwise null. |
| 458 | */ |
| 459 | static PhoneGlobals getInstanceIfPrimary() { |
| 460 | return sMe; |
| 461 | } |
| 462 | |
| 463 | /** |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 464 | * Returns the default phone. |
| 465 | * |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 466 | * WARNING: This method should be used carefully, now that there may be multiple phones. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | */ |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 468 | public static Phone getPhone() { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 469 | return PhoneFactory.getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 472 | public static Phone getPhone(int subId) { |
| 473 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 476 | /* package */ CallManager getCallManager() { |
| 477 | return mCM; |
| 478 | } |
| 479 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 480 | public PersistableBundle getCarrierConfig() { |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 481 | return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId()); |
| 482 | } |
| 483 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 484 | public PersistableBundle getCarrierConfigForSubId(int subId) { |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 485 | return configLoader.getConfigForSubId(subId); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 489 | * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from |
| 490 | * Notification context. |
| 491 | */ |
| 492 | /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) { |
| 493 | Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null, |
| 494 | context, NotificationBroadcastReceiver.class); |
| 495 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 496 | } |
| 497 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 498 | boolean isSimPinEnabled() { |
| 499 | return mIsSimPinEnabled; |
| 500 | } |
| 501 | |
| 502 | boolean authenticateAgainstCachedSimPin(String pin) { |
| 503 | return (mCachedSimPin != null && mCachedSimPin.equals(pin)); |
| 504 | } |
| 505 | |
| 506 | void setCachedSimPin(String pin) { |
| 507 | mCachedSimPin = pin; |
| 508 | } |
| 509 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | /** |
| 511 | * Handles OTASP-related events from the telephony layer. |
| 512 | * |
| 513 | * While an OTASP call is active, the CallNotifier forwards |
| 514 | * OTASP-related telephony events to this method. |
| 515 | */ |
| 516 | void handleOtaspEvent(Message msg) { |
| 517 | if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")..."); |
| 518 | |
| 519 | if (otaUtils == null) { |
| 520 | // We shouldn't be getting OTASP events without ever |
| 521 | // having started the OTASP call in the first place! |
| 522 | Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! " |
| 523 | + "message = " + msg); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Similarly, handle the disconnect event of an OTASP call |
| 532 | * by forwarding it to the OtaUtils instance. |
| 533 | */ |
| 534 | /* package */ void handleOtaspDisconnect() { |
| 535 | if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()..."); |
| 536 | |
| 537 | if (otaUtils == null) { |
| 538 | // We shouldn't be getting OTASP events without ever |
| 539 | // having started the OTASP call in the first place! |
| 540 | Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!"); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | otaUtils.onOtaspDisconnect(); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Sets the activity responsible for un-PUK-blocking the device |
| 549 | * so that we may close it when we receive a positive result. |
| 550 | * mPUKEntryActivity is also used to indicate to the device that |
| 551 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 552 | * it is NOT null, then we are trying to unlock and waiting for |
| 553 | * the SIM to move to READY state. |
| 554 | * |
| 555 | * @param activity is the activity to close when PUK has |
| 556 | * finished unlocking. Can be set to null to indicate the unlock |
| 557 | * or SIM READYing process is over. |
| 558 | */ |
| 559 | void setPukEntryActivity(Activity activity) { |
| 560 | mPUKEntryActivity = activity; |
| 561 | } |
| 562 | |
| 563 | Activity getPUKEntryActivity() { |
| 564 | return mPUKEntryActivity; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 569 | * blocking - SIM READYing progress, so that we may dismiss it |
| 570 | * when we receive a positive result. |
| 571 | * |
| 572 | * @param dialog indicates the progress dialog informing the user |
| 573 | * of the state of the device. Dismissed upon completion of |
| 574 | * READYing process |
| 575 | */ |
| 576 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 577 | mPUKEntryProgressDialog = dialog; |
| 578 | } |
| 579 | |
| 580 | ProgressDialog getPUKEntryProgressDialog() { |
| 581 | return mPUKEntryProgressDialog; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Controls whether or not the screen is allowed to sleep. |
| 586 | * |
| 587 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 588 | * settings for the poke lock to determine when to timeout and let |
| 589 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 590 | * |
| 591 | * @param ws tells the device to how to wake. |
| 592 | */ |
| 593 | /* package */ void requestWakeState(WakeState ws) { |
| 594 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 595 | synchronized (this) { |
| 596 | if (mWakeState != ws) { |
| 597 | switch (ws) { |
| 598 | case PARTIAL: |
| 599 | // acquire the processor wake lock, and release the FULL |
| 600 | // lock if it is being held. |
| 601 | mPartialWakeLock.acquire(); |
| 602 | if (mWakeLock.isHeld()) { |
| 603 | mWakeLock.release(); |
| 604 | } |
| 605 | break; |
| 606 | case FULL: |
| 607 | // acquire the full wake lock, and release the PARTIAL |
| 608 | // lock if it is being held. |
| 609 | mWakeLock.acquire(); |
| 610 | if (mPartialWakeLock.isHeld()) { |
| 611 | mPartialWakeLock.release(); |
| 612 | } |
| 613 | break; |
| 614 | case SLEEP: |
| 615 | default: |
| 616 | // release both the PARTIAL and FULL locks. |
| 617 | if (mWakeLock.isHeld()) { |
| 618 | mWakeLock.release(); |
| 619 | } |
| 620 | if (mPartialWakeLock.isHeld()) { |
| 621 | mPartialWakeLock.release(); |
| 622 | } |
| 623 | break; |
| 624 | } |
| 625 | mWakeState = ws; |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * If we are not currently keeping the screen on, then poke the power |
| 632 | * manager to wake up the screen for the user activity timeout duration. |
| 633 | */ |
| 634 | /* package */ void wakeUpScreen() { |
| 635 | synchronized (this) { |
| 636 | if (mWakeState == WakeState.SLEEP) { |
| 637 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
Dianne Hackborn | 148769b | 2015-07-13 17:55:47 -0700 | [diff] [blame] | 638 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Sets the wake state and screen timeout based on the current state |
| 645 | * of the phone, and the current state of the in-call UI. |
| 646 | * |
| 647 | * This method is a "UI Policy" wrapper around |
| 648 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 649 | * |
| 650 | * It's safe to call this method regardless of the state of the Phone |
| 651 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 652 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 653 | */ |
| 654 | /* package */ void updateWakeState() { |
| 655 | PhoneConstants.State state = mCM.getState(); |
| 656 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 657 | // True if the speakerphone is in use. (If so, we *always* use |
| 658 | // the default timeout. Since the user is obviously not holding |
| 659 | // the phone up to his/her face, we don't need to worry about |
| 660 | // false touches, and thus don't need to turn the screen off so |
| 661 | // aggressively.) |
| 662 | // Note that we need to make a fresh call to this method any |
| 663 | // time the speaker state changes. (That happens in |
| 664 | // PhoneUtils.turnOnSpeaker().) |
| 665 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 666 | |
| 667 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 668 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 669 | // the speaker state (since while using BT it's common for the |
| 670 | // user to put the phone straight into a pocket, in which case the |
| 671 | // timeout should probably still be short.) |
| 672 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 673 | // Decide whether to force the screen on or not. |
| 674 | // |
| 675 | // Force the screen to be on if the phone is ringing or dialing, |
| 676 | // or if we're displaying the "Call ended" UI for a connection in |
| 677 | // the "disconnected" state. |
| 678 | // However, if the phone is disconnected while the user is in the |
| 679 | // middle of selecting a quick response message, we should not force |
| 680 | // the screen to be on. |
| 681 | // |
| 682 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 683 | boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 684 | boolean keepScreenOn = isRinging || isDialing; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 685 | // keepScreenOn == true means we'll hold a full wake lock: |
| 686 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Manually pokes the PowerManager's userActivity method. Since we |
| 691 | * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY} |
| 692 | * flag while the InCallScreen is active when there is no proximity sensor, |
| 693 | * we need to do this for touch events that really do count as user activity |
| 694 | * (like pressing any onscreen UI elements.) |
| 695 | */ |
| 696 | /* package */ void pokeUserActivity() { |
| 697 | if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()..."); |
| 698 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
| 699 | } |
| 700 | |
| 701 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 702 | * Notifies the phone app when the phone state changes. |
| 703 | * |
Santos Cordon | fc30981 | 2013-08-20 18:33:16 -0700 | [diff] [blame] | 704 | * This method will updates various states inside Phone app (e.g. update-lock state, etc.) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 705 | */ |
| 706 | /* package */ void updatePhoneState(PhoneConstants.State state) { |
| 707 | if (state != mLastPhoneState) { |
| 708 | mLastPhoneState = state; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 709 | |
| 710 | // Try to acquire or release UpdateLock. |
| 711 | // |
| 712 | // Watch out: we don't release the lock here when the screen is still in foreground. |
| 713 | // At that time InCallScreen will release it on onPause(). |
| 714 | if (state != PhoneConstants.State.IDLE) { |
| 715 | // UpdateLock is a recursive lock, while we may get "acquire" request twice and |
| 716 | // "release" request once for a single call (RINGING + OFFHOOK and IDLE). |
| 717 | // We need to manually ensure the lock is just acquired once for each (and this |
| 718 | // will prevent other possible buggy situations too). |
| 719 | if (!mUpdateLock.isHeld()) { |
| 720 | mUpdateLock.acquire(); |
| 721 | } |
| 722 | } else { |
Jay Shrauner | a5d1321 | 2013-09-19 13:37:43 -0700 | [diff] [blame] | 723 | if (mUpdateLock.isHeld()) { |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 724 | mUpdateLock.release(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
| 730 | /* package */ PhoneConstants.State getPhoneState() { |
| 731 | return mLastPhoneState; |
| 732 | } |
| 733 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 734 | KeyguardManager getKeyguardManager() { |
| 735 | return mKeyguardManager; |
| 736 | } |
| 737 | |
| 738 | private void onMMIComplete(AsyncResult r) { |
| 739 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 740 | MmiCode mmiCode = (MmiCode) r.result; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 741 | PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 744 | private void initForNewRadioTechnology(int phoneId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 745 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
| 746 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 747 | final Phone phone = PhoneFactory.getPhone(phoneId); |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 748 | if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) { |
| 749 | // Clean up OTA for non-CDMA since it is only valid for CDMA. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 750 | clearOtaState(); |
| 751 | } |
| 752 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 753 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
| 754 | callStateMonitor.updateAfterRadioTechnologyChange(); |
| 755 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 756 | // Update registration for ICC status after radio technology change |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 757 | IccCard sim = phone == null ? null : phone.getIccCard(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 758 | if (sim != null) { |
| 759 | if (DBG) Log.d(LOG_TAG, "Update registration for ICC status..."); |
| 760 | |
| 761 | //Register all events new to the new active phone |
| 762 | sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); |
| 763 | } |
| 764 | } |
| 765 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 766 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 767 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 768 | */ |
| 769 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 770 | @Override |
| 771 | public void onReceive(Context context, Intent intent) { |
| 772 | String action = intent.getAction(); |
| 773 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
| 774 | boolean enabled = System.getInt(getContentResolver(), |
| 775 | System.AIRPLANE_MODE_ON, 0) == 0; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 776 | PhoneUtils.setRadioPower(enabled); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 777 | } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 778 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 779 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 780 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 781 | String state = intent.getStringExtra(PhoneConstants.STATE_KEY); |
| 782 | if (VDBG) { |
| 783 | Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); |
| 784 | Log.d(LOG_TAG, "- state: " + state); |
| 785 | Log.d(LOG_TAG, "- reason: " |
| 786 | + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 787 | Log.d(LOG_TAG, "- subId: " + subId); |
| 788 | Log.d(LOG_TAG, "- phoneId: " + phoneId); |
| 789 | } |
| 790 | Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ? |
| 791 | PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone(); |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 792 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 793 | // The "data disconnected due to roaming" notification is shown |
| 794 | // if (a) you have the "data roaming" feature turned off, and |
| 795 | // (b) you just lost data connectivity because you're roaming. |
| 796 | boolean disconnectedDueToRoaming = |
| 797 | !phone.getDataRoamingEnabled() |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 798 | && PhoneConstants.DataState.DISCONNECTED.equals(state) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 799 | && Phone.REASON_ROAMING_ON.equals( |
| 800 | intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
Yorke Lee | 4d2db1c | 2014-11-06 11:37:09 -0800 | [diff] [blame] | 801 | if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) { |
| 802 | mDataDisconnectedDueToRoaming = disconnectedDueToRoaming; |
| 803 | mHandler.sendEmptyMessage(disconnectedDueToRoaming |
| 804 | ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK); |
| 805 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 806 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 807 | (mPUKEntryActivity != null)) { |
| 808 | // if an attempt to un-PUK-lock the device was made, while we're |
| 809 | // receiving this state change notification, notify the handler. |
| 810 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 811 | // been attempted. |
| 812 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 813 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 814 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 815 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 816 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, |
| 817 | SubscriptionManager.INVALID_PHONE_INDEX); |
| 818 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId |
| 819 | + ") is active."); |
| 820 | initForNewRadioTechnology(phoneId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 821 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 822 | handleServiceStateChanged(intent); |
| 823 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 824 | if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 825 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 826 | // Start Emergency Callback Mode service |
| 827 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 828 | context.startService(new Intent(context, |
| 829 | EmergencyCallbackModeService.class)); |
| 830 | } |
| 831 | } else { |
| 832 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 833 | // on a device that doesn't support ECM in the first place. |
| 834 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, " |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 835 | + "but ECM isn't supported for phone: " |
| 836 | + mCM.getFgPhone().getPhoneName()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 842 | /** |
| 843 | * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus |
| 844 | * sent from framework's notification mechanism (which is outside Phone context). |
| 845 | * This should be visible from outside, but shouldn't be in "exported" state. |
| 846 | * |
| 847 | * TODO: If possible merge this into PhoneAppBroadcastReceiver. |
| 848 | */ |
| 849 | public static class NotificationBroadcastReceiver extends BroadcastReceiver { |
| 850 | @Override |
| 851 | public void onReceive(Context context, Intent intent) { |
| 852 | String action = intent.getAction(); |
| 853 | // TODO: use "if (VDBG)" here. |
| 854 | Log.d(LOG_TAG, "Broadcast from Notification: " + action); |
| 855 | |
| 856 | if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) { |
| 857 | PhoneUtils.hangup(PhoneGlobals.getInstance().mCM); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 858 | } else { |
| 859 | Log.w(LOG_TAG, "Received hang-up request from notification," |
| 860 | + " but there's no call the system can hang up."); |
| 861 | } |
| 862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | private void handleServiceStateChanged(Intent intent) { |
| 866 | /** |
| 867 | * This used to handle updating EriTextWidgetProvider this routine |
| 868 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 869 | * be removed. But leaving just in case it might be needed in the near |
| 870 | * future. |
| 871 | */ |
| 872 | |
| 873 | // If service just returned, start sending out the queued messages |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 874 | Bundle extras = intent.getExtras(); |
| 875 | if (extras != null) { |
| 876 | ServiceState ss = ServiceState.newFromBundle(extras); |
| 877 | if (ss != null) { |
| 878 | int state = ss.getState(); |
| 879 | notificationMgr.updateNetworkSelection(state); |
| 880 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
| 884 | public boolean isOtaCallInActiveState() { |
| 885 | boolean otaCallActive = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 886 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive); |
| 887 | return otaCallActive; |
| 888 | } |
| 889 | |
| 890 | public boolean isOtaCallInEndState() { |
| 891 | boolean otaCallEnded = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 892 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded); |
| 893 | return otaCallEnded; |
| 894 | } |
| 895 | |
| 896 | // it is safe to call clearOtaState() even if the InCallScreen isn't active |
| 897 | public void clearOtaState() { |
| 898 | if (DBG) Log.d(LOG_TAG, "- clearOtaState ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 899 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 900 | otaUtils.cleanOtaScreen(true); |
| 901 | if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen"); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active |
| 906 | public void dismissOtaDialogs() { |
| 907 | if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 908 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 909 | otaUtils.dismissAllOtaDialogs(); |
| 910 | if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs"); |
| 911 | } |
| 912 | } |
| 913 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 914 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 915 | * Triggers a refresh of the message waiting (voicemail) indicator. |
| 916 | * |
| 917 | * @param subId the subscription id we should refresh the notification for. |
| 918 | */ |
| 919 | public void refreshMwiIndicator(int subId) { |
| 920 | notificationMgr.refreshMwi(subId); |
| 921 | } |
| 922 | |
| 923 | /** |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 924 | * Dismisses the message waiting (voicemail) indicator. |
| 925 | * |
| 926 | * @param subId the subscription id we should dismiss the notification for. |
| 927 | */ |
| 928 | public void clearMwiIndicator(int subId) { |
| 929 | notificationMgr.updateMwi(subId, false); |
| 930 | } |
| 931 | |
| 932 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 933 | * "Call origin" may be used by Contacts app to specify where the phone call comes from. |
| 934 | * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}. |
| 935 | * Any other value will be ignored, to make sure that malicious apps can't trick the in-call |
| 936 | * UI into launching some random other app after a call ends. |
| 937 | * |
| 938 | * TODO: make this more generic. Note that we should let the "origin" specify its package |
| 939 | * while we are now assuming it is "com.android.contacts" |
| 940 | */ |
| 941 | public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN"; |
| 942 | private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer"; |
| 943 | private static final String ALLOWED_EXTRA_CALL_ORIGIN = |
| 944 | "com.android.dialer.DialtactsActivity"; |
| 945 | /** |
| 946 | * Used to determine if the preserved call origin is fresh enough. |
| 947 | */ |
| 948 | private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 949 | } |