blob: d0b236fc180ad15befabbbdf8759900f8bb1cd61 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.Activity;
20import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.ContentResolver;
24import android.content.Context;
25import android.content.ContextWrapper;
26import android.content.Intent;
27import android.content.IntentFilter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070029import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.net.Uri;
Brad Ebinger533c6c12017-08-02 11:38:48 -070031import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070033import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070036import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.SystemClock;
39import android.os.SystemProperties;
40import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070041import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080043import android.provider.Settings;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070044import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070045import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.telephony.ServiceState;
Andrew Lee385019f2014-11-24 14:19:50 -080047import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070048import android.telephony.TelephonyManager;
49import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070051import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070052
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import com.android.internal.telephony.Call;
54import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import com.android.internal.telephony.IccCardConstants;
56import com.android.internal.telephony.MmiCode;
57import com.android.internal.telephony.Phone;
58import com.android.internal.telephony.PhoneConstants;
59import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070060import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.TelephonyCapabilities;
62import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070063import com.android.internal.telephony.dataconnection.DataConnectionReasons;
64import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
65import com.android.internal.util.IndentingPrintWriter;
Santos Cordon352ff652014-05-30 01:41:45 -070066import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080067import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070068import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070069import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070070import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071
Jack Yu1a2fc352017-07-14 17:14:37 -070072import java.io.FileDescriptor;
73import java.io.PrintWriter;
74
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075/**
76 * Global state for the telephony subsystem when running in the primary
77 * phone process.
78 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070079public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070080 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
82 /**
83 * Phone app-wide debug level:
84 * 0 - no debug logging
85 * 1 - normal debug logging if ro.debuggable is set (which is true in
86 * "eng" and "userdebug" builds but not "user" builds)
87 * 2 - ultra-verbose debug logging
88 *
89 * Most individual classes in the phone app have a local DBG constant,
90 * typically set to
91 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
92 * or else
93 * (PhoneApp.DBG_LEVEL >= 2)
94 * depending on the desired verbosity.
95 *
96 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
97 */
Andrew Lee88b51e22014-10-29 15:48:51 -070098 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099
100 private static final boolean DBG =
101 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
102 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
103
104 // Message codes; see mHandler below.
105 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
108 private static final int EVENT_DATA_ROAMING_OK = 11;
109 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700110 private static final int EVENT_RESTART_SIP = 13;
Jack Yu1a2fc352017-07-14 17:14:37 -0700111 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
112 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
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
Santos Cordone18902f2016-03-22 17:16:04 -0700121 public static final int AIRPLANE_ON = 1;
122 public static final int AIRPLANE_OFF = 0;
123
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 /**
125 * Allowable values for the wake lock code.
126 * SLEEP means the device can be put to sleep.
127 * PARTIAL means wake the processor, but we display can be kept off.
128 * FULL means wake both the processor and the display.
129 */
130 public enum WakeState {
131 SLEEP,
132 PARTIAL,
133 FULL
134 }
135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static PhoneGlobals sMe;
137
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700139 CallNotifier notifier;
140 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700141 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700142 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800143 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700144
Santos Cordon69a69192013-08-22 14:25:42 -0700145 private CallGatewayManager callGatewayManager;
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530146 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 static boolean sVoiceCapable = true;
149
Santos Cordonc593d002015-06-03 15:41:15 -0700150 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 CdmaPhoneCallState cdmaPhoneCallState;
152
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 // 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 Yu1a2fc352017-07-14 17:14:37 -0700160 private boolean mNoDataDueToRoaming = false;
Jack Yu953f9352017-05-18 14:41:06 -0700161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 private WakeState mWakeState = WakeState.SLEEP;
163
164 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 private PowerManager.WakeLock mWakeLock;
166 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 private UpdateLock mUpdateLock;
170
Jack Yu1a2fc352017-07-14 17:14:37 -0700171 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
172 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
173
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 // Broadcast receiver for various intent broadcasts (see onCreate())
175 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700176 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700177 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700179 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
180 new CarrierVvmPackageInstalledReceiver();
181
Jack Yu1a2fc352017-07-14 17:14:37 -0700182 private final SettingsObserver mSettingsObserver;
183
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184 Handler mHandler = new Handler() {
185 @Override
186 public void handleMessage(Message msg) {
187 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700188 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 // TODO: This event should be handled by the lock screen, just
191 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
192 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700193 if (getCarrierConfig().getBoolean(
194 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 // Some products don't have the concept of a "SIM network lock"
196 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000197 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 } else {
199 // Normal case: show the "SIM network unlock" PIN entry screen.
200 // The user won't be able to do anything else until
201 // they enter a valid SIM network PIN.
202 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800203 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
204 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 }
206 break;
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 case EVENT_DATA_ROAMING_DISCONNECTED:
Pengquan Meng8783d932017-10-16 14:57:40 -0700209 notificationMgr.showDataDisconnectedRoaming(msg.arg1);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210 break;
211
212 case EVENT_DATA_ROAMING_OK:
213 notificationMgr.hideDataDisconnectedRoaming();
214 break;
215
216 case MMI_COMPLETE:
217 onMMIComplete((AsyncResult) msg.obj);
218 break;
219
220 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800221 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 break;
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 case EVENT_SIM_STATE_CHANGED:
225 // Marks the event where the SIM goes into ready state.
226 // Right now, this is only used for the PUK-unlocking
227 // process.
228 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
229 // when the right event is triggered and there
230 // are UI objects in the foreground, we close
231 // them to display the lock panel.
232 if (mPUKEntryActivity != null) {
233 mPUKEntryActivity.finish();
234 mPUKEntryActivity = null;
235 }
236 if (mPUKEntryProgressDialog != null) {
237 mPUKEntryProgressDialog.dismiss();
238 mPUKEntryProgressDialog = null;
239 }
240 }
241 break;
242
243 case EVENT_UNSOL_CDMA_INFO_RECORD:
244 //TODO: handle message here;
245 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700246 case EVENT_RESTART_SIP:
247 // This should only run if the Phone process crashed and was restarted. We do
248 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700249 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700250 // upon BOOT_COMPLETED.
251 UserManager userManager = UserManager.get(sMe);
252 if (userManager != null && userManager.isUserUnlocked()) {
253 SipUtil.startSipService();
254 }
255 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700256 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
257 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
258 updateDataRoamingStatus();
259 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 }
261 }
262 };
263
264 public PhoneGlobals(Context context) {
265 super(context);
266 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700267 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 }
269
270 public void onCreate() {
271 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
272
273 ContentResolver resolver = getContentResolver();
274
275 // Cache the "voice capable" flag.
276 // This flag currently comes from a resource (which is
277 // overrideable on a per-product basis):
278 sVoiceCapable =
279 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
280 // ...but this might eventually become a PackageManager "system
281 // feature" instead, in which case we'd do something like:
282 // sVoiceCapable =
283 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
284
Stuart Scottdcf40a92014-12-09 10:45:01 -0800285 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 // Initialize the telephony framework
287 PhoneFactory.makeDefaultPhones(this);
288
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 // Start TelephonyDebugService After the default phone is created.
290 Intent intent = new Intent(this, TelephonyDebugService.class);
291 startService(intent);
292
293 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800294 for (Phone phone : PhoneFactory.getPhones()) {
295 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
298 // Create the NotificationMgr singleton, which is used to display
299 // status bar icons and control other status bar behavior.
300 notificationMgr = NotificationMgr.init(this);
301
Brad Ebinger3fa43462016-04-12 16:06:48 -0700302 // If PhoneGlobals has crashed and is being restarted, then restart.
303 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
304
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700305 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
306 cdmaPhoneCallState = new CdmaPhoneCallState();
307 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 // before registering for phone state changes
310 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
311 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
312 // lock used to keep the processor awake, when we don't care for the display.
313 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
314 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
317
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
319 // during phone calls.
320 mUpdateLock = new UpdateLock("phone");
321
322 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
323
324 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
325
Jay Shrauner21a75342013-11-25 16:14:43 -0800326 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700327
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328 // Create the CallerInfoCache singleton, which remembers custom ring tone and
329 // send-to-voicemail settings.
330 //
331 // The asynchronous caching will start just after this call.
332 callerInfoCache = CallerInfoCache.init(this);
333
Stuart Scottdcf40a92014-12-09 10:45:01 -0800334 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700335
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800336 configLoader = CarrierConfigLoader.init(this);
337
Jack Yu1a2fc352017-07-14 17:14:37 -0700338 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // asynchronous events from the telephony layer (like
340 // launching the incoming-call UI when an incoming call comes
341 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800342 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Stuart Scottdcf40a92014-12-09 10:45:01 -0800344 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 // register for MMI/USSD
347 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
348
349 // register connection tracking to PhoneUtils
350 PhoneUtils.initializeConnectionHandler(mCM);
351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 // Register for misc other intent broadcasts.
353 IntentFilter intentFilter =
354 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
356 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
357 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
358 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700359 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
360 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 registerReceiver(mReceiver, intentFilter);
362
Brad Ebinger533c6c12017-08-02 11:38:48 -0700363 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700364 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
365 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
366 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700367 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700368
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700369 mCarrierVvmPackageInstalledReceiver.register(this);
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800372 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
374 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
375
376 // Make sure the audio mode (along with some
377 // audio-mode-related state of our own) is initialized
378 // correctly, given the current state of the phone.
379 PhoneUtils.setAudioMode(mCM);
380 }
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 // XXX pre-load the SimProvider so that it's ready
383 resolver.getType(Uri.parse("content://icc/adn"));
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 // TODO: Register for Cdma Information Records
386 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 // Read HAC settings and configure audio hardware
389 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800390 int hac = android.provider.Settings.System.getInt(
391 getContentResolver(),
392 android.provider.Settings.System.HEARING_AID,
393 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800395 audioManager.setParameter(SettingsConstants.HAC_KEY,
396 hac == SettingsConstants.HAC_ENABLED
397 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
Santos Cordonff506f52013-11-21 19:13:19 -0800399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /**
402 * Returns the singleton instance of the PhoneApp.
403 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800404 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 if (sMe == null) {
406 throw new IllegalStateException("No PhoneGlobals here!");
407 }
408 return sMe;
409 }
410
411 /**
412 * Returns the singleton instance of the PhoneApp if running as the
413 * primary user, otherwise null.
414 */
415 static PhoneGlobals getInstanceIfPrimary() {
416 return sMe;
417 }
418
419 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800420 * Returns the default phone.
421 *
Andrew Lee385019f2014-11-24 14:19:50 -0800422 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 */
Andrew Lee83383e42014-10-31 12:42:28 -0700424 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800425 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 }
427
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800428 public static Phone getPhone(int subId) {
429 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800430 }
431
Santos Cordonde10b752013-09-19 04:11:33 -0700432 /* package */ CallManager getCallManager() {
433 return mCM;
434 }
435
Chris Manton4e9fa912015-06-19 11:26:57 -0700436 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800437 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700438 }
439
Chris Manton4e9fa912015-06-19 11:26:57 -0700440 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen6d3d6b32018-03-01 13:58:03 -0800441 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700442 }
443
Jack Yu1a2fc352017-07-14 17:14:37 -0700444 private void registerSettingsObserver() {
445 mSettingsObserver.unobserve();
446 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
447 String mobileDataSetting = Settings.Global.MOBILE_DATA;
448 if (TelephonyManager.getDefault().getSimCount() > 1) {
449 int subId = mDefaultDataSubId;
450 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
451 dataRoamingSetting += subId;
452 mobileDataSetting += subId;
453 }
454 }
455
456 // Listen for user data roaming setting changed event
457 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
458 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
459
460 // Listen for mobile data setting changed event
461 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
462 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
463 }
464
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 * Sets the activity responsible for un-PUK-blocking the device
467 * so that we may close it when we receive a positive result.
468 * mPUKEntryActivity is also used to indicate to the device that
469 * we are trying to un-PUK-lock the phone. In other words, iff
470 * it is NOT null, then we are trying to unlock and waiting for
471 * the SIM to move to READY state.
472 *
473 * @param activity is the activity to close when PUK has
474 * finished unlocking. Can be set to null to indicate the unlock
475 * or SIM READYing process is over.
476 */
477 void setPukEntryActivity(Activity activity) {
478 mPUKEntryActivity = activity;
479 }
480
481 Activity getPUKEntryActivity() {
482 return mPUKEntryActivity;
483 }
484
485 /**
486 * Sets the dialog responsible for notifying the user of un-PUK-
487 * blocking - SIM READYing progress, so that we may dismiss it
488 * when we receive a positive result.
489 *
490 * @param dialog indicates the progress dialog informing the user
491 * of the state of the device. Dismissed upon completion of
492 * READYing process
493 */
494 void setPukEntryProgressDialog(ProgressDialog dialog) {
495 mPUKEntryProgressDialog = dialog;
496 }
497
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 /**
499 * Controls whether or not the screen is allowed to sleep.
500 *
501 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
502 * settings for the poke lock to determine when to timeout and let
503 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
504 *
505 * @param ws tells the device to how to wake.
506 */
507 /* package */ void requestWakeState(WakeState ws) {
508 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
509 synchronized (this) {
510 if (mWakeState != ws) {
511 switch (ws) {
512 case PARTIAL:
513 // acquire the processor wake lock, and release the FULL
514 // lock if it is being held.
515 mPartialWakeLock.acquire();
516 if (mWakeLock.isHeld()) {
517 mWakeLock.release();
518 }
519 break;
520 case FULL:
521 // acquire the full wake lock, and release the PARTIAL
522 // lock if it is being held.
523 mWakeLock.acquire();
524 if (mPartialWakeLock.isHeld()) {
525 mPartialWakeLock.release();
526 }
527 break;
528 case SLEEP:
529 default:
530 // release both the PARTIAL and FULL locks.
531 if (mWakeLock.isHeld()) {
532 mWakeLock.release();
533 }
534 if (mPartialWakeLock.isHeld()) {
535 mPartialWakeLock.release();
536 }
537 break;
538 }
539 mWakeState = ws;
540 }
541 }
542 }
543
544 /**
545 * If we are not currently keeping the screen on, then poke the power
546 * manager to wake up the screen for the user activity timeout duration.
547 */
548 /* package */ void wakeUpScreen() {
549 synchronized (this) {
550 if (mWakeState == WakeState.SLEEP) {
551 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700552 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553 }
554 }
555 }
556
557 /**
558 * Sets the wake state and screen timeout based on the current state
559 * of the phone, and the current state of the in-call UI.
560 *
561 * This method is a "UI Policy" wrapper around
562 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
563 *
564 * It's safe to call this method regardless of the state of the Phone
565 * (e.g. whether or not it's idle), and regardless of the state of the
566 * Phone UI (e.g. whether or not the InCallScreen is active.)
567 */
568 /* package */ void updateWakeState() {
569 PhoneConstants.State state = mCM.getState();
570
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 // True if the speakerphone is in use. (If so, we *always* use
572 // the default timeout. Since the user is obviously not holding
573 // the phone up to his/her face, we don't need to worry about
574 // false touches, and thus don't need to turn the screen off so
575 // aggressively.)
576 // Note that we need to make a fresh call to this method any
577 // time the speaker state changes. (That happens in
578 // PhoneUtils.turnOnSpeaker().)
579 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
580
581 // TODO (bug 1440854): The screen timeout *might* also need to
582 // depend on the bluetooth state, but this isn't as clear-cut as
583 // the speaker state (since while using BT it's common for the
584 // user to put the phone straight into a pocket, in which case the
585 // timeout should probably still be short.)
586
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587 // Decide whether to force the screen on or not.
588 //
589 // Force the screen to be on if the phone is ringing or dialing,
590 // or if we're displaying the "Call ended" UI for a connection in
591 // the "disconnected" state.
592 // However, if the phone is disconnected while the user is in the
593 // middle of selecting a quick response message, we should not force
594 // the screen to be on.
595 //
596 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800597 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700598 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 // keepScreenOn == true means we'll hold a full wake lock:
600 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
601 }
602
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 KeyguardManager getKeyguardManager() {
604 return mKeyguardManager;
605 }
606
607 private void onMMIComplete(AsyncResult r) {
608 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
609 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800610 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 }
612
fionaxu80126972017-02-01 17:01:26 -0800613 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 }
617
Chris Mantona09f3632016-02-09 14:48:42 -0800618 private void handleAirplaneModeChange(Context context, int newMode) {
619 int cellState = Settings.Global.getInt(context.getContentResolver(),
620 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
621 boolean isAirplaneNewlyOn = (newMode == 1);
622 switch (cellState) {
623 case PhoneConstants.CELL_OFF_FLAG:
624 // Airplane mode does not affect the cell radio if user
625 // has turned it off.
626 break;
627 case PhoneConstants.CELL_ON_FLAG:
628 maybeTurnCellOff(context, isAirplaneNewlyOn);
629 break;
630 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
631 maybeTurnCellOn(context, isAirplaneNewlyOn);
632 break;
633 }
634 }
635
636 /*
637 * Returns true if the radio must be turned off when entering airplane mode.
638 */
639 private boolean isCellOffInAirplaneMode(Context context) {
640 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
641 Settings.Global.AIRPLANE_MODE_RADIOS);
642 return airplaneModeRadios == null
643 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
644 }
645
646 private void setRadioPowerOff(Context context) {
647 Log.i(LOG_TAG, "Turning radio off - airplane");
648 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000649 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700650 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800651 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
652 PhoneUtils.setRadioPower(false);
653 }
654
655 private void setRadioPowerOn(Context context) {
656 Log.i(LOG_TAG, "Turning radio on - airplane");
657 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
658 PhoneConstants.CELL_ON_FLAG);
659 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
660 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700661 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800662 PhoneUtils.setRadioPower(true);
663 }
664
665 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
666 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700667 // If we are trying to turn off the radio, make sure there are no active
668 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700669 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
670
671 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700672 // Switch airplane mode back to off.
673 ConnectivityManager.from(this).setAirplaneMode(false);
674 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
675 .show();
676 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800677 } else if (isCellOffInAirplaneMode(context)) {
678 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700679 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800680 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700681 }
Chris Mantona09f3632016-02-09 14:48:42 -0800682 }
683 }
684
685 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
686 if (!isAirplaneNewlyOn) {
687 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700688 }
689 }
690
Santos Cordon593ab382013-08-06 21:58:23 -0700691 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700692 * Receiver for misc intent broadcasts the Phone app cares about.
693 */
694 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
695 @Override
696 public void onReceive(Context context, Intent intent) {
697 String action = intent.getAction();
698 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700699 int airplaneMode = Settings.Global.getInt(getContentResolver(),
700 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
701 // Treat any non-OFF values as ON.
702 if (airplaneMode != AIRPLANE_OFF) {
703 airplaneMode = AIRPLANE_ON;
704 }
Chris Mantona09f3632016-02-09 14:48:42 -0800705 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
707 (mPUKEntryActivity != null)) {
708 // if an attempt to un-PUK-lock the device was made, while we're
709 // receiving this state change notification, notify the handler.
710 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
711 // been attempted.
712 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
713 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
714 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
715 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800716 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
717 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
719 handleServiceStateChanged(intent);
720 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530721 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530722 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530723 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
724 if (phoneInEcm != null) {
725 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
726 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
727 // Start Emergency Callback Mode service
728 if (intent.getBooleanExtra("phoneinECMState", false)) {
729 context.startService(new Intent(context,
730 EmergencyCallbackModeService.class));
731 } else {
732 phoneInEcm = null;
733 }
734 } else {
735 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
736 // on a device that doesn't support ECM in the first place.
737 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
738 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
739 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700740 }
741 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530742 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700744 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
745 // Roaming status could be overridden by carrier config, so we need to update it.
746 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
747 updateDataRoamingStatus();
748 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
749 // We also need to pay attention when default data subscription changes.
750 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
751 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
752 registerSettingsObserver();
753 Phone phone = getPhone(mDefaultDataSubId);
754 if (phone != null) {
755 updateDataRoamingStatus();
756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 }
758 }
759 }
760
Brad Ebinger28626122017-08-10 14:13:35 -0700761 private class SipReceiver extends BroadcastReceiver {
762
763 @Override
764 public void onReceive(Context context, Intent intent) {
765 String action = intent.getAction();
766
767 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
768 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
769 SipUtil.startSipService();
770 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
771 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
772 sipAccountRegistry.setup(context);
773 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
774 if (DBG) {
775 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
776 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
777 }
778 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
779 SipManager.EXTRA_LOCAL_URI));
780 } else {
781 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
782 }
783 }
784 }
785
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700786 private void handleServiceStateChanged(Intent intent) {
787 /**
788 * This used to handle updating EriTextWidgetProvider this routine
789 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
790 * be removed. But leaving just in case it might be needed in the near
791 * future.
792 */
793
Jack Yu1a2fc352017-07-14 17:14:37 -0700794 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700795 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700796 Bundle extras = intent.getExtras();
797 if (extras != null) {
798 ServiceState ss = ServiceState.newFromBundle(extras);
799 if (ss != null) {
800 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700801 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
802 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
803 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700804
805 if (VDBG) {
806 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
807 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
808 }
809 if (subId == mDefaultDataSubId) {
810 updateDataRoamingStatus();
811 }
Santos Cordonc593d002015-06-03 15:41:15 -0700812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700813 }
814 }
815
Jack Yu1a2fc352017-07-14 17:14:37 -0700816 /**
817 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
818 * to notify the user so they can enable it through settings. Vise versa if the condition
819 * changes, we need to dismiss the notification.
820 */
821 private void updateDataRoamingStatus() {
822 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
823 Phone phone = getPhone(mDefaultDataSubId);
824 if (phone == null) {
825 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
826 return;
827 }
828
829 DataConnectionReasons reasons = new DataConnectionReasons();
830 boolean dataAllowed = phone.isDataAllowed(reasons);
831 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
832 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
833 if (!mNoDataDueToRoaming
834 && !dataAllowed
835 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
836 // If the only reason of no data is data roaming disabled, then we notify the user
837 // so the user can turn on data roaming.
838 mNoDataDueToRoaming = true;
839 Log.d(LOG_TAG, "Show roaming disconnected notification");
840 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700841 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
842 msg.arg1 = mDefaultDataSubId;
843 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700844 } else if (mNoDataDueToRoaming && (dataAllowed
845 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
846 // Otherwise dismiss the notification we showed earlier.
847 mNoDataDueToRoaming = false;
848 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
849 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
850 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
851 }
852 }
853
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530854 public Phone getPhoneInEcm() {
855 return phoneInEcm;
856 }
857
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700858 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800859 * Triggers a refresh of the message waiting (voicemail) indicator.
860 *
861 * @param subId the subscription id we should refresh the notification for.
862 */
863 public void refreshMwiIndicator(int subId) {
864 notificationMgr.refreshMwi(subId);
865 }
866
867 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700868 * Dismisses the message waiting (voicemail) indicator.
869 *
870 * @param subId the subscription id we should dismiss the notification for.
871 */
872 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700873 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
874 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700875 Phone phone = getPhone(subId);
876 if (phone == null) {
877 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
878 } else {
879 phone.setVoiceMessageCount(0);
880 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700881 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700882
883 /**
884 * Enables or disables the visual voicemail check for message waiting indicator. Default value
885 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
886 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
887 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
888 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
889 * configuration state will be cleared and the MWI for voicemail that arrives when the device
890 * is offline will be cleared, even if the account cannot be activated. A full solution will be
891 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
892 * risky at this moment. This is a temporary workaround to shut down the configuration state
893 * check if visual voicemail cannot be activated.
894 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
895 *
896 * @param subId the account to set the enabled state
897 */
898 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
899 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
900 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700901
902 /**
903 * Dump the state of the object, add calls to other objects as desired.
904 *
905 * @param fd File descriptor
906 * @param printWriter Print writer
907 * @param args Arguments
908 */
909 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
910 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
911 pw.println("------- PhoneGlobals -------");
912 pw.increaseIndent();
913 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
914 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
915 pw.println("mDataRoamingNotifLog:");
916 pw.increaseIndent();
917 mDataRoamingNotifLog.dump(fd, pw, args);
918 pw.decreaseIndent();
919 pw.decreaseIndent();
920 pw.println("------- End PhoneGlobals -------");
921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700922}