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