blob: 062286ce44733009b81e76277556de44718636d5 [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;
Santos Cordon352ff652014-05-30 01:41:45 -070065import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080066import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070067import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070068import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070069import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070
Jack Yu1a2fc352017-07-14 17:14:37 -070071import java.io.FileDescriptor;
72import java.io.PrintWriter;
73
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074/**
75 * Global state for the telephony subsystem when running in the primary
76 * phone process.
77 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070078public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070079 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080
81 /**
82 * Phone app-wide debug level:
83 * 0 - no debug logging
84 * 1 - normal debug logging if ro.debuggable is set (which is true in
85 * "eng" and "userdebug" builds but not "user" builds)
86 * 2 - ultra-verbose debug logging
87 *
88 * Most individual classes in the phone app have a local DBG constant,
89 * typically set to
90 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
91 * or else
92 * (PhoneApp.DBG_LEVEL >= 2)
93 * depending on the desired verbosity.
94 *
95 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
96 */
Andrew Lee88b51e22014-10-29 15:48:51 -070097 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99 private static final boolean DBG =
100 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
101 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
102
103 // Message codes; see mHandler below.
104 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
107 private static final int EVENT_DATA_ROAMING_OK = 11;
108 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700109 private static final int EVENT_RESTART_SIP = 13;
Jack Yu1a2fc352017-07-14 17:14:37 -0700110 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
111 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112
113 // The MMI codes are also used by the InCallScreen.
114 public static final int MMI_INITIATE = 51;
115 public static final int MMI_COMPLETE = 52;
116 public static final int MMI_CANCEL = 53;
117 // Don't use message codes larger than 99 here; those are reserved for
118 // the individual Activities of the Phone UI.
119
Santos Cordone18902f2016-03-22 17:16:04 -0700120 public static final int AIRPLANE_ON = 1;
121 public static final int AIRPLANE_OFF = 0;
122
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123 /**
124 * Allowable values for the wake lock code.
125 * SLEEP means the device can be put to sleep.
126 * PARTIAL means wake the processor, but we display can be kept off.
127 * FULL means wake both the processor and the display.
128 */
129 public enum WakeState {
130 SLEEP,
131 PARTIAL,
132 FULL
133 }
134
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135 private static PhoneGlobals sMe;
136
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700138 CallNotifier notifier;
139 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700140 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700141 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800142 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700143
Santos Cordon69a69192013-08-22 14:25:42 -0700144 private CallGatewayManager callGatewayManager;
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530145 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700146
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 static boolean sVoiceCapable = true;
148
Santos Cordonc593d002015-06-03 15:41:15 -0700149 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 CdmaPhoneCallState cdmaPhoneCallState;
151
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 // The currently-active PUK entry activity and progress dialog.
153 // Normally, these are the Emergency Dialer and the subsequent
154 // progress dialog. null if there is are no such objects in
155 // the foreground.
156 private Activity mPUKEntryActivity;
157 private ProgressDialog mPUKEntryProgressDialog;
158
Jack Yu1a2fc352017-07-14 17:14:37 -0700159 private boolean mNoDataDueToRoaming = false;
Jack Yu953f9352017-05-18 14:41:06 -0700160
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 private WakeState mWakeState = WakeState.SLEEP;
162
163 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private PowerManager.WakeLock mWakeLock;
165 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167
168 private UpdateLock mUpdateLock;
169
Jack Yu1a2fc352017-07-14 17:14:37 -0700170 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
171 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
172
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 // Broadcast receiver for various intent broadcasts (see onCreate())
174 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700175 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700176 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700178 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
179 new CarrierVvmPackageInstalledReceiver();
180
Jack Yu1a2fc352017-07-14 17:14:37 -0700181 private final SettingsObserver mSettingsObserver;
182
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183 Handler mHandler = new Handler() {
184 @Override
185 public void handleMessage(Message msg) {
186 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700187 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 // TODO: This event should be handled by the lock screen, just
190 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
191 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700192 if (getCarrierConfig().getBoolean(
193 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 // Some products don't have the concept of a "SIM network lock"
195 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000196 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 } else {
198 // Normal case: show the "SIM network unlock" PIN entry screen.
199 // The user won't be able to do anything else until
200 // they enter a valid SIM network PIN.
201 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700202 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 }
204 break;
205
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206 case EVENT_DATA_ROAMING_DISCONNECTED:
Pengquan Meng8783d932017-10-16 14:57:40 -0700207 notificationMgr.showDataDisconnectedRoaming(msg.arg1);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 break;
209
210 case EVENT_DATA_ROAMING_OK:
211 notificationMgr.hideDataDisconnectedRoaming();
212 break;
213
214 case MMI_COMPLETE:
215 onMMIComplete((AsyncResult) msg.obj);
216 break;
217
218 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800219 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 break;
221
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 case EVENT_SIM_STATE_CHANGED:
223 // Marks the event where the SIM goes into ready state.
224 // Right now, this is only used for the PUK-unlocking
225 // process.
226 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
227 // when the right event is triggered and there
228 // are UI objects in the foreground, we close
229 // them to display the lock panel.
230 if (mPUKEntryActivity != null) {
231 mPUKEntryActivity.finish();
232 mPUKEntryActivity = null;
233 }
234 if (mPUKEntryProgressDialog != null) {
235 mPUKEntryProgressDialog.dismiss();
236 mPUKEntryProgressDialog = null;
237 }
238 }
239 break;
240
241 case EVENT_UNSOL_CDMA_INFO_RECORD:
242 //TODO: handle message here;
243 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700244 case EVENT_RESTART_SIP:
245 // This should only run if the Phone process crashed and was restarted. We do
246 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700247 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700248 // upon BOOT_COMPLETED.
249 UserManager userManager = UserManager.get(sMe);
250 if (userManager != null && userManager.isUserUnlocked()) {
251 SipUtil.startSipService();
252 }
253 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700254 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
255 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
256 updateDataRoamingStatus();
257 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259 }
260 };
261
262 public PhoneGlobals(Context context) {
263 super(context);
264 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700265 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266 }
267
268 public void onCreate() {
269 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
270
271 ContentResolver resolver = getContentResolver();
272
273 // Cache the "voice capable" flag.
274 // This flag currently comes from a resource (which is
275 // overrideable on a per-product basis):
276 sVoiceCapable =
277 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
278 // ...but this might eventually become a PackageManager "system
279 // feature" instead, in which case we'd do something like:
280 // sVoiceCapable =
281 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
282
Stuart Scottdcf40a92014-12-09 10:45:01 -0800283 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 // Initialize the telephony framework
285 PhoneFactory.makeDefaultPhones(this);
286
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 // Start TelephonyDebugService After the default phone is created.
288 Intent intent = new Intent(this, TelephonyDebugService.class);
289 startService(intent);
290
291 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800292 for (Phone phone : PhoneFactory.getPhones()) {
293 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
296 // Create the NotificationMgr singleton, which is used to display
297 // status bar icons and control other status bar behavior.
298 notificationMgr = NotificationMgr.init(this);
299
Brad Ebinger3fa43462016-04-12 16:06:48 -0700300 // If PhoneGlobals has crashed and is being restarted, then restart.
301 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
302
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700303 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
304 cdmaPhoneCallState = new CdmaPhoneCallState();
305 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 // before registering for phone state changes
308 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
309 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
310 // lock used to keep the processor awake, when we don't care for the display.
311 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
312 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
314 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
315
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
317 // during phone calls.
318 mUpdateLock = new UpdateLock("phone");
319
320 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
321
322 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
323
Jay Shrauner21a75342013-11-25 16:14:43 -0800324 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700325
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 // Create the CallerInfoCache singleton, which remembers custom ring tone and
327 // send-to-voicemail settings.
328 //
329 // The asynchronous caching will start just after this call.
330 callerInfoCache = CallerInfoCache.init(this);
331
Stuart Scottdcf40a92014-12-09 10:45:01 -0800332 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700333
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800334 configLoader = CarrierConfigLoader.init(this);
335
Jack Yu1a2fc352017-07-14 17:14:37 -0700336 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // asynchronous events from the telephony layer (like
338 // launching the incoming-call UI when an incoming call comes
339 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800340 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Stuart Scottdcf40a92014-12-09 10:45:01 -0800342 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
344 // register for MMI/USSD
345 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
346
347 // register connection tracking to PhoneUtils
348 PhoneUtils.initializeConnectionHandler(mCM);
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 // Register for misc other intent broadcasts.
351 IntentFilter intentFilter =
352 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
354 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
355 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
356 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700357 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
358 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 registerReceiver(mReceiver, intentFilter);
360
Brad Ebinger533c6c12017-08-02 11:38:48 -0700361 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700362 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
363 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
364 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700365 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700366
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700367 mCarrierVvmPackageInstalledReceiver.register(this);
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800370 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
372 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
373
374 // Make sure the audio mode (along with some
375 // audio-mode-related state of our own) is initialized
376 // correctly, given the current state of the phone.
377 PhoneUtils.setAudioMode(mCM);
378 }
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 // XXX pre-load the SimProvider so that it's ready
381 resolver.getType(Uri.parse("content://icc/adn"));
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // TODO: Register for Cdma Information Records
384 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 // Read HAC settings and configure audio hardware
387 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800388 int hac = android.provider.Settings.System.getInt(
389 getContentResolver(),
390 android.provider.Settings.System.HEARING_AID,
391 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800393 audioManager.setParameter(SettingsConstants.HAC_KEY,
394 hac == SettingsConstants.HAC_ENABLED
395 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 }
Santos Cordonff506f52013-11-21 19:13:19 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 /**
400 * Returns the singleton instance of the PhoneApp.
401 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800402 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 if (sMe == null) {
404 throw new IllegalStateException("No PhoneGlobals here!");
405 }
406 return sMe;
407 }
408
409 /**
410 * Returns the singleton instance of the PhoneApp if running as the
411 * primary user, otherwise null.
412 */
413 static PhoneGlobals getInstanceIfPrimary() {
414 return sMe;
415 }
416
417 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800418 * Returns the default phone.
419 *
Andrew Lee385019f2014-11-24 14:19:50 -0800420 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 */
Andrew Lee83383e42014-10-31 12:42:28 -0700422 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800423 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 }
425
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800426 public static Phone getPhone(int subId) {
427 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800428 }
429
Santos Cordonde10b752013-09-19 04:11:33 -0700430 /* package */ CallManager getCallManager() {
431 return mCM;
432 }
433
Chris Manton4e9fa912015-06-19 11:26:57 -0700434 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800435 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700436 }
437
Chris Manton4e9fa912015-06-19 11:26:57 -0700438 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700439 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700440 }
441
Jack Yu1a2fc352017-07-14 17:14:37 -0700442 private void registerSettingsObserver() {
443 mSettingsObserver.unobserve();
444 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
445 String mobileDataSetting = Settings.Global.MOBILE_DATA;
446 if (TelephonyManager.getDefault().getSimCount() > 1) {
447 int subId = mDefaultDataSubId;
448 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
449 dataRoamingSetting += subId;
450 mobileDataSetting += subId;
451 }
452 }
453
454 // Listen for user data roaming setting changed event
455 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
456 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
457
458 // Listen for mobile data setting changed event
459 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
460 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
461 }
462
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 * Sets the activity responsible for un-PUK-blocking the device
465 * so that we may close it when we receive a positive result.
466 * mPUKEntryActivity is also used to indicate to the device that
467 * we are trying to un-PUK-lock the phone. In other words, iff
468 * it is NOT null, then we are trying to unlock and waiting for
469 * the SIM to move to READY state.
470 *
471 * @param activity is the activity to close when PUK has
472 * finished unlocking. Can be set to null to indicate the unlock
473 * or SIM READYing process is over.
474 */
475 void setPukEntryActivity(Activity activity) {
476 mPUKEntryActivity = activity;
477 }
478
479 Activity getPUKEntryActivity() {
480 return mPUKEntryActivity;
481 }
482
483 /**
484 * Sets the dialog responsible for notifying the user of un-PUK-
485 * blocking - SIM READYing progress, so that we may dismiss it
486 * when we receive a positive result.
487 *
488 * @param dialog indicates the progress dialog informing the user
489 * of the state of the device. Dismissed upon completion of
490 * READYing process
491 */
492 void setPukEntryProgressDialog(ProgressDialog dialog) {
493 mPUKEntryProgressDialog = dialog;
494 }
495
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 /**
497 * Controls whether or not the screen is allowed to sleep.
498 *
499 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
500 * settings for the poke lock to determine when to timeout and let
501 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
502 *
503 * @param ws tells the device to how to wake.
504 */
505 /* package */ void requestWakeState(WakeState ws) {
506 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
507 synchronized (this) {
508 if (mWakeState != ws) {
509 switch (ws) {
510 case PARTIAL:
511 // acquire the processor wake lock, and release the FULL
512 // lock if it is being held.
513 mPartialWakeLock.acquire();
514 if (mWakeLock.isHeld()) {
515 mWakeLock.release();
516 }
517 break;
518 case FULL:
519 // acquire the full wake lock, and release the PARTIAL
520 // lock if it is being held.
521 mWakeLock.acquire();
522 if (mPartialWakeLock.isHeld()) {
523 mPartialWakeLock.release();
524 }
525 break;
526 case SLEEP:
527 default:
528 // release both the PARTIAL and FULL locks.
529 if (mWakeLock.isHeld()) {
530 mWakeLock.release();
531 }
532 if (mPartialWakeLock.isHeld()) {
533 mPartialWakeLock.release();
534 }
535 break;
536 }
537 mWakeState = ws;
538 }
539 }
540 }
541
542 /**
543 * If we are not currently keeping the screen on, then poke the power
544 * manager to wake up the screen for the user activity timeout duration.
545 */
546 /* package */ void wakeUpScreen() {
547 synchronized (this) {
548 if (mWakeState == WakeState.SLEEP) {
549 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700550 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 }
552 }
553 }
554
555 /**
556 * Sets the wake state and screen timeout based on the current state
557 * of the phone, and the current state of the in-call UI.
558 *
559 * This method is a "UI Policy" wrapper around
560 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
561 *
562 * It's safe to call this method regardless of the state of the Phone
563 * (e.g. whether or not it's idle), and regardless of the state of the
564 * Phone UI (e.g. whether or not the InCallScreen is active.)
565 */
566 /* package */ void updateWakeState() {
567 PhoneConstants.State state = mCM.getState();
568
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // True if the speakerphone is in use. (If so, we *always* use
570 // the default timeout. Since the user is obviously not holding
571 // the phone up to his/her face, we don't need to worry about
572 // false touches, and thus don't need to turn the screen off so
573 // aggressively.)
574 // Note that we need to make a fresh call to this method any
575 // time the speaker state changes. (That happens in
576 // PhoneUtils.turnOnSpeaker().)
577 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
578
579 // TODO (bug 1440854): The screen timeout *might* also need to
580 // depend on the bluetooth state, but this isn't as clear-cut as
581 // the speaker state (since while using BT it's common for the
582 // user to put the phone straight into a pocket, in which case the
583 // timeout should probably still be short.)
584
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 // Decide whether to force the screen on or not.
586 //
587 // Force the screen to be on if the phone is ringing or dialing,
588 // or if we're displaying the "Call ended" UI for a connection in
589 // the "disconnected" state.
590 // However, if the phone is disconnected while the user is in the
591 // middle of selecting a quick response message, we should not force
592 // the screen to be on.
593 //
594 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800595 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700596 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 // keepScreenOn == true means we'll hold a full wake lock:
598 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
599 }
600
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 KeyguardManager getKeyguardManager() {
602 return mKeyguardManager;
603 }
604
605 private void onMMIComplete(AsyncResult r) {
606 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
607 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800608 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609 }
610
fionaxu80126972017-02-01 17:01:26 -0800611 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 }
615
Chris Mantona09f3632016-02-09 14:48:42 -0800616 private void handleAirplaneModeChange(Context context, int newMode) {
617 int cellState = Settings.Global.getInt(context.getContentResolver(),
618 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
619 boolean isAirplaneNewlyOn = (newMode == 1);
620 switch (cellState) {
621 case PhoneConstants.CELL_OFF_FLAG:
622 // Airplane mode does not affect the cell radio if user
623 // has turned it off.
624 break;
625 case PhoneConstants.CELL_ON_FLAG:
626 maybeTurnCellOff(context, isAirplaneNewlyOn);
627 break;
628 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
629 maybeTurnCellOn(context, isAirplaneNewlyOn);
630 break;
631 }
632 }
633
634 /*
635 * Returns true if the radio must be turned off when entering airplane mode.
636 */
637 private boolean isCellOffInAirplaneMode(Context context) {
638 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
639 Settings.Global.AIRPLANE_MODE_RADIOS);
640 return airplaneModeRadios == null
641 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
642 }
643
644 private void setRadioPowerOff(Context context) {
645 Log.i(LOG_TAG, "Turning radio off - airplane");
646 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000647 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700648 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800649 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
650 PhoneUtils.setRadioPower(false);
651 }
652
653 private void setRadioPowerOn(Context context) {
654 Log.i(LOG_TAG, "Turning radio on - airplane");
655 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
656 PhoneConstants.CELL_ON_FLAG);
657 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
658 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700659 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800660 PhoneUtils.setRadioPower(true);
661 }
662
663 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
664 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700665 // If we are trying to turn off the radio, make sure there are no active
666 // emergency calls. If there are, switch airplane mode back to off.
667 if (PhoneUtils.isInEmergencyCall(mCM)) {
668 // Switch airplane mode back to off.
669 ConnectivityManager.from(this).setAirplaneMode(false);
670 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
671 .show();
672 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800673 } else if (isCellOffInAirplaneMode(context)) {
674 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700675 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800676 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700677 }
Chris Mantona09f3632016-02-09 14:48:42 -0800678 }
679 }
680
681 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
682 if (!isAirplaneNewlyOn) {
683 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700684 }
685 }
686
Santos Cordon593ab382013-08-06 21:58:23 -0700687 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700688 * Receiver for misc intent broadcasts the Phone app cares about.
689 */
690 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
691 @Override
692 public void onReceive(Context context, Intent intent) {
693 String action = intent.getAction();
694 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700695 int airplaneMode = Settings.Global.getInt(getContentResolver(),
696 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
697 // Treat any non-OFF values as ON.
698 if (airplaneMode != AIRPLANE_OFF) {
699 airplaneMode = AIRPLANE_ON;
700 }
Chris Mantona09f3632016-02-09 14:48:42 -0800701 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
703 (mPUKEntryActivity != null)) {
704 // if an attempt to un-PUK-lock the device was made, while we're
705 // receiving this state change notification, notify the handler.
706 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
707 // been attempted.
708 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
709 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
710 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
711 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800712 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
713 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700714 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
715 handleServiceStateChanged(intent);
716 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530717 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530718 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530719 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
720 if (phoneInEcm != null) {
721 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
722 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
723 // Start Emergency Callback Mode service
724 if (intent.getBooleanExtra("phoneinECMState", false)) {
725 context.startService(new Intent(context,
726 EmergencyCallbackModeService.class));
727 } else {
728 phoneInEcm = null;
729 }
730 } else {
731 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
732 // on a device that doesn't support ECM in the first place.
733 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
734 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
735 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700736 }
737 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530738 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700740 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
741 // Roaming status could be overridden by carrier config, so we need to update it.
742 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
743 updateDataRoamingStatus();
744 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
745 // We also need to pay attention when default data subscription changes.
746 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
747 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
748 registerSettingsObserver();
749 Phone phone = getPhone(mDefaultDataSubId);
750 if (phone != null) {
751 updateDataRoamingStatus();
752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700753 }
754 }
755 }
756
Brad Ebinger28626122017-08-10 14:13:35 -0700757 private class SipReceiver extends BroadcastReceiver {
758
759 @Override
760 public void onReceive(Context context, Intent intent) {
761 String action = intent.getAction();
762
763 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
764 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
765 SipUtil.startSipService();
766 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
767 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
768 sipAccountRegistry.setup(context);
769 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
770 if (DBG) {
771 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
772 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
773 }
774 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
775 SipManager.EXTRA_LOCAL_URI));
776 } else {
777 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
778 }
779 }
780 }
781
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 private void handleServiceStateChanged(Intent intent) {
783 /**
784 * This used to handle updating EriTextWidgetProvider this routine
785 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
786 * be removed. But leaving just in case it might be needed in the near
787 * future.
788 */
789
Jack Yu1a2fc352017-07-14 17:14:37 -0700790 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700792 Bundle extras = intent.getExtras();
793 if (extras != null) {
794 ServiceState ss = ServiceState.newFromBundle(extras);
795 if (ss != null) {
796 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700797 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
798 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
799 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700800
801 if (VDBG) {
802 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
803 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
804 }
805 if (subId == mDefaultDataSubId) {
806 updateDataRoamingStatus();
807 }
Santos Cordonc593d002015-06-03 15:41:15 -0700808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700809 }
810 }
811
Jack Yu1a2fc352017-07-14 17:14:37 -0700812 /**
813 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
814 * to notify the user so they can enable it through settings. Vise versa if the condition
815 * changes, we need to dismiss the notification.
816 */
817 private void updateDataRoamingStatus() {
818 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
819 Phone phone = getPhone(mDefaultDataSubId);
820 if (phone == null) {
821 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
822 return;
823 }
824
825 DataConnectionReasons reasons = new DataConnectionReasons();
826 boolean dataAllowed = phone.isDataAllowed(reasons);
827 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
828 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
829 if (!mNoDataDueToRoaming
830 && !dataAllowed
831 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
832 // If the only reason of no data is data roaming disabled, then we notify the user
833 // so the user can turn on data roaming.
834 mNoDataDueToRoaming = true;
835 Log.d(LOG_TAG, "Show roaming disconnected notification");
836 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700837 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
838 msg.arg1 = mDefaultDataSubId;
839 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700840 } else if (mNoDataDueToRoaming && (dataAllowed
841 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
842 // Otherwise dismiss the notification we showed earlier.
843 mNoDataDueToRoaming = false;
844 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
845 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
846 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
847 }
848 }
849
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530850 public Phone getPhoneInEcm() {
851 return phoneInEcm;
852 }
853
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700854 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800855 * Triggers a refresh of the message waiting (voicemail) indicator.
856 *
857 * @param subId the subscription id we should refresh the notification for.
858 */
859 public void refreshMwiIndicator(int subId) {
860 notificationMgr.refreshMwi(subId);
861 }
862
863 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700864 * Dismisses the message waiting (voicemail) indicator.
865 *
866 * @param subId the subscription id we should dismiss the notification for.
867 */
868 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700869 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
870 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700871 Phone phone = getPhone(subId);
872 if (phone == null) {
873 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
874 } else {
875 phone.setVoiceMessageCount(0);
876 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700877 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700878
879 /**
880 * Enables or disables the visual voicemail check for message waiting indicator. Default value
881 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
882 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
883 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
884 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
885 * configuration state will be cleared and the MWI for voicemail that arrives when the device
886 * is offline will be cleared, even if the account cannot be activated. A full solution will be
887 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
888 * risky at this moment. This is a temporary workaround to shut down the configuration state
889 * check if visual voicemail cannot be activated.
890 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
891 *
892 * @param subId the account to set the enabled state
893 */
894 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
895 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
896 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700897
898 /**
899 * Dump the state of the object, add calls to other objects as desired.
900 *
901 * @param fd File descriptor
902 * @param printWriter Print writer
903 * @param args Arguments
904 */
905 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
906 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
907 pw.println("------- PhoneGlobals -------");
908 pw.increaseIndent();
909 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
910 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
911 pw.println("mDataRoamingNotifLog:");
912 pw.increaseIndent();
913 mDataRoamingNotifLog.dump(fd, pw, args);
914 pw.decreaseIndent();
915 pw.decreaseIndent();
916 pw.println("------- End PhoneGlobals -------");
917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700918}