blob: da45900392e074f8a62c5a961358616d2d061136 [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;
Junda Liu12f7d802015-05-01 12:06:44 -070044import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.telephony.ServiceState;
Andrew Lee385019f2014-11-24 14:19:50 -080046import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070047import android.telephony.TelephonyManager;
48import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070050import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070051
Eric Erfanianc712d4b2018-01-03 16:36:14 -080052import com.android.i18n.phonenumbers.PhoneNumberUtil;
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
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800184 private final PhoneNumberUtil mPhoneNumberUtil = PhoneNumberUtil.getInstance();
185
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 Handler mHandler = new Handler() {
187 @Override
188 public void handleMessage(Message msg) {
189 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700190 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 // TODO: This event should be handled by the lock screen, just
193 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
194 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700195 if (getCarrierConfig().getBoolean(
196 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 // Some products don't have the concept of a "SIM network lock"
198 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800199 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 } else {
201 // Normal case: show the "SIM network unlock" PIN entry screen.
202 // The user won't be able to do anything else until
203 // they enter a valid SIM network PIN.
204 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700205 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206 }
207 break;
208
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209 case EVENT_DATA_ROAMING_DISCONNECTED:
Pengquan Meng8783d932017-10-16 14:57:40 -0700210 notificationMgr.showDataDisconnectedRoaming(msg.arg1);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 break;
212
213 case EVENT_DATA_ROAMING_OK:
214 notificationMgr.hideDataDisconnectedRoaming();
215 break;
216
217 case MMI_COMPLETE:
218 onMMIComplete((AsyncResult) msg.obj);
219 break;
220
221 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800222 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 break;
224
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 case EVENT_SIM_STATE_CHANGED:
226 // Marks the event where the SIM goes into ready state.
227 // Right now, this is only used for the PUK-unlocking
228 // process.
229 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
230 // when the right event is triggered and there
231 // are UI objects in the foreground, we close
232 // them to display the lock panel.
233 if (mPUKEntryActivity != null) {
234 mPUKEntryActivity.finish();
235 mPUKEntryActivity = null;
236 }
237 if (mPUKEntryProgressDialog != null) {
238 mPUKEntryProgressDialog.dismiss();
239 mPUKEntryProgressDialog = null;
240 }
241 }
242 break;
243
244 case EVENT_UNSOL_CDMA_INFO_RECORD:
245 //TODO: handle message here;
246 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700247 case EVENT_RESTART_SIP:
248 // This should only run if the Phone process crashed and was restarted. We do
249 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700250 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700251 // upon BOOT_COMPLETED.
252 UserManager userManager = UserManager.get(sMe);
253 if (userManager != null && userManager.isUserUnlocked()) {
254 SipUtil.startSipService();
255 }
256 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700257 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
258 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
259 updateDataRoamingStatus();
260 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 }
262 }
263 };
264
265 public PhoneGlobals(Context context) {
266 super(context);
267 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700268 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 }
270
271 public void onCreate() {
272 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
273
274 ContentResolver resolver = getContentResolver();
275
276 // Cache the "voice capable" flag.
277 // This flag currently comes from a resource (which is
278 // overrideable on a per-product basis):
279 sVoiceCapable =
280 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
281 // ...but this might eventually become a PackageManager "system
282 // feature" instead, in which case we'd do something like:
283 // sVoiceCapable =
284 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
285
Stuart Scottdcf40a92014-12-09 10:45:01 -0800286 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 // Initialize the telephony framework
288 PhoneFactory.makeDefaultPhones(this);
289
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 // Start TelephonyDebugService After the default phone is created.
291 Intent intent = new Intent(this, TelephonyDebugService.class);
292 startService(intent);
293
294 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800295 for (Phone phone : PhoneFactory.getPhones()) {
296 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
299 // Create the NotificationMgr singleton, which is used to display
300 // status bar icons and control other status bar behavior.
301 notificationMgr = NotificationMgr.init(this);
302
Brad Ebinger3fa43462016-04-12 16:06:48 -0700303 // If PhoneGlobals has crashed and is being restarted, then restart.
304 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
305
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700306 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
307 cdmaPhoneCallState = new CdmaPhoneCallState();
308 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 // before registering for phone state changes
311 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
312 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
313 // lock used to keep the processor awake, when we don't care for the display.
314 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
315 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
317 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
320 // during phone calls.
321 mUpdateLock = new UpdateLock("phone");
322
323 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
324
325 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
326
Jay Shrauner21a75342013-11-25 16:14:43 -0800327 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 // Create the CallerInfoCache singleton, which remembers custom ring tone and
330 // send-to-voicemail settings.
331 //
332 // The asynchronous caching will start just after this call.
333 callerInfoCache = CallerInfoCache.init(this);
334
Stuart Scottdcf40a92014-12-09 10:45:01 -0800335 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700336
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800337 configLoader = CarrierConfigLoader.init(this);
338
Jack Yu1a2fc352017-07-14 17:14:37 -0700339 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 // asynchronous events from the telephony layer (like
341 // launching the incoming-call UI when an incoming call comes
342 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800343 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Stuart Scottdcf40a92014-12-09 10:45:01 -0800345 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
347 // register for MMI/USSD
348 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
349
350 // register connection tracking to PhoneUtils
351 PhoneUtils.initializeConnectionHandler(mCM);
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 // Register for misc other intent broadcasts.
354 IntentFilter intentFilter =
355 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
357 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
358 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
359 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700360 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
361 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 registerReceiver(mReceiver, intentFilter);
363
Brad Ebinger533c6c12017-08-02 11:38:48 -0700364 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700365 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
366 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
367 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700368 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700369
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700370 mCarrierVvmPackageInstalledReceiver.register(this);
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800373 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
375 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
376
377 // Make sure the audio mode (along with some
378 // audio-mode-related state of our own) is initialized
379 // correctly, given the current state of the phone.
380 PhoneUtils.setAudioMode(mCM);
381 }
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // XXX pre-load the SimProvider so that it's ready
384 resolver.getType(Uri.parse("content://icc/adn"));
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 // TODO: Register for Cdma Information Records
387 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 // Read HAC settings and configure audio hardware
390 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800391 int hac = android.provider.Settings.System.getInt(
392 getContentResolver(),
393 android.provider.Settings.System.HEARING_AID,
394 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800396 audioManager.setParameter(SettingsConstants.HAC_KEY,
397 hac == SettingsConstants.HAC_ENABLED
398 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 }
Santos Cordonff506f52013-11-21 19:13:19 -0800400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 /**
403 * Returns the singleton instance of the PhoneApp.
404 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800405 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 if (sMe == null) {
407 throw new IllegalStateException("No PhoneGlobals here!");
408 }
409 return sMe;
410 }
411
412 /**
413 * Returns the singleton instance of the PhoneApp if running as the
414 * primary user, otherwise null.
415 */
416 static PhoneGlobals getInstanceIfPrimary() {
417 return sMe;
418 }
419
420 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800421 * Returns the default phone.
422 *
Andrew Lee385019f2014-11-24 14:19:50 -0800423 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 */
Andrew Lee83383e42014-10-31 12:42:28 -0700425 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800426 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 }
428
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800429 public static Phone getPhone(int subId) {
430 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800431 }
432
Santos Cordonde10b752013-09-19 04:11:33 -0700433 /* package */ CallManager getCallManager() {
434 return mCM;
435 }
436
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800437 public PhoneNumberUtil getPhoneNumberUtil() {
438 return mPhoneNumberUtil;
439 }
440
Chris Manton4e9fa912015-06-19 11:26:57 -0700441 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800442 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700443 }
444
Chris Manton4e9fa912015-06-19 11:26:57 -0700445 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700446 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700447 }
448
Jack Yu1a2fc352017-07-14 17:14:37 -0700449 private void registerSettingsObserver() {
450 mSettingsObserver.unobserve();
451 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
452 String mobileDataSetting = Settings.Global.MOBILE_DATA;
453 if (TelephonyManager.getDefault().getSimCount() > 1) {
454 int subId = mDefaultDataSubId;
455 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
456 dataRoamingSetting += subId;
457 mobileDataSetting += subId;
458 }
459 }
460
461 // Listen for user data roaming setting changed event
462 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
463 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
464
465 // Listen for mobile data setting changed event
466 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
467 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
468 }
469
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 * Sets the activity responsible for un-PUK-blocking the device
472 * so that we may close it when we receive a positive result.
473 * mPUKEntryActivity is also used to indicate to the device that
474 * we are trying to un-PUK-lock the phone. In other words, iff
475 * it is NOT null, then we are trying to unlock and waiting for
476 * the SIM to move to READY state.
477 *
478 * @param activity is the activity to close when PUK has
479 * finished unlocking. Can be set to null to indicate the unlock
480 * or SIM READYing process is over.
481 */
482 void setPukEntryActivity(Activity activity) {
483 mPUKEntryActivity = activity;
484 }
485
486 Activity getPUKEntryActivity() {
487 return mPUKEntryActivity;
488 }
489
490 /**
491 * Sets the dialog responsible for notifying the user of un-PUK-
492 * blocking - SIM READYing progress, so that we may dismiss it
493 * when we receive a positive result.
494 *
495 * @param dialog indicates the progress dialog informing the user
496 * of the state of the device. Dismissed upon completion of
497 * READYing process
498 */
499 void setPukEntryProgressDialog(ProgressDialog dialog) {
500 mPUKEntryProgressDialog = dialog;
501 }
502
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503 /**
504 * Controls whether or not the screen is allowed to sleep.
505 *
506 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
507 * settings for the poke lock to determine when to timeout and let
508 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
509 *
510 * @param ws tells the device to how to wake.
511 */
512 /* package */ void requestWakeState(WakeState ws) {
513 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
514 synchronized (this) {
515 if (mWakeState != ws) {
516 switch (ws) {
517 case PARTIAL:
518 // acquire the processor wake lock, and release the FULL
519 // lock if it is being held.
520 mPartialWakeLock.acquire();
521 if (mWakeLock.isHeld()) {
522 mWakeLock.release();
523 }
524 break;
525 case FULL:
526 // acquire the full wake lock, and release the PARTIAL
527 // lock if it is being held.
528 mWakeLock.acquire();
529 if (mPartialWakeLock.isHeld()) {
530 mPartialWakeLock.release();
531 }
532 break;
533 case SLEEP:
534 default:
535 // release both the PARTIAL and FULL locks.
536 if (mWakeLock.isHeld()) {
537 mWakeLock.release();
538 }
539 if (mPartialWakeLock.isHeld()) {
540 mPartialWakeLock.release();
541 }
542 break;
543 }
544 mWakeState = ws;
545 }
546 }
547 }
548
549 /**
550 * If we are not currently keeping the screen on, then poke the power
551 * manager to wake up the screen for the user activity timeout duration.
552 */
553 /* package */ void wakeUpScreen() {
554 synchronized (this) {
555 if (mWakeState == WakeState.SLEEP) {
556 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700557 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558 }
559 }
560 }
561
562 /**
563 * Sets the wake state and screen timeout based on the current state
564 * of the phone, and the current state of the in-call UI.
565 *
566 * This method is a "UI Policy" wrapper around
567 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
568 *
569 * It's safe to call this method regardless of the state of the Phone
570 * (e.g. whether or not it's idle), and regardless of the state of the
571 * Phone UI (e.g. whether or not the InCallScreen is active.)
572 */
573 /* package */ void updateWakeState() {
574 PhoneConstants.State state = mCM.getState();
575
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 // True if the speakerphone is in use. (If so, we *always* use
577 // the default timeout. Since the user is obviously not holding
578 // the phone up to his/her face, we don't need to worry about
579 // false touches, and thus don't need to turn the screen off so
580 // aggressively.)
581 // Note that we need to make a fresh call to this method any
582 // time the speaker state changes. (That happens in
583 // PhoneUtils.turnOnSpeaker().)
584 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
585
586 // TODO (bug 1440854): The screen timeout *might* also need to
587 // depend on the bluetooth state, but this isn't as clear-cut as
588 // the speaker state (since while using BT it's common for the
589 // user to put the phone straight into a pocket, in which case the
590 // timeout should probably still be short.)
591
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 // Decide whether to force the screen on or not.
593 //
594 // Force the screen to be on if the phone is ringing or dialing,
595 // or if we're displaying the "Call ended" UI for a connection in
596 // the "disconnected" state.
597 // However, if the phone is disconnected while the user is in the
598 // middle of selecting a quick response message, we should not force
599 // the screen to be on.
600 //
601 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800602 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700603 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 // keepScreenOn == true means we'll hold a full wake lock:
605 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
606 }
607
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700608 KeyguardManager getKeyguardManager() {
609 return mKeyguardManager;
610 }
611
612 private void onMMIComplete(AsyncResult r) {
613 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
614 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800615 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 }
617
fionaxu80126972017-02-01 17:01:26 -0800618 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 }
622
Chris Mantona09f3632016-02-09 14:48:42 -0800623 private void handleAirplaneModeChange(Context context, int newMode) {
624 int cellState = Settings.Global.getInt(context.getContentResolver(),
625 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
626 boolean isAirplaneNewlyOn = (newMode == 1);
627 switch (cellState) {
628 case PhoneConstants.CELL_OFF_FLAG:
629 // Airplane mode does not affect the cell radio if user
630 // has turned it off.
631 break;
632 case PhoneConstants.CELL_ON_FLAG:
633 maybeTurnCellOff(context, isAirplaneNewlyOn);
634 break;
635 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
636 maybeTurnCellOn(context, isAirplaneNewlyOn);
637 break;
638 }
639 }
640
641 /*
642 * Returns true if the radio must be turned off when entering airplane mode.
643 */
644 private boolean isCellOffInAirplaneMode(Context context) {
645 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
646 Settings.Global.AIRPLANE_MODE_RADIOS);
647 return airplaneModeRadios == null
648 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
649 }
650
651 private void setRadioPowerOff(Context context) {
652 Log.i(LOG_TAG, "Turning radio off - airplane");
653 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800654 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700655 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800656 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
657 PhoneUtils.setRadioPower(false);
658 }
659
660 private void setRadioPowerOn(Context context) {
661 Log.i(LOG_TAG, "Turning radio on - airplane");
662 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
663 PhoneConstants.CELL_ON_FLAG);
664 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
665 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700666 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800667 PhoneUtils.setRadioPower(true);
668 }
669
670 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
671 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700672 // If we are trying to turn off the radio, make sure there are no active
673 // emergency calls. If there are, switch airplane mode back to off.
674 if (PhoneUtils.isInEmergencyCall(mCM)) {
675 // Switch airplane mode back to off.
676 ConnectivityManager.from(this).setAirplaneMode(false);
677 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
678 .show();
679 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800680 } else if (isCellOffInAirplaneMode(context)) {
681 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700682 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800683 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700684 }
Chris Mantona09f3632016-02-09 14:48:42 -0800685 }
686 }
687
688 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
689 if (!isAirplaneNewlyOn) {
690 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700691 }
692 }
693
Santos Cordon593ab382013-08-06 21:58:23 -0700694 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700695 * Receiver for misc intent broadcasts the Phone app cares about.
696 */
697 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
698 @Override
699 public void onReceive(Context context, Intent intent) {
700 String action = intent.getAction();
701 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700702 int airplaneMode = Settings.Global.getInt(getContentResolver(),
703 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
704 // Treat any non-OFF values as ON.
705 if (airplaneMode != AIRPLANE_OFF) {
706 airplaneMode = AIRPLANE_ON;
707 }
Chris Mantona09f3632016-02-09 14:48:42 -0800708 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
710 (mPUKEntryActivity != null)) {
711 // if an attempt to un-PUK-lock the device was made, while we're
712 // receiving this state change notification, notify the handler.
713 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
714 // been attempted.
715 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
716 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
717 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
718 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800719 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
720 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700721 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
722 handleServiceStateChanged(intent);
723 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530724 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530725 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530726 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
727 if (phoneInEcm != null) {
728 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
729 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
730 // Start Emergency Callback Mode service
731 if (intent.getBooleanExtra("phoneinECMState", false)) {
732 context.startService(new Intent(context,
733 EmergencyCallbackModeService.class));
734 } else {
735 phoneInEcm = null;
736 }
737 } else {
738 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
739 // on a device that doesn't support ECM in the first place.
740 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
741 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
742 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 }
744 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530745 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700746 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700747 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
748 // Roaming status could be overridden by carrier config, so we need to update it.
749 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
750 updateDataRoamingStatus();
751 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
752 // We also need to pay attention when default data subscription changes.
753 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
754 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
755 registerSettingsObserver();
756 Phone phone = getPhone(mDefaultDataSubId);
757 if (phone != null) {
758 updateDataRoamingStatus();
759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 }
761 }
762 }
763
Brad Ebinger28626122017-08-10 14:13:35 -0700764 private class SipReceiver extends BroadcastReceiver {
765
766 @Override
767 public void onReceive(Context context, Intent intent) {
768 String action = intent.getAction();
769
770 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
771 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
772 SipUtil.startSipService();
773 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
774 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
775 sipAccountRegistry.setup(context);
776 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
777 if (DBG) {
778 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
779 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
780 }
781 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
782 SipManager.EXTRA_LOCAL_URI));
783 } else {
784 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
785 }
786 }
787 }
788
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700789 private void handleServiceStateChanged(Intent intent) {
790 /**
791 * This used to handle updating EriTextWidgetProvider this routine
792 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
793 * be removed. But leaving just in case it might be needed in the near
794 * future.
795 */
796
Jack Yu1a2fc352017-07-14 17:14:37 -0700797 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700798 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700799 Bundle extras = intent.getExtras();
800 if (extras != null) {
801 ServiceState ss = ServiceState.newFromBundle(extras);
802 if (ss != null) {
803 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700804 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
805 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
806 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700807
808 if (VDBG) {
809 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
810 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
811 }
812 if (subId == mDefaultDataSubId) {
813 updateDataRoamingStatus();
814 }
Santos Cordonc593d002015-06-03 15:41:15 -0700815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816 }
817 }
818
Jack Yu1a2fc352017-07-14 17:14:37 -0700819 /**
820 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
821 * to notify the user so they can enable it through settings. Vise versa if the condition
822 * changes, we need to dismiss the notification.
823 */
824 private void updateDataRoamingStatus() {
825 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
826 Phone phone = getPhone(mDefaultDataSubId);
827 if (phone == null) {
828 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
829 return;
830 }
831
832 DataConnectionReasons reasons = new DataConnectionReasons();
833 boolean dataAllowed = phone.isDataAllowed(reasons);
834 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
835 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
836 if (!mNoDataDueToRoaming
837 && !dataAllowed
838 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
839 // If the only reason of no data is data roaming disabled, then we notify the user
840 // so the user can turn on data roaming.
841 mNoDataDueToRoaming = true;
842 Log.d(LOG_TAG, "Show roaming disconnected notification");
843 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700844 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
845 msg.arg1 = mDefaultDataSubId;
846 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700847 } else if (mNoDataDueToRoaming && (dataAllowed
848 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
849 // Otherwise dismiss the notification we showed earlier.
850 mNoDataDueToRoaming = false;
851 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
852 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
853 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
854 }
855 }
856
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530857 public Phone getPhoneInEcm() {
858 return phoneInEcm;
859 }
860
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700861 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800862 * Triggers a refresh of the message waiting (voicemail) indicator.
863 *
864 * @param subId the subscription id we should refresh the notification for.
865 */
866 public void refreshMwiIndicator(int subId) {
867 notificationMgr.refreshMwi(subId);
868 }
869
870 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700871 * Dismisses the message waiting (voicemail) indicator.
872 *
873 * @param subId the subscription id we should dismiss the notification for.
874 */
875 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700876 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
877 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700878 Phone phone = getPhone(subId);
879 if (phone == null) {
880 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
881 } else {
882 phone.setVoiceMessageCount(0);
883 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700884 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700885
886 /**
887 * Enables or disables the visual voicemail check for message waiting indicator. Default value
888 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
889 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
890 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
891 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
892 * configuration state will be cleared and the MWI for voicemail that arrives when the device
893 * is offline will be cleared, even if the account cannot be activated. A full solution will be
894 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
895 * risky at this moment. This is a temporary workaround to shut down the configuration state
896 * check if visual voicemail cannot be activated.
897 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
898 *
899 * @param subId the account to set the enabled state
900 */
901 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
902 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
903 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700904
905 /**
906 * Dump the state of the object, add calls to other objects as desired.
907 *
908 * @param fd File descriptor
909 * @param printWriter Print writer
910 * @param args Arguments
911 */
912 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
913 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
914 pw.println("------- PhoneGlobals -------");
915 pw.increaseIndent();
916 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
917 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
918 pw.println("mDataRoamingNotifLog:");
919 pw.increaseIndent();
920 mDataRoamingNotifLog.dump(fd, pw, args);
921 pw.decreaseIndent();
922 pw.decreaseIndent();
923 pw.println("------- End PhoneGlobals -------");
924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700925}