blob: 0792019ff377a0ba019c2be4dbf26794e62b36d5 [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
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import com.android.internal.telephony.Call;
53import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import com.android.internal.telephony.IccCardConstants;
55import com.android.internal.telephony.MmiCode;
56import com.android.internal.telephony.Phone;
57import com.android.internal.telephony.PhoneConstants;
58import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070059import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.TelephonyCapabilities;
61import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070062import com.android.internal.telephony.dataconnection.DataConnectionReasons;
63import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
64import com.android.internal.util.IndentingPrintWriter;
Sooraj Sasindran1a8d0ef2018-08-30 18:25:58 -070065import com.android.phone.anas.AlternativeNetworkAccessService;
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);
Sooraj Sasindran1a8d0ef2018-08-30 18:25:58 -0700337 AlternativeNetworkAccessService.initInstance(this);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800338
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
Chris Manton4e9fa912015-06-19 11:26:57 -0700437 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800438 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700439 }
440
Chris Manton4e9fa912015-06-19 11:26:57 -0700441 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen45b51c72018-03-01 13:58:03 -0800442 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700443 }
444
Jack Yu1a2fc352017-07-14 17:14:37 -0700445 private void registerSettingsObserver() {
446 mSettingsObserver.unobserve();
447 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
448 String mobileDataSetting = Settings.Global.MOBILE_DATA;
449 if (TelephonyManager.getDefault().getSimCount() > 1) {
450 int subId = mDefaultDataSubId;
451 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
452 dataRoamingSetting += subId;
453 mobileDataSetting += subId;
454 }
455 }
456
457 // Listen for user data roaming setting changed event
458 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
459 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
460
461 // Listen for mobile data setting changed event
462 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
463 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
464 }
465
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 * Sets the activity responsible for un-PUK-blocking the device
468 * so that we may close it when we receive a positive result.
469 * mPUKEntryActivity is also used to indicate to the device that
470 * we are trying to un-PUK-lock the phone. In other words, iff
471 * it is NOT null, then we are trying to unlock and waiting for
472 * the SIM to move to READY state.
473 *
474 * @param activity is the activity to close when PUK has
475 * finished unlocking. Can be set to null to indicate the unlock
476 * or SIM READYing process is over.
477 */
478 void setPukEntryActivity(Activity activity) {
479 mPUKEntryActivity = activity;
480 }
481
482 Activity getPUKEntryActivity() {
483 return mPUKEntryActivity;
484 }
485
486 /**
487 * Sets the dialog responsible for notifying the user of un-PUK-
488 * blocking - SIM READYing progress, so that we may dismiss it
489 * when we receive a positive result.
490 *
491 * @param dialog indicates the progress dialog informing the user
492 * of the state of the device. Dismissed upon completion of
493 * READYing process
494 */
495 void setPukEntryProgressDialog(ProgressDialog dialog) {
496 mPUKEntryProgressDialog = dialog;
497 }
498
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 /**
500 * Controls whether or not the screen is allowed to sleep.
501 *
502 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
503 * settings for the poke lock to determine when to timeout and let
504 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
505 *
506 * @param ws tells the device to how to wake.
507 */
508 /* package */ void requestWakeState(WakeState ws) {
509 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
510 synchronized (this) {
511 if (mWakeState != ws) {
512 switch (ws) {
513 case PARTIAL:
514 // acquire the processor wake lock, and release the FULL
515 // lock if it is being held.
516 mPartialWakeLock.acquire();
517 if (mWakeLock.isHeld()) {
518 mWakeLock.release();
519 }
520 break;
521 case FULL:
522 // acquire the full wake lock, and release the PARTIAL
523 // lock if it is being held.
524 mWakeLock.acquire();
525 if (mPartialWakeLock.isHeld()) {
526 mPartialWakeLock.release();
527 }
528 break;
529 case SLEEP:
530 default:
531 // release both the PARTIAL and FULL locks.
532 if (mWakeLock.isHeld()) {
533 mWakeLock.release();
534 }
535 if (mPartialWakeLock.isHeld()) {
536 mPartialWakeLock.release();
537 }
538 break;
539 }
540 mWakeState = ws;
541 }
542 }
543 }
544
545 /**
546 * If we are not currently keeping the screen on, then poke the power
547 * manager to wake up the screen for the user activity timeout duration.
548 */
549 /* package */ void wakeUpScreen() {
550 synchronized (this) {
551 if (mWakeState == WakeState.SLEEP) {
552 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700553 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554 }
555 }
556 }
557
558 /**
559 * Sets the wake state and screen timeout based on the current state
560 * of the phone, and the current state of the in-call UI.
561 *
562 * This method is a "UI Policy" wrapper around
563 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
564 *
565 * It's safe to call this method regardless of the state of the Phone
566 * (e.g. whether or not it's idle), and regardless of the state of the
567 * Phone UI (e.g. whether or not the InCallScreen is active.)
568 */
569 /* package */ void updateWakeState() {
570 PhoneConstants.State state = mCM.getState();
571
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 // True if the speakerphone is in use. (If so, we *always* use
573 // the default timeout. Since the user is obviously not holding
574 // the phone up to his/her face, we don't need to worry about
575 // false touches, and thus don't need to turn the screen off so
576 // aggressively.)
577 // Note that we need to make a fresh call to this method any
578 // time the speaker state changes. (That happens in
579 // PhoneUtils.turnOnSpeaker().)
580 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
581
582 // TODO (bug 1440854): The screen timeout *might* also need to
583 // depend on the bluetooth state, but this isn't as clear-cut as
584 // the speaker state (since while using BT it's common for the
585 // user to put the phone straight into a pocket, in which case the
586 // timeout should probably still be short.)
587
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588 // Decide whether to force the screen on or not.
589 //
590 // Force the screen to be on if the phone is ringing or dialing,
591 // or if we're displaying the "Call ended" UI for a connection in
592 // the "disconnected" state.
593 // However, if the phone is disconnected while the user is in the
594 // middle of selecting a quick response message, we should not force
595 // the screen to be on.
596 //
597 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800598 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700599 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 // keepScreenOn == true means we'll hold a full wake lock:
601 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
602 }
603
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 KeyguardManager getKeyguardManager() {
605 return mKeyguardManager;
606 }
607
608 private void onMMIComplete(AsyncResult r) {
609 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
610 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800611 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 }
613
fionaxu80126972017-02-01 17:01:26 -0800614 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 }
618
Chris Mantona09f3632016-02-09 14:48:42 -0800619 private void handleAirplaneModeChange(Context context, int newMode) {
620 int cellState = Settings.Global.getInt(context.getContentResolver(),
621 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
622 boolean isAirplaneNewlyOn = (newMode == 1);
623 switch (cellState) {
624 case PhoneConstants.CELL_OFF_FLAG:
625 // Airplane mode does not affect the cell radio if user
626 // has turned it off.
627 break;
628 case PhoneConstants.CELL_ON_FLAG:
629 maybeTurnCellOff(context, isAirplaneNewlyOn);
630 break;
631 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
632 maybeTurnCellOn(context, isAirplaneNewlyOn);
633 break;
634 }
635 }
636
637 /*
638 * Returns true if the radio must be turned off when entering airplane mode.
639 */
640 private boolean isCellOffInAirplaneMode(Context context) {
641 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
642 Settings.Global.AIRPLANE_MODE_RADIOS);
643 return airplaneModeRadios == null
644 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
645 }
646
647 private void setRadioPowerOff(Context context) {
648 Log.i(LOG_TAG, "Turning radio off - airplane");
649 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000650 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700651 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800652 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
653 PhoneUtils.setRadioPower(false);
654 }
655
656 private void setRadioPowerOn(Context context) {
657 Log.i(LOG_TAG, "Turning radio on - airplane");
658 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
659 PhoneConstants.CELL_ON_FLAG);
660 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
661 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700662 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800663 PhoneUtils.setRadioPower(true);
664 }
665
666 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
667 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700668 // If we are trying to turn off the radio, make sure there are no active
669 // emergency calls. If there are, switch airplane mode back to off.
670 if (PhoneUtils.isInEmergencyCall(mCM)) {
671 // Switch airplane mode back to off.
672 ConnectivityManager.from(this).setAirplaneMode(false);
673 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
674 .show();
675 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800676 } else if (isCellOffInAirplaneMode(context)) {
677 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700678 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800679 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700680 }
Chris Mantona09f3632016-02-09 14:48:42 -0800681 }
682 }
683
684 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
685 if (!isAirplaneNewlyOn) {
686 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700687 }
688 }
689
Santos Cordon593ab382013-08-06 21:58:23 -0700690 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 * Receiver for misc intent broadcasts the Phone app cares about.
692 */
693 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
694 @Override
695 public void onReceive(Context context, Intent intent) {
696 String action = intent.getAction();
697 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700698 int airplaneMode = Settings.Global.getInt(getContentResolver(),
699 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
700 // Treat any non-OFF values as ON.
701 if (airplaneMode != AIRPLANE_OFF) {
702 airplaneMode = AIRPLANE_ON;
703 }
Chris Mantona09f3632016-02-09 14:48:42 -0800704 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700705 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
706 (mPUKEntryActivity != null)) {
707 // if an attempt to un-PUK-lock the device was made, while we're
708 // receiving this state change notification, notify the handler.
709 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
710 // been attempted.
711 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
712 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
713 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
714 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800715 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
716 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
718 handleServiceStateChanged(intent);
719 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530720 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530721 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530722 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
723 if (phoneInEcm != null) {
724 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
725 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
726 // Start Emergency Callback Mode service
727 if (intent.getBooleanExtra("phoneinECMState", false)) {
728 context.startService(new Intent(context,
729 EmergencyCallbackModeService.class));
730 } else {
731 phoneInEcm = null;
732 }
733 } else {
734 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
735 // on a device that doesn't support ECM in the first place.
736 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
737 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
738 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739 }
740 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530741 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700742 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700743 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
744 // Roaming status could be overridden by carrier config, so we need to update it.
745 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
746 updateDataRoamingStatus();
747 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
748 // We also need to pay attention when default data subscription changes.
749 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
750 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
751 registerSettingsObserver();
752 Phone phone = getPhone(mDefaultDataSubId);
753 if (phone != null) {
754 updateDataRoamingStatus();
755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700756 }
757 }
758 }
759
Brad Ebinger28626122017-08-10 14:13:35 -0700760 private class SipReceiver extends BroadcastReceiver {
761
762 @Override
763 public void onReceive(Context context, Intent intent) {
764 String action = intent.getAction();
765
766 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
767 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
768 SipUtil.startSipService();
769 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
770 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
771 sipAccountRegistry.setup(context);
772 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
773 if (DBG) {
774 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
775 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
776 }
777 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
778 SipManager.EXTRA_LOCAL_URI));
779 } else {
780 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
781 }
782 }
783 }
784
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785 private void handleServiceStateChanged(Intent intent) {
786 /**
787 * This used to handle updating EriTextWidgetProvider this routine
788 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
789 * be removed. But leaving just in case it might be needed in the near
790 * future.
791 */
792
Jack Yu1a2fc352017-07-14 17:14:37 -0700793 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700794 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700795 Bundle extras = intent.getExtras();
796 if (extras != null) {
797 ServiceState ss = ServiceState.newFromBundle(extras);
798 if (ss != null) {
799 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700800 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
801 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
802 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700803
804 if (VDBG) {
805 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
806 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
807 }
808 if (subId == mDefaultDataSubId) {
809 updateDataRoamingStatus();
810 }
Santos Cordonc593d002015-06-03 15:41:15 -0700811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 }
813 }
814
Jack Yu1a2fc352017-07-14 17:14:37 -0700815 /**
816 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
817 * to notify the user so they can enable it through settings. Vise versa if the condition
818 * changes, we need to dismiss the notification.
819 */
820 private void updateDataRoamingStatus() {
821 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
822 Phone phone = getPhone(mDefaultDataSubId);
823 if (phone == null) {
824 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
825 return;
826 }
827
828 DataConnectionReasons reasons = new DataConnectionReasons();
829 boolean dataAllowed = phone.isDataAllowed(reasons);
830 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
831 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
832 if (!mNoDataDueToRoaming
833 && !dataAllowed
834 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
835 // If the only reason of no data is data roaming disabled, then we notify the user
836 // so the user can turn on data roaming.
837 mNoDataDueToRoaming = true;
838 Log.d(LOG_TAG, "Show roaming disconnected notification");
839 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700840 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
841 msg.arg1 = mDefaultDataSubId;
842 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700843 } else if (mNoDataDueToRoaming && (dataAllowed
844 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
845 // Otherwise dismiss the notification we showed earlier.
846 mNoDataDueToRoaming = false;
847 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
848 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
849 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
850 }
851 }
852
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530853 public Phone getPhoneInEcm() {
854 return phoneInEcm;
855 }
856
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700857 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800858 * Triggers a refresh of the message waiting (voicemail) indicator.
859 *
860 * @param subId the subscription id we should refresh the notification for.
861 */
862 public void refreshMwiIndicator(int subId) {
863 notificationMgr.refreshMwi(subId);
864 }
865
866 /**
Pengquan Menge3d01e22018-09-20 15:25:35 -0700867 * Called when the network selection on the subscription {@code subId} is changed by the user.
868 *
869 * @param subId the subscription id.
870 */
871 public void onNetworkSelectionChanged(int subId) {
872 Phone phone = getPhone(subId);
873 if (phone != null) {
874 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
875 } else {
876 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
877 }
878 }
879
880 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700881 * Dismisses the message waiting (voicemail) indicator.
882 *
883 * @param subId the subscription id we should dismiss the notification for.
884 */
885 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700886 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
887 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700888 Phone phone = getPhone(subId);
889 if (phone == null) {
890 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
891 } else {
892 phone.setVoiceMessageCount(0);
893 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700894 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700895
896 /**
897 * Enables or disables the visual voicemail check for message waiting indicator. Default value
898 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
899 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
900 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
901 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
902 * configuration state will be cleared and the MWI for voicemail that arrives when the device
903 * is offline will be cleared, even if the account cannot be activated. A full solution will be
904 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
905 * risky at this moment. This is a temporary workaround to shut down the configuration state
906 * check if visual voicemail cannot be activated.
907 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
908 *
909 * @param subId the account to set the enabled state
910 */
911 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
912 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
913 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700914
915 /**
916 * Dump the state of the object, add calls to other objects as desired.
917 *
918 * @param fd File descriptor
919 * @param printWriter Print writer
920 * @param args Arguments
921 */
922 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
923 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
924 pw.println("------- PhoneGlobals -------");
925 pw.increaseIndent();
926 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
927 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
928 pw.println("mDataRoamingNotifLog:");
929 pw.increaseIndent();
930 mDataRoamingNotifLog.dump(fd, pw, args);
931 pw.decreaseIndent();
932 pw.decreaseIndent();
933 pw.println("------- End PhoneGlobals -------");
934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935}