blob: fae712aa289e9f392a3b9e97af3c7c11d50df05f [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;
31import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070032import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070035import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.SystemClock;
38import android.os.SystemProperties;
39import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070040import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080042import android.provider.Settings;
Junda Liu12f7d802015-05-01 12:06:44 -070043import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.telephony.ServiceState;
Andrew Lee385019f2014-11-24 14:19:50 -080045import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070047import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070048
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import com.android.internal.telephony.Call;
50import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import com.android.internal.telephony.IccCardConstants;
52import com.android.internal.telephony.MmiCode;
53import com.android.internal.telephony.Phone;
54import com.android.internal.telephony.PhoneConstants;
55import com.android.internal.telephony.PhoneFactory;
56import com.android.internal.telephony.TelephonyCapabilities;
57import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070058import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080059import com.android.phone.settings.SettingsConstants;
Brad Ebinger3fa43462016-04-12 16:06:48 -070060import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061
62/**
63 * Global state for the telephony subsystem when running in the primary
64 * phone process.
65 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070066public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070067 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068
69 /**
70 * Phone app-wide debug level:
71 * 0 - no debug logging
72 * 1 - normal debug logging if ro.debuggable is set (which is true in
73 * "eng" and "userdebug" builds but not "user" builds)
74 * 2 - ultra-verbose debug logging
75 *
76 * Most individual classes in the phone app have a local DBG constant,
77 * typically set to
78 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
79 * or else
80 * (PhoneApp.DBG_LEVEL >= 2)
81 * depending on the desired verbosity.
82 *
83 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
84 */
Andrew Lee88b51e22014-10-29 15:48:51 -070085 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
87 private static final boolean DBG =
88 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
89 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
90
91 // Message codes; see mHandler below.
92 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
95 private static final int EVENT_DATA_ROAMING_OK = 11;
96 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -070097 private static final int EVENT_RESTART_SIP = 13;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99 // The MMI codes are also used by the InCallScreen.
100 public static final int MMI_INITIATE = 51;
101 public static final int MMI_COMPLETE = 52;
102 public static final int MMI_CANCEL = 53;
103 // Don't use message codes larger than 99 here; those are reserved for
104 // the individual Activities of the Phone UI.
105
Santos Cordone18902f2016-03-22 17:16:04 -0700106 public static final int AIRPLANE_ON = 1;
107 public static final int AIRPLANE_OFF = 0;
108
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 /**
110 * Allowable values for the wake lock code.
111 * SLEEP means the device can be put to sleep.
112 * PARTIAL means wake the processor, but we display can be kept off.
113 * FULL means wake both the processor and the display.
114 */
115 public enum WakeState {
116 SLEEP,
117 PARTIAL,
118 FULL
119 }
120
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 private static PhoneGlobals sMe;
122
123 // A few important fields we expose to the rest of the package
124 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700127 CallNotifier notifier;
128 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700129 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700130 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800131 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700132
Santos Cordon69a69192013-08-22 14:25:42 -0700133 private CallGatewayManager callGatewayManager;
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530134 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 static boolean sVoiceCapable = true;
137
Santos Cordonc593d002015-06-03 15:41:15 -0700138 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 CdmaPhoneCallState cdmaPhoneCallState;
140
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 // The currently-active PUK entry activity and progress dialog.
142 // Normally, these are the Emergency Dialer and the subsequent
143 // progress dialog. null if there is are no such objects in
144 // the foreground.
145 private Activity mPUKEntryActivity;
146 private ProgressDialog mPUKEntryProgressDialog;
147
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800148 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 private WakeState mWakeState = WakeState.SLEEP;
151
152 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 private PowerManager.WakeLock mWakeLock;
154 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156
157 private UpdateLock mUpdateLock;
158
159 // Broadcast receiver for various intent broadcasts (see onCreate())
160 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 /**
163 * The singleton OtaUtils instance used for OTASP calls.
164 *
165 * The OtaUtils instance is created lazily the first time we need to
166 * make an OTASP call, regardless of whether it's an interactive or
167 * non-interactive OTASP call.
168 */
169 public OtaUtils otaUtils;
170
171 // Following are the CDMA OTA information Objects used during OTA Call.
172 // cdmaOtaProvisionData object store static OTA information that needs
173 // to be maintained even during Slider open/close scenarios.
174 // cdmaOtaConfigData object stores configuration info to control visiblity
175 // of each OTA Screens.
176 // cdmaOtaScreenState object store OTA Screen State information.
177 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
178 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
179 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
180 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
181
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 Handler mHandler = new Handler() {
183 @Override
184 public void handleMessage(Message msg) {
185 PhoneConstants.State phoneState;
186 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 // TODO: This event should be handled by the lock screen, just
188 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
189 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700190 if (getCarrierConfig().getBoolean(
191 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 // Some products don't have the concept of a "SIM network lock"
193 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
194 + "not showing 'SIM network unlock' PIN entry screen");
195 } else {
196 // Normal case: show the "SIM network unlock" PIN entry screen.
197 // The user won't be able to do anything else until
198 // they enter a valid SIM network PIN.
199 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700200 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 }
202 break;
203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 case EVENT_DATA_ROAMING_DISCONNECTED:
205 notificationMgr.showDataDisconnectedRoaming();
206 break;
207
208 case EVENT_DATA_ROAMING_OK:
209 notificationMgr.hideDataDisconnectedRoaming();
210 break;
211
212 case MMI_COMPLETE:
213 onMMIComplete((AsyncResult) msg.obj);
214 break;
215
216 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800217 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 break;
219
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 case EVENT_SIM_STATE_CHANGED:
221 // Marks the event where the SIM goes into ready state.
222 // Right now, this is only used for the PUK-unlocking
223 // process.
224 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
225 // when the right event is triggered and there
226 // are UI objects in the foreground, we close
227 // them to display the lock panel.
228 if (mPUKEntryActivity != null) {
229 mPUKEntryActivity.finish();
230 mPUKEntryActivity = null;
231 }
232 if (mPUKEntryProgressDialog != null) {
233 mPUKEntryProgressDialog.dismiss();
234 mPUKEntryProgressDialog = null;
235 }
236 }
237 break;
238
239 case EVENT_UNSOL_CDMA_INFO_RECORD:
240 //TODO: handle message here;
241 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700242 case EVENT_RESTART_SIP:
243 // This should only run if the Phone process crashed and was restarted. We do
244 // not want this running if the device is still in the FBE encrypted state.
245 // This is the same procedure that is triggered in the SipBroadcastReceiver
246 // upon BOOT_COMPLETED.
247 UserManager userManager = UserManager.get(sMe);
248 if (userManager != null && userManager.isUserUnlocked()) {
249 SipUtil.startSipService();
250 }
251 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 }
253 }
254 };
255
256 public PhoneGlobals(Context context) {
257 super(context);
258 sMe = this;
259 }
260
261 public void onCreate() {
262 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
263
264 ContentResolver resolver = getContentResolver();
265
266 // Cache the "voice capable" flag.
267 // This flag currently comes from a resource (which is
268 // overrideable on a per-product basis):
269 sVoiceCapable =
270 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
271 // ...but this might eventually become a PackageManager "system
272 // feature" instead, in which case we'd do something like:
273 // sVoiceCapable =
274 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
275
Stuart Scottdcf40a92014-12-09 10:45:01 -0800276 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 // Initialize the telephony framework
278 PhoneFactory.makeDefaultPhones(this);
279
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 // Start TelephonyDebugService After the default phone is created.
281 Intent intent = new Intent(this, TelephonyDebugService.class);
282 startService(intent);
283
284 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800285 for (Phone phone : PhoneFactory.getPhones()) {
286 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
289 // Create the NotificationMgr singleton, which is used to display
290 // status bar icons and control other status bar behavior.
291 notificationMgr = NotificationMgr.init(this);
292
Brad Ebinger3fa43462016-04-12 16:06:48 -0700293 // If PhoneGlobals has crashed and is being restarted, then restart.
294 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
295
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700296 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
297 cdmaPhoneCallState = new CdmaPhoneCallState();
298 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 // before registering for phone state changes
301 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
302 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
303 // lock used to keep the processor awake, when we don't care for the display.
304 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
305 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
307 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
308
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
310 // during phone calls.
311 mUpdateLock = new UpdateLock("phone");
312
313 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
314
315 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
316
Jay Shrauner21a75342013-11-25 16:14:43 -0800317 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 // Create the CallController singleton, which is the interface
320 // to the telephony layer for user-initiated telephony functionality
321 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700322 callController = CallController.init(this, callLogger, callGatewayManager);
323
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 // Create the CallerInfoCache singleton, which remembers custom ring tone and
325 // send-to-voicemail settings.
326 //
327 // The asynchronous caching will start just after this call.
328 callerInfoCache = CallerInfoCache.init(this);
329
Stuart Scottdcf40a92014-12-09 10:45:01 -0800330 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700331
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800332 configLoader = CarrierConfigLoader.init(this);
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 // Create the CallNotifer singleton, which handles
335 // asynchronous events from the telephony layer (like
336 // launching the incoming-call UI when an incoming call comes
337 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800338 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339
Stuart Scottdcf40a92014-12-09 10:45:01 -0800340 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
342 // register for MMI/USSD
343 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
344
345 // register connection tracking to PhoneUtils
346 PhoneUtils.initializeConnectionHandler(mCM);
347
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // Register for misc other intent broadcasts.
349 IntentFilter intentFilter =
350 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
353 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
354 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
355 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 registerReceiver(mReceiver, intentFilter);
357
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 //set the default values for the preferences in the phone.
359 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
360
361 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
362
363 // Make sure the audio mode (along with some
364 // audio-mode-related state of our own) is initialized
365 // correctly, given the current state of the phone.
366 PhoneUtils.setAudioMode(mCM);
367 }
368
Santos Cordon52bc81b2014-10-07 19:55:12 -0700369 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
370 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
371 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
372 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
374 // XXX pre-load the SimProvider so that it's ready
375 resolver.getType(Uri.parse("content://icc/adn"));
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 // TODO: Register for Cdma Information Records
378 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 // Read HAC settings and configure audio hardware
381 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800382 int hac = android.provider.Settings.System.getInt(
383 getContentResolver(),
384 android.provider.Settings.System.HEARING_AID,
385 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800387 audioManager.setParameter(SettingsConstants.HAC_KEY,
388 hac == SettingsConstants.HAC_ENABLED
389 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 }
Santos Cordonff506f52013-11-21 19:13:19 -0800391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * Returns the singleton instance of the PhoneApp.
395 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800396 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 if (sMe == null) {
398 throw new IllegalStateException("No PhoneGlobals here!");
399 }
400 return sMe;
401 }
402
403 /**
404 * Returns the singleton instance of the PhoneApp if running as the
405 * primary user, otherwise null.
406 */
407 static PhoneGlobals getInstanceIfPrimary() {
408 return sMe;
409 }
410
411 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800412 * Returns the default phone.
413 *
Andrew Lee385019f2014-11-24 14:19:50 -0800414 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 */
Andrew Lee83383e42014-10-31 12:42:28 -0700416 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800417 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 }
419
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800420 public static Phone getPhone(int subId) {
421 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800422 }
423
Santos Cordonde10b752013-09-19 04:11:33 -0700424 /* package */ CallManager getCallManager() {
425 return mCM;
426 }
427
Chris Manton4e9fa912015-06-19 11:26:57 -0700428 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800429 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700430 }
431
Chris Manton4e9fa912015-06-19 11:26:57 -0700432 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700433 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700434 }
435
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * Handles OTASP-related events from the telephony layer.
438 *
439 * While an OTASP call is active, the CallNotifier forwards
440 * OTASP-related telephony events to this method.
441 */
442 void handleOtaspEvent(Message msg) {
443 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
444
445 if (otaUtils == null) {
446 // We shouldn't be getting OTASP events without ever
447 // having started the OTASP call in the first place!
448 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
449 + "message = " + msg);
450 return;
451 }
452
453 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
454 }
455
456 /**
457 * Similarly, handle the disconnect event of an OTASP call
458 * by forwarding it to the OtaUtils instance.
459 */
460 /* package */ void handleOtaspDisconnect() {
461 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
462
463 if (otaUtils == null) {
464 // We shouldn't be getting OTASP events without ever
465 // having started the OTASP call in the first place!
466 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
467 return;
468 }
469
470 otaUtils.onOtaspDisconnect();
471 }
472
473 /**
474 * Sets the activity responsible for un-PUK-blocking the device
475 * so that we may close it when we receive a positive result.
476 * mPUKEntryActivity is also used to indicate to the device that
477 * we are trying to un-PUK-lock the phone. In other words, iff
478 * it is NOT null, then we are trying to unlock and waiting for
479 * the SIM to move to READY state.
480 *
481 * @param activity is the activity to close when PUK has
482 * finished unlocking. Can be set to null to indicate the unlock
483 * or SIM READYing process is over.
484 */
485 void setPukEntryActivity(Activity activity) {
486 mPUKEntryActivity = activity;
487 }
488
489 Activity getPUKEntryActivity() {
490 return mPUKEntryActivity;
491 }
492
493 /**
494 * Sets the dialog responsible for notifying the user of un-PUK-
495 * blocking - SIM READYing progress, so that we may dismiss it
496 * when we receive a positive result.
497 *
498 * @param dialog indicates the progress dialog informing the user
499 * of the state of the device. Dismissed upon completion of
500 * READYing process
501 */
502 void setPukEntryProgressDialog(ProgressDialog dialog) {
503 mPUKEntryProgressDialog = dialog;
504 }
505
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 /**
507 * Controls whether or not the screen is allowed to sleep.
508 *
509 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
510 * settings for the poke lock to determine when to timeout and let
511 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
512 *
513 * @param ws tells the device to how to wake.
514 */
515 /* package */ void requestWakeState(WakeState ws) {
516 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
517 synchronized (this) {
518 if (mWakeState != ws) {
519 switch (ws) {
520 case PARTIAL:
521 // acquire the processor wake lock, and release the FULL
522 // lock if it is being held.
523 mPartialWakeLock.acquire();
524 if (mWakeLock.isHeld()) {
525 mWakeLock.release();
526 }
527 break;
528 case FULL:
529 // acquire the full wake lock, and release the PARTIAL
530 // lock if it is being held.
531 mWakeLock.acquire();
532 if (mPartialWakeLock.isHeld()) {
533 mPartialWakeLock.release();
534 }
535 break;
536 case SLEEP:
537 default:
538 // release both the PARTIAL and FULL locks.
539 if (mWakeLock.isHeld()) {
540 mWakeLock.release();
541 }
542 if (mPartialWakeLock.isHeld()) {
543 mPartialWakeLock.release();
544 }
545 break;
546 }
547 mWakeState = ws;
548 }
549 }
550 }
551
552 /**
553 * If we are not currently keeping the screen on, then poke the power
554 * manager to wake up the screen for the user activity timeout duration.
555 */
556 /* package */ void wakeUpScreen() {
557 synchronized (this) {
558 if (mWakeState == WakeState.SLEEP) {
559 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700560 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561 }
562 }
563 }
564
565 /**
566 * Sets the wake state and screen timeout based on the current state
567 * of the phone, and the current state of the in-call UI.
568 *
569 * This method is a "UI Policy" wrapper around
570 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
571 *
572 * It's safe to call this method regardless of the state of the Phone
573 * (e.g. whether or not it's idle), and regardless of the state of the
574 * Phone UI (e.g. whether or not the InCallScreen is active.)
575 */
576 /* package */ void updateWakeState() {
577 PhoneConstants.State state = mCM.getState();
578
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // True if the speakerphone is in use. (If so, we *always* use
580 // the default timeout. Since the user is obviously not holding
581 // the phone up to his/her face, we don't need to worry about
582 // false touches, and thus don't need to turn the screen off so
583 // aggressively.)
584 // Note that we need to make a fresh call to this method any
585 // time the speaker state changes. (That happens in
586 // PhoneUtils.turnOnSpeaker().)
587 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
588
589 // TODO (bug 1440854): The screen timeout *might* also need to
590 // depend on the bluetooth state, but this isn't as clear-cut as
591 // the speaker state (since while using BT it's common for the
592 // user to put the phone straight into a pocket, in which case the
593 // timeout should probably still be short.)
594
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595 // Decide whether to force the screen on or not.
596 //
597 // Force the screen to be on if the phone is ringing or dialing,
598 // or if we're displaying the "Call ended" UI for a connection in
599 // the "disconnected" state.
600 // However, if the phone is disconnected while the user is in the
601 // middle of selecting a quick response message, we should not force
602 // the screen to be on.
603 //
604 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800605 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700606 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 // keepScreenOn == true means we'll hold a full wake lock:
608 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
609 }
610
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 KeyguardManager getKeyguardManager() {
612 return mKeyguardManager;
613 }
614
615 private void onMMIComplete(AsyncResult r) {
616 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
617 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800618 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 }
620
Stuart Scottdcf40a92014-12-09 10:45:01 -0800621 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
623
Stuart Scottdcf40a92014-12-09 10:45:01 -0800624 final Phone phone = PhoneFactory.getPhone(phoneId);
Santos Cordonc593d002015-06-03 15:41:15 -0700625 if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
626 // Clean up OTA for non-CDMA since it is only valid for CDMA.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 clearOtaState();
628 }
629
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 }
632
Chris Mantona09f3632016-02-09 14:48:42 -0800633 private void handleAirplaneModeChange(Context context, int newMode) {
634 int cellState = Settings.Global.getInt(context.getContentResolver(),
635 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
636 boolean isAirplaneNewlyOn = (newMode == 1);
637 switch (cellState) {
638 case PhoneConstants.CELL_OFF_FLAG:
639 // Airplane mode does not affect the cell radio if user
640 // has turned it off.
641 break;
642 case PhoneConstants.CELL_ON_FLAG:
643 maybeTurnCellOff(context, isAirplaneNewlyOn);
644 break;
645 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
646 maybeTurnCellOn(context, isAirplaneNewlyOn);
647 break;
648 }
649 }
650
651 /*
652 * Returns true if the radio must be turned off when entering airplane mode.
653 */
654 private boolean isCellOffInAirplaneMode(Context context) {
655 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
656 Settings.Global.AIRPLANE_MODE_RADIOS);
657 return airplaneModeRadios == null
658 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
659 }
660
661 private void setRadioPowerOff(Context context) {
662 Log.i(LOG_TAG, "Turning radio off - airplane");
663 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
664 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
665 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
666 PhoneUtils.setRadioPower(false);
667 }
668
669 private void setRadioPowerOn(Context context) {
670 Log.i(LOG_TAG, "Turning radio on - airplane");
671 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
672 PhoneConstants.CELL_ON_FLAG);
673 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
674 1);
675 PhoneUtils.setRadioPower(true);
676 }
677
678 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
679 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700680 // If we are trying to turn off the radio, make sure there are no active
681 // emergency calls. If there are, switch airplane mode back to off.
682 if (PhoneUtils.isInEmergencyCall(mCM)) {
683 // Switch airplane mode back to off.
684 ConnectivityManager.from(this).setAirplaneMode(false);
685 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
686 .show();
687 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800688 } else if (isCellOffInAirplaneMode(context)) {
689 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700690 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800691 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700692 }
Chris Mantona09f3632016-02-09 14:48:42 -0800693 }
694 }
695
696 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
697 if (!isAirplaneNewlyOn) {
698 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700699 }
700 }
701
Santos Cordon593ab382013-08-06 21:58:23 -0700702 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700703 * Receiver for misc intent broadcasts the Phone app cares about.
704 */
705 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
706 @Override
707 public void onReceive(Context context, Intent intent) {
708 String action = intent.getAction();
709 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700710 int airplaneMode = Settings.Global.getInt(getContentResolver(),
711 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
712 // Treat any non-OFF values as ON.
713 if (airplaneMode != AIRPLANE_OFF) {
714 airplaneMode = AIRPLANE_ON;
715 }
Chris Mantona09f3632016-02-09 14:48:42 -0800716 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800718 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
719 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
720 int phoneId = SubscriptionManager.getPhoneId(subId);
721 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
722 if (VDBG) {
723 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
724 Log.d(LOG_TAG, "- state: " + state);
725 Log.d(LOG_TAG, "- reason: "
726 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
727 Log.d(LOG_TAG, "- subId: " + subId);
728 Log.d(LOG_TAG, "- phoneId: " + phoneId);
729 }
730 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
731 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordonc593d002015-06-03 15:41:15 -0700732
Honggang0a05b652015-09-08 10:48:30 +0800733 // If not default data subscription, ignore the broadcast intent and avoid action.
Andreas Gampebab21c72016-07-19 13:54:25 -0700734 if (subId != SubscriptionManager.getDefaultDataSubscriptionId()) {
Honggang0a05b652015-09-08 10:48:30 +0800735 if (VDBG) Log.d(LOG_TAG, "Ignore broadcast intent as not default data sub.");
736 return;
737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700738 // The "data disconnected due to roaming" notification is shown
739 // if (a) you have the "data roaming" feature turned off, and
740 // (b) you just lost data connectivity because you're roaming.
741 boolean disconnectedDueToRoaming =
742 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800743 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 && Phone.REASON_ROAMING_ON.equals(
745 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800746 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
747 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
748 mHandler.sendEmptyMessage(disconnectedDueToRoaming
749 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
752 (mPUKEntryActivity != null)) {
753 // if an attempt to un-PUK-lock the device was made, while we're
754 // receiving this state change notification, notify the handler.
755 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
756 // been attempted.
757 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
758 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
759 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
760 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800761 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
762 SubscriptionManager.INVALID_PHONE_INDEX);
763 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
764 + ") is active.");
765 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700766 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
767 handleServiceStateChanged(intent);
768 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530769 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530770 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530771 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
772 if (phoneInEcm != null) {
773 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
774 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
775 // Start Emergency Callback Mode service
776 if (intent.getBooleanExtra("phoneinECMState", false)) {
777 context.startService(new Intent(context,
778 EmergencyCallbackModeService.class));
779 } else {
780 phoneInEcm = null;
781 }
782 } else {
783 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
784 // on a device that doesn't support ECM in the first place.
785 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
786 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
787 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 }
789 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530790 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700792 }
793 }
794 }
795
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700796 private void handleServiceStateChanged(Intent intent) {
797 /**
798 * This used to handle updating EriTextWidgetProvider this routine
799 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
800 * be removed. But leaving just in case it might be needed in the near
801 * future.
802 */
803
804 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700805 Bundle extras = intent.getExtras();
806 if (extras != null) {
807 ServiceState ss = ServiceState.newFromBundle(extras);
808 if (ss != null) {
809 int state = ss.getState();
810 notificationMgr.updateNetworkSelection(state);
811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 }
813 }
814
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700815 // it is safe to call clearOtaState() even if the InCallScreen isn't active
816 public void clearOtaState() {
817 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700818 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700819 otaUtils.cleanOtaScreen(true);
820 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
821 }
822 }
823
824 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
825 public void dismissOtaDialogs() {
826 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700827 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 otaUtils.dismissAllOtaDialogs();
829 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
830 }
831 }
832
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530833 public Phone getPhoneInEcm() {
834 return phoneInEcm;
835 }
836
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800838 * Triggers a refresh of the message waiting (voicemail) indicator.
839 *
840 * @param subId the subscription id we should refresh the notification for.
841 */
842 public void refreshMwiIndicator(int subId) {
843 notificationMgr.refreshMwi(subId);
844 }
845
846 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700847 * Dismisses the message waiting (voicemail) indicator.
848 *
849 * @param subId the subscription id we should dismiss the notification for.
850 */
851 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700852 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
853 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700854 Phone phone = getPhone(subId);
855 if (phone == null) {
856 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
857 } else {
858 phone.setVoiceMessageCount(0);
859 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700860 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700861
862 /**
863 * Enables or disables the visual voicemail check for message waiting indicator. Default value
864 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
865 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
866 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
867 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
868 * configuration state will be cleared and the MWI for voicemail that arrives when the device
869 * is offline will be cleared, even if the account cannot be activated. A full solution will be
870 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
871 * risky at this moment. This is a temporary workaround to shut down the configuration state
872 * check if visual voicemail cannot be activated.
873 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
874 *
875 * @param subId the account to set the enabled state
876 */
877 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
878 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700880}