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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.app.ProgressDialog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 23 | import android.content.ContentResolver; |
| 24 | import android.content.Context; |
| 25 | import android.content.ContextWrapper; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.media.AudioManager; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 29 | import android.net.ConnectivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.os.AsyncResult; |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 32 | import android.os.Bundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 35 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.os.PowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.os.SystemClock; |
| 38 | import android.os.SystemProperties; |
| 39 | import android.os.UpdateLock; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 40 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.preference.PreferenceManager; |
Sanket Padawe | 4c69923 | 2016-02-09 11:07:22 -0800 | [diff] [blame] | 42 | import android.provider.Settings; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 43 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.telephony.ServiceState; |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 45 | import android.telephony.SubscriptionManager; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 46 | import android.telephony.TelephonyManager; |
| 47 | import android.util.LocalLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.util.Log; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 49 | import android.widget.Toast; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 50 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.Call; |
| 52 | import com.android.internal.telephony.CallManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import com.android.internal.telephony.IccCardConstants; |
| 54 | import com.android.internal.telephony.MmiCode; |
| 55 | import com.android.internal.telephony.Phone; |
| 56 | import com.android.internal.telephony.PhoneConstants; |
| 57 | import com.android.internal.telephony.PhoneFactory; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 58 | import com.android.internal.telephony.SettingsObserver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.TelephonyCapabilities; |
| 60 | import com.android.internal.telephony.TelephonyIntents; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 61 | import com.android.internal.telephony.dataconnection.DataConnectionReasons; |
| 62 | import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType; |
| 63 | import com.android.internal.util.IndentingPrintWriter; |
Santos Cordon | 352ff65 | 2014-05-30 01:41:45 -0700 | [diff] [blame] | 64 | import com.android.phone.common.CallLogAsync; |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 65 | import com.android.phone.settings.SettingsConstants; |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 66 | import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 67 | import com.android.services.telephony.sip.SipUtil; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 69 | import java.io.FileDescriptor; |
| 70 | import java.io.PrintWriter; |
| 71 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Global state for the telephony subsystem when running in the primary |
| 74 | * phone process. |
| 75 | */ |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 76 | public class PhoneGlobals extends ContextWrapper { |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 77 | public static final String LOG_TAG = "PhoneGlobals"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Phone app-wide debug level: |
| 81 | * 0 - no debug logging |
| 82 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 83 | * "eng" and "userdebug" builds but not "user" builds) |
| 84 | * 2 - ultra-verbose debug logging |
| 85 | * |
| 86 | * Most individual classes in the phone app have a local DBG constant, |
| 87 | * typically set to |
| 88 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 89 | * or else |
| 90 | * (PhoneApp.DBG_LEVEL >= 2) |
| 91 | * depending on the desired verbosity. |
| 92 | * |
| 93 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 94 | */ |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 95 | public static final int DBG_LEVEL = 0; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 96 | |
| 97 | private static final boolean DBG = |
| 98 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 99 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 100 | |
| 101 | // Message codes; see mHandler below. |
| 102 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; |
| 105 | private static final int EVENT_DATA_ROAMING_OK = 11; |
| 106 | private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 107 | private static final int EVENT_RESTART_SIP = 13; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 108 | private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14; |
| 109 | private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | |
| 111 | // The MMI codes are also used by the InCallScreen. |
| 112 | public static final int MMI_INITIATE = 51; |
| 113 | public static final int MMI_COMPLETE = 52; |
| 114 | public static final int MMI_CANCEL = 53; |
| 115 | // Don't use message codes larger than 99 here; those are reserved for |
| 116 | // the individual Activities of the Phone UI. |
| 117 | |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 118 | public static final int AIRPLANE_ON = 1; |
| 119 | public static final int AIRPLANE_OFF = 0; |
| 120 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 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 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | private static PhoneGlobals sMe; |
| 134 | |
| 135 | // A few important fields we expose to the rest of the package |
| 136 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | CallController callController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 139 | CallNotifier notifier; |
| 140 | CallerInfoCache callerInfoCache; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 141 | NotificationMgr notificationMgr; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 142 | public PhoneInterfaceManager phoneMgr; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 143 | CarrierConfigLoader configLoader; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 144 | |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 145 | private CallGatewayManager callGatewayManager; |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 146 | private Phone phoneInEcm; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 147 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 148 | static boolean sVoiceCapable = true; |
| 149 | |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 150 | // TODO: Remove, no longer used. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | CdmaPhoneCallState cdmaPhoneCallState; |
| 152 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 | // The currently-active PUK entry activity and progress dialog. |
| 154 | // Normally, these are the Emergency Dialer and the subsequent |
| 155 | // progress dialog. null if there is are no such objects in |
| 156 | // the foreground. |
| 157 | private Activity mPUKEntryActivity; |
| 158 | private ProgressDialog mPUKEntryProgressDialog; |
| 159 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 160 | private boolean mNoDataDueToRoaming = false; |
Jack Yu | 953f935 | 2017-05-18 14:41:06 -0700 | [diff] [blame] | 161 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | private WakeState mWakeState = WakeState.SLEEP; |
| 163 | |
| 164 | private PowerManager mPowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | private PowerManager.WakeLock mWakeLock; |
| 166 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | |
| 169 | private UpdateLock mUpdateLock; |
| 170 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 171 | private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 172 | private final LocalLog mDataRoamingNotifLog = new LocalLog(50); |
| 173 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 175 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 176 | |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 177 | private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver = |
| 178 | new CarrierVvmPackageInstalledReceiver(); |
| 179 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 180 | private final SettingsObserver mSettingsObserver; |
| 181 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | Handler mHandler = new Handler() { |
| 183 | @Override |
| 184 | public void handleMessage(Message msg) { |
| 185 | PhoneConstants.State phoneState; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 186 | if (VDBG) Log.v(LOG_TAG, "event=" + msg.what); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | switch (msg.what) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | // TODO: This event should be handled by the lock screen, just |
| 189 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 190 | case EVENT_SIM_NETWORK_LOCKED: |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 191 | if (getCarrierConfig().getBoolean( |
| 192 | CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | // Some products don't have the concept of a "SIM network lock" |
| 194 | Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " |
| 195 | + "not showing 'SIM network unlock' PIN entry screen"); |
| 196 | } else { |
| 197 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 198 | // The user won't be able to do anything else until |
| 199 | // they enter a valid SIM network PIN. |
| 200 | Log.i(LOG_TAG, "show sim depersonal panel"); |
Tyler Gunn | 52a3707 | 2015-08-24 14:23:19 -0700 | [diff] [blame] | 201 | IccNetworkDepersonalizationPanel.showDialog(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | } |
| 203 | break; |
| 204 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | case EVENT_DATA_ROAMING_DISCONNECTED: |
| 206 | notificationMgr.showDataDisconnectedRoaming(); |
| 207 | break; |
| 208 | |
| 209 | case EVENT_DATA_ROAMING_OK: |
| 210 | notificationMgr.hideDataDisconnectedRoaming(); |
| 211 | break; |
| 212 | |
| 213 | case MMI_COMPLETE: |
| 214 | onMMIComplete((AsyncResult) msg.obj); |
| 215 | break; |
| 216 | |
| 217 | case MMI_CANCEL: |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 218 | PhoneUtils.cancelMmiCode(mCM.getFgPhone()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 219 | break; |
| 220 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | case EVENT_SIM_STATE_CHANGED: |
| 222 | // Marks the event where the SIM goes into ready state. |
| 223 | // Right now, this is only used for the PUK-unlocking |
| 224 | // process. |
| 225 | if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) { |
| 226 | // when the right event is triggered and there |
| 227 | // are UI objects in the foreground, we close |
| 228 | // them to display the lock panel. |
| 229 | if (mPUKEntryActivity != null) { |
| 230 | mPUKEntryActivity.finish(); |
| 231 | mPUKEntryActivity = null; |
| 232 | } |
| 233 | if (mPUKEntryProgressDialog != null) { |
| 234 | mPUKEntryProgressDialog.dismiss(); |
| 235 | mPUKEntryProgressDialog = null; |
| 236 | } |
| 237 | } |
| 238 | break; |
| 239 | |
| 240 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 241 | //TODO: handle message here; |
| 242 | break; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 243 | case EVENT_RESTART_SIP: |
| 244 | // This should only run if the Phone process crashed and was restarted. We do |
| 245 | // not want this running if the device is still in the FBE encrypted state. |
| 246 | // This is the same procedure that is triggered in the SipBroadcastReceiver |
| 247 | // upon BOOT_COMPLETED. |
| 248 | UserManager userManager = UserManager.get(sMe); |
| 249 | if (userManager != null && userManager.isUserUnlocked()) { |
| 250 | SipUtil.startSipService(); |
| 251 | } |
| 252 | break; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 253 | case EVENT_DATA_ROAMING_SETTINGS_CHANGED: |
| 254 | case EVENT_MOBILE_DATA_SETTINGS_CHANGED: |
| 255 | updateDataRoamingStatus(); |
| 256 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | }; |
| 260 | |
| 261 | public PhoneGlobals(Context context) { |
| 262 | super(context); |
| 263 | sMe = this; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 264 | mSettingsObserver = new SettingsObserver(context, mHandler); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | public void onCreate() { |
| 268 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 269 | |
| 270 | ContentResolver resolver = getContentResolver(); |
| 271 | |
| 272 | // Cache the "voice capable" flag. |
| 273 | // This flag currently comes from a resource (which is |
| 274 | // overrideable on a per-product basis): |
| 275 | sVoiceCapable = |
| 276 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 277 | // ...but this might eventually become a PackageManager "system |
| 278 | // feature" instead, in which case we'd do something like: |
| 279 | // sVoiceCapable = |
| 280 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 281 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 282 | if (mCM == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | // Initialize the telephony framework |
| 284 | PhoneFactory.makeDefaultPhones(this); |
| 285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 286 | // Start TelephonyDebugService After the default phone is created. |
| 287 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 288 | startService(intent); |
| 289 | |
| 290 | mCM = CallManager.getInstance(); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 291 | for (Phone phone : PhoneFactory.getPhones()) { |
| 292 | mCM.registerPhone(phone); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 294 | |
| 295 | // Create the NotificationMgr singleton, which is used to display |
| 296 | // status bar icons and control other status bar behavior. |
| 297 | notificationMgr = NotificationMgr.init(this); |
| 298 | |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 299 | // If PhoneGlobals has crashed and is being restarted, then restart. |
| 300 | mHandler.sendEmptyMessage(EVENT_RESTART_SIP); |
| 301 | |
Anthony Lee | 03ebdfc | 2015-07-27 08:12:02 -0700 | [diff] [blame] | 302 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 303 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 304 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 306 | // before registering for phone state changes |
| 307 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 308 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 309 | // lock used to keep the processor awake, when we don't care for the display. |
| 310 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 311 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 312 | |
| 313 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 316 | // during phone calls. |
| 317 | mUpdateLock = new UpdateLock("phone"); |
| 318 | |
| 319 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 320 | |
| 321 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 322 | |
Jay Shrauner | 21a7534 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 323 | callGatewayManager = CallGatewayManager.getInstance(); |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 324 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | // Create the CallController singleton, which is the interface |
| 326 | // to the telephony layer for user-initiated telephony functionality |
| 327 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 328 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 329 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 331 | // send-to-voicemail settings. |
| 332 | // |
| 333 | // The asynchronous caching will start just after this call. |
| 334 | callerInfoCache = CallerInfoCache.init(this); |
| 335 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 336 | phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone()); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 337 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 338 | configLoader = CarrierConfigLoader.init(this); |
| 339 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 340 | // Create the CallNotifier singleton, which handles |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | // asynchronous events from the telephony layer (like |
| 342 | // launching the incoming-call UI when an incoming call comes |
| 343 | // in.) |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 344 | notifier = CallNotifier.init(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 346 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 347 | |
| 348 | // register for MMI/USSD |
| 349 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 350 | |
| 351 | // register connection tracking to PhoneUtils |
| 352 | PhoneUtils.initializeConnectionHandler(mCM); |
| 353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | // Register for misc other intent broadcasts. |
| 355 | IntentFilter intentFilter = |
| 356 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 358 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 359 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 360 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 361 | intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
| 362 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | registerReceiver(mReceiver, intentFilter); |
| 364 | |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 365 | mCarrierVvmPackageInstalledReceiver.register(this); |
| 366 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | //set the default values for the preferences in the phone. |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 368 | PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | |
| 370 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 371 | |
| 372 | // Make sure the audio mode (along with some |
| 373 | // audio-mode-related state of our own) is initialized |
| 374 | // correctly, given the current state of the phone. |
| 375 | PhoneUtils.setAudioMode(mCM); |
| 376 | } |
| 377 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | // XXX pre-load the SimProvider so that it's ready |
| 379 | resolver.getType(Uri.parse("content://icc/adn")); |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | // TODO: Register for Cdma Information Records |
| 382 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | // Read HAC settings and configure audio hardware |
| 385 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 386 | int hac = android.provider.Settings.System.getInt( |
| 387 | getContentResolver(), |
| 388 | android.provider.Settings.System.HEARING_AID, |
| 389 | 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 391 | audioManager.setParameter(SettingsConstants.HAC_KEY, |
| 392 | hac == SettingsConstants.HAC_ENABLED |
| 393 | ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | } |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 395 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | /** |
| 398 | * Returns the singleton instance of the PhoneApp. |
| 399 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 400 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | if (sMe == null) { |
| 402 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 403 | } |
| 404 | return sMe; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Returns the singleton instance of the PhoneApp if running as the |
| 409 | * primary user, otherwise null. |
| 410 | */ |
| 411 | static PhoneGlobals getInstanceIfPrimary() { |
| 412 | return sMe; |
| 413 | } |
| 414 | |
| 415 | /** |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 416 | * Returns the default phone. |
| 417 | * |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 418 | * 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] | 419 | */ |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 420 | public static Phone getPhone() { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 421 | return PhoneFactory.getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 424 | public static Phone getPhone(int subId) { |
| 425 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 428 | /* package */ CallManager getCallManager() { |
| 429 | return mCM; |
| 430 | } |
| 431 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 432 | public PersistableBundle getCarrierConfig() { |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 433 | return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId()); |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 436 | public PersistableBundle getCarrierConfigForSubId(int subId) { |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 437 | return configLoader.getConfigForSubId(subId); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 440 | private void registerSettingsObserver() { |
| 441 | mSettingsObserver.unobserve(); |
| 442 | String dataRoamingSetting = Settings.Global.DATA_ROAMING; |
| 443 | String mobileDataSetting = Settings.Global.MOBILE_DATA; |
| 444 | if (TelephonyManager.getDefault().getSimCount() > 1) { |
| 445 | int subId = mDefaultDataSubId; |
| 446 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 447 | dataRoamingSetting += subId; |
| 448 | mobileDataSetting += subId; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // Listen for user data roaming setting changed event |
| 453 | mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting), |
| 454 | EVENT_DATA_ROAMING_SETTINGS_CHANGED); |
| 455 | |
| 456 | // Listen for mobile data setting changed event |
| 457 | mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting), |
| 458 | EVENT_MOBILE_DATA_SETTINGS_CHANGED); |
| 459 | } |
| 460 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 462 | * Sets the activity responsible for un-PUK-blocking the device |
| 463 | * so that we may close it when we receive a positive result. |
| 464 | * mPUKEntryActivity is also used to indicate to the device that |
| 465 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 466 | * it is NOT null, then we are trying to unlock and waiting for |
| 467 | * the SIM to move to READY state. |
| 468 | * |
| 469 | * @param activity is the activity to close when PUK has |
| 470 | * finished unlocking. Can be set to null to indicate the unlock |
| 471 | * or SIM READYing process is over. |
| 472 | */ |
| 473 | void setPukEntryActivity(Activity activity) { |
| 474 | mPUKEntryActivity = activity; |
| 475 | } |
| 476 | |
| 477 | Activity getPUKEntryActivity() { |
| 478 | return mPUKEntryActivity; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 483 | * blocking - SIM READYing progress, so that we may dismiss it |
| 484 | * when we receive a positive result. |
| 485 | * |
| 486 | * @param dialog indicates the progress dialog informing the user |
| 487 | * of the state of the device. Dismissed upon completion of |
| 488 | * READYing process |
| 489 | */ |
| 490 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 491 | mPUKEntryProgressDialog = dialog; |
| 492 | } |
| 493 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 494 | /** |
| 495 | * Controls whether or not the screen is allowed to sleep. |
| 496 | * |
| 497 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 498 | * settings for the poke lock to determine when to timeout and let |
| 499 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 500 | * |
| 501 | * @param ws tells the device to how to wake. |
| 502 | */ |
| 503 | /* package */ void requestWakeState(WakeState ws) { |
| 504 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 505 | synchronized (this) { |
| 506 | if (mWakeState != ws) { |
| 507 | switch (ws) { |
| 508 | case PARTIAL: |
| 509 | // acquire the processor wake lock, and release the FULL |
| 510 | // lock if it is being held. |
| 511 | mPartialWakeLock.acquire(); |
| 512 | if (mWakeLock.isHeld()) { |
| 513 | mWakeLock.release(); |
| 514 | } |
| 515 | break; |
| 516 | case FULL: |
| 517 | // acquire the full wake lock, and release the PARTIAL |
| 518 | // lock if it is being held. |
| 519 | mWakeLock.acquire(); |
| 520 | if (mPartialWakeLock.isHeld()) { |
| 521 | mPartialWakeLock.release(); |
| 522 | } |
| 523 | break; |
| 524 | case SLEEP: |
| 525 | default: |
| 526 | // release both the PARTIAL and FULL locks. |
| 527 | if (mWakeLock.isHeld()) { |
| 528 | mWakeLock.release(); |
| 529 | } |
| 530 | if (mPartialWakeLock.isHeld()) { |
| 531 | mPartialWakeLock.release(); |
| 532 | } |
| 533 | break; |
| 534 | } |
| 535 | mWakeState = ws; |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * If we are not currently keeping the screen on, then poke the power |
| 542 | * manager to wake up the screen for the user activity timeout duration. |
| 543 | */ |
| 544 | /* package */ void wakeUpScreen() { |
| 545 | synchronized (this) { |
| 546 | if (mWakeState == WakeState.SLEEP) { |
| 547 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
Dianne Hackborn | 148769b | 2015-07-13 17:55:47 -0700 | [diff] [blame] | 548 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Sets the wake state and screen timeout based on the current state |
| 555 | * of the phone, and the current state of the in-call UI. |
| 556 | * |
| 557 | * This method is a "UI Policy" wrapper around |
| 558 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 559 | * |
| 560 | * It's safe to call this method regardless of the state of the Phone |
| 561 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 562 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 563 | */ |
| 564 | /* package */ void updateWakeState() { |
| 565 | PhoneConstants.State state = mCM.getState(); |
| 566 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 567 | // True if the speakerphone is in use. (If so, we *always* use |
| 568 | // the default timeout. Since the user is obviously not holding |
| 569 | // the phone up to his/her face, we don't need to worry about |
| 570 | // false touches, and thus don't need to turn the screen off so |
| 571 | // aggressively.) |
| 572 | // Note that we need to make a fresh call to this method any |
| 573 | // time the speaker state changes. (That happens in |
| 574 | // PhoneUtils.turnOnSpeaker().) |
| 575 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 576 | |
| 577 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 578 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 579 | // the speaker state (since while using BT it's common for the |
| 580 | // user to put the phone straight into a pocket, in which case the |
| 581 | // timeout should probably still be short.) |
| 582 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | // Decide whether to force the screen on or not. |
| 584 | // |
| 585 | // Force the screen to be on if the phone is ringing or dialing, |
| 586 | // or if we're displaying the "Call ended" UI for a connection in |
| 587 | // the "disconnected" state. |
| 588 | // However, if the phone is disconnected while the user is in the |
| 589 | // middle of selecting a quick response message, we should not force |
| 590 | // the screen to be on. |
| 591 | // |
| 592 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 593 | boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 594 | boolean keepScreenOn = isRinging || isDialing; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 595 | // keepScreenOn == true means we'll hold a full wake lock: |
| 596 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 597 | } |
| 598 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 599 | KeyguardManager getKeyguardManager() { |
| 600 | return mKeyguardManager; |
| 601 | } |
| 602 | |
| 603 | private void onMMIComplete(AsyncResult r) { |
| 604 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 605 | MmiCode mmiCode = (MmiCode) r.result; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 606 | PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 607 | } |
| 608 | |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 609 | private void initForNewRadioTechnology() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 610 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 611 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 614 | private void handleAirplaneModeChange(Context context, int newMode) { |
| 615 | int cellState = Settings.Global.getInt(context.getContentResolver(), |
| 616 | Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG); |
| 617 | boolean isAirplaneNewlyOn = (newMode == 1); |
| 618 | switch (cellState) { |
| 619 | case PhoneConstants.CELL_OFF_FLAG: |
| 620 | // Airplane mode does not affect the cell radio if user |
| 621 | // has turned it off. |
| 622 | break; |
| 623 | case PhoneConstants.CELL_ON_FLAG: |
| 624 | maybeTurnCellOff(context, isAirplaneNewlyOn); |
| 625 | break; |
| 626 | case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG: |
| 627 | maybeTurnCellOn(context, isAirplaneNewlyOn); |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /* |
| 633 | * Returns true if the radio must be turned off when entering airplane mode. |
| 634 | */ |
| 635 | private boolean isCellOffInAirplaneMode(Context context) { |
| 636 | String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(), |
| 637 | Settings.Global.AIRPLANE_MODE_RADIOS); |
| 638 | return airplaneModeRadios == null |
| 639 | || airplaneModeRadios.contains(Settings.Global.RADIO_CELL); |
| 640 | } |
| 641 | |
| 642 | private void setRadioPowerOff(Context context) { |
| 643 | Log.i(LOG_TAG, "Turning radio off - airplane"); |
| 644 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 645 | PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG); |
Sooraj Sasindran | 798bafa | 2017-04-03 22:49:00 -0700 | [diff] [blame] | 646 | SystemProperties.set("persist.radio.airplane_mode_on", "1"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 647 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0); |
| 648 | PhoneUtils.setRadioPower(false); |
| 649 | } |
| 650 | |
| 651 | private void setRadioPowerOn(Context context) { |
| 652 | Log.i(LOG_TAG, "Turning radio on - airplane"); |
| 653 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 654 | PhoneConstants.CELL_ON_FLAG); |
| 655 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, |
| 656 | 1); |
Sooraj Sasindran | 798bafa | 2017-04-03 22:49:00 -0700 | [diff] [blame] | 657 | SystemProperties.set("persist.radio.airplane_mode_on", "0"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 658 | PhoneUtils.setRadioPower(true); |
| 659 | } |
| 660 | |
| 661 | private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) { |
| 662 | if (isAirplaneNewlyOn) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 663 | // If we are trying to turn off the radio, make sure there are no active |
| 664 | // emergency calls. If there are, switch airplane mode back to off. |
| 665 | if (PhoneUtils.isInEmergencyCall(mCM)) { |
| 666 | // Switch airplane mode back to off. |
| 667 | ConnectivityManager.from(this).setAirplaneMode(false); |
| 668 | Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG) |
| 669 | .show(); |
| 670 | Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 671 | } else if (isCellOffInAirplaneMode(context)) { |
| 672 | setRadioPowerOff(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 673 | } else { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 674 | Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off"); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 675 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) { |
| 680 | if (!isAirplaneNewlyOn) { |
| 681 | setRadioPowerOn(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 685 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 686 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 687 | */ |
| 688 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 689 | @Override |
| 690 | public void onReceive(Context context, Intent intent) { |
| 691 | String action = intent.getAction(); |
| 692 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 693 | int airplaneMode = Settings.Global.getInt(getContentResolver(), |
| 694 | Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF); |
| 695 | // Treat any non-OFF values as ON. |
| 696 | if (airplaneMode != AIRPLANE_OFF) { |
| 697 | airplaneMode = AIRPLANE_ON; |
| 698 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 699 | handleAirplaneModeChange(context, airplaneMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 700 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 701 | (mPUKEntryActivity != null)) { |
| 702 | // if an attempt to un-PUK-lock the device was made, while we're |
| 703 | // receiving this state change notification, notify the handler. |
| 704 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 705 | // been attempted. |
| 706 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 707 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 708 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 709 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 710 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); |
| 711 | initForNewRadioTechnology(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 712 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 713 | handleServiceStateChanged(intent); |
| 714 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 715 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0); |
Srikanth Chintala | 079912a | 2016-03-03 16:35:01 +0530 | [diff] [blame] | 716 | phoneInEcm = PhoneFactory.getPhone(phoneId); |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 717 | Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId); |
| 718 | if (phoneInEcm != null) { |
| 719 | if (TelephonyCapabilities.supportsEcm(phoneInEcm)) { |
| 720 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 721 | // Start Emergency Callback Mode service |
| 722 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 723 | context.startService(new Intent(context, |
| 724 | EmergencyCallbackModeService.class)); |
| 725 | } else { |
| 726 | phoneInEcm = null; |
| 727 | } |
| 728 | } else { |
| 729 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 730 | // on a device that doesn't support ECM in the first place. |
| 731 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but " |
| 732 | + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName()); |
| 733 | phoneInEcm = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 734 | } |
| 735 | } else { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 736 | Log.w(LOG_TAG, "phoneInEcm is null."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 737 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 738 | } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { |
| 739 | // Roaming status could be overridden by carrier config, so we need to update it. |
| 740 | if (VDBG) Log.v(LOG_TAG, "carrier config changed."); |
| 741 | updateDataRoamingStatus(); |
| 742 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { |
| 743 | // We also need to pay attention when default data subscription changes. |
| 744 | if (VDBG) Log.v(LOG_TAG, "default data sub changed."); |
| 745 | mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 746 | registerSettingsObserver(); |
| 747 | Phone phone = getPhone(mDefaultDataSubId); |
| 748 | if (phone != null) { |
| 749 | updateDataRoamingStatus(); |
| 750 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 755 | private void handleServiceStateChanged(Intent intent) { |
| 756 | /** |
| 757 | * This used to handle updating EriTextWidgetProvider this routine |
| 758 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 759 | * be removed. But leaving just in case it might be needed in the near |
| 760 | * future. |
| 761 | */ |
| 762 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 763 | if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 764 | // If service just returned, start sending out the queued messages |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 765 | Bundle extras = intent.getExtras(); |
| 766 | if (extras != null) { |
| 767 | ServiceState ss = ServiceState.newFromBundle(extras); |
| 768 | if (ss != null) { |
| 769 | int state = ss.getState(); |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 770 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 771 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 772 | notificationMgr.updateNetworkSelection(state, subId); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 773 | |
| 774 | if (VDBG) { |
| 775 | Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId=" |
| 776 | + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming()); |
| 777 | } |
| 778 | if (subId == mDefaultDataSubId) { |
| 779 | updateDataRoamingStatus(); |
| 780 | } |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 785 | /** |
| 786 | * When roaming, if mobile data cannot be established due to data roaming not enabled, we need |
| 787 | * to notify the user so they can enable it through settings. Vise versa if the condition |
| 788 | * changes, we need to dismiss the notification. |
| 789 | */ |
| 790 | private void updateDataRoamingStatus() { |
| 791 | if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus"); |
| 792 | Phone phone = getPhone(mDefaultDataSubId); |
| 793 | if (phone == null) { |
| 794 | Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId); |
| 795 | return; |
| 796 | } |
| 797 | |
| 798 | DataConnectionReasons reasons = new DataConnectionReasons(); |
| 799 | boolean dataAllowed = phone.isDataAllowed(reasons); |
| 800 | mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons); |
| 801 | if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons); |
| 802 | if (!mNoDataDueToRoaming |
| 803 | && !dataAllowed |
| 804 | && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) { |
| 805 | // If the only reason of no data is data roaming disabled, then we notify the user |
| 806 | // so the user can turn on data roaming. |
| 807 | mNoDataDueToRoaming = true; |
| 808 | Log.d(LOG_TAG, "Show roaming disconnected notification"); |
| 809 | mDataRoamingNotifLog.log("Show"); |
| 810 | mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_DISCONNECTED); |
| 811 | } else if (mNoDataDueToRoaming && (dataAllowed |
| 812 | || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) { |
| 813 | // Otherwise dismiss the notification we showed earlier. |
| 814 | mNoDataDueToRoaming = false; |
| 815 | Log.d(LOG_TAG, "Dismiss roaming disconnected notification"); |
| 816 | mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons); |
| 817 | mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK); |
| 818 | } |
| 819 | } |
| 820 | |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 821 | public Phone getPhoneInEcm() { |
| 822 | return phoneInEcm; |
| 823 | } |
| 824 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 825 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 826 | * Triggers a refresh of the message waiting (voicemail) indicator. |
| 827 | * |
| 828 | * @param subId the subscription id we should refresh the notification for. |
| 829 | */ |
| 830 | public void refreshMwiIndicator(int subId) { |
| 831 | notificationMgr.refreshMwi(subId); |
| 832 | } |
| 833 | |
| 834 | /** |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 835 | * Dismisses the message waiting (voicemail) indicator. |
| 836 | * |
| 837 | * @param subId the subscription id we should dismiss the notification for. |
| 838 | */ |
| 839 | public void clearMwiIndicator(int subId) { |
Ta-wei Yen | 6310668 | 2016-07-11 14:11:27 -0700 | [diff] [blame] | 840 | // Setting voiceMessageCount to 0 will remove the current notification and clear the system |
| 841 | // cached value. |
Ta-wei Yen | 7df340d | 2016-07-25 10:59:53 -0700 | [diff] [blame] | 842 | Phone phone = getPhone(subId); |
| 843 | if (phone == null) { |
| 844 | Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId); |
| 845 | } else { |
| 846 | phone.setVoiceMessageCount(0); |
| 847 | } |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 848 | } |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 849 | |
| 850 | /** |
| 851 | * Enables or disables the visual voicemail check for message waiting indicator. Default value |
| 852 | * is true. MWI is the traditional voicemail notification which should be suppressed if visual |
| 853 | * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently |
| 854 | * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress |
| 855 | * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the |
| 856 | * configuration state will be cleared and the MWI for voicemail that arrives when the device |
| 857 | * is offline will be cleared, even if the account cannot be activated. A full solution will be |
| 858 | * adding a setMwiEnabled() method and stop checking the configuration state, but that is too |
| 859 | * risky at this moment. This is a temporary workaround to shut down the configuration state |
| 860 | * check if visual voicemail cannot be activated. |
| 861 | * <p>TODO(twyen): implement the setMwiEnabled() mentioned above. |
| 862 | * |
| 863 | * @param subId the account to set the enabled state |
| 864 | */ |
| 865 | public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) { |
| 866 | notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled); |
| 867 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame^] | 868 | |
| 869 | /** |
| 870 | * Dump the state of the object, add calls to other objects as desired. |
| 871 | * |
| 872 | * @param fd File descriptor |
| 873 | * @param printWriter Print writer |
| 874 | * @param args Arguments |
| 875 | */ |
| 876 | public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) { |
| 877 | IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " "); |
| 878 | pw.println("------- PhoneGlobals -------"); |
| 879 | pw.increaseIndent(); |
| 880 | pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming); |
| 881 | pw.println("mDefaultDataSubId=" + mDefaultDataSubId); |
| 882 | pw.println("mDataRoamingNotifLog:"); |
| 883 | pw.increaseIndent(); |
| 884 | mDataRoamingNotifLog.dump(fd, pw, args); |
| 885 | pw.decreaseIndent(); |
| 886 | pw.decreaseIndent(); |
| 887 | pw.println("------- End PhoneGlobals -------"); |
| 888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 889 | } |