blob: 036a9beee1e121cf6560987e4707483c5e9ce6ad [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
Jordan Liuff2ccd72019-07-23 15:54:41 -070019import android.annotation.IntDef;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.app.Activity;
21import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.ContextWrapper;
27import android.content.Intent;
28import android.content.IntentFilter;
Brad Ebinger05f52c22019-12-05 13:03:21 -080029import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080030import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070032import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070035import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070038import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080042import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070043import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070044import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080045import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070046import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070048import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080049import android.telephony.SubscriptionManager;
Hall Liuaa4211e2021-01-20 15:43:39 -080050import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070051import android.telephony.TelephonyManager;
Jack Yu311536f2018-11-26 11:20:48 -080052import android.telephony.data.ApnSetting;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070055import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070056
Brad Ebingere3ae65a2020-09-11 12:45:11 -070057import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010058import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.IccCardConstants;
61import com.android.internal.telephony.MmiCode;
62import com.android.internal.telephony.Phone;
63import com.android.internal.telephony.PhoneConstants;
64import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070065import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080067import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070069import com.android.internal.telephony.dataconnection.DataConnectionReasons;
70import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
Brad Ebinger05f52c22019-12-05 13:03:21 -080071import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080072import com.android.internal.telephony.imsphone.ImsPhone;
73import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000074import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070075import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070076import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080077import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070078import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080079import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080
Jack Yu1a2fc352017-07-14 17:14:37 -070081import java.io.FileDescriptor;
82import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070083import java.lang.annotation.Retention;
84import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070085import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070086
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087/**
88 * Global state for the telephony subsystem when running in the primary
89 * phone process.
90 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070091public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070092 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093
94 /**
95 * Phone app-wide debug level:
96 * 0 - no debug logging
97 * 1 - normal debug logging if ro.debuggable is set (which is true in
98 * "eng" and "userdebug" builds but not "user" builds)
99 * 2 - ultra-verbose debug logging
100 *
101 * Most individual classes in the phone app have a local DBG constant,
102 * typically set to
103 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
104 * or else
105 * (PhoneApp.DBG_LEVEL >= 2)
106 * depending on the desired verbosity.
107 *
108 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
109 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700110 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111
112 private static final boolean DBG =
113 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
114 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
115
116 // Message codes; see mHandler below.
117 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700120 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
121 private static final int EVENT_DATA_ROAMING_OK = 12;
122 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700123 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
124 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800125 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126
127 // The MMI codes are also used by the InCallScreen.
128 public static final int MMI_INITIATE = 51;
129 public static final int MMI_COMPLETE = 52;
130 public static final int MMI_CANCEL = 53;
131 // Don't use message codes larger than 99 here; those are reserved for
132 // the individual Activities of the Phone UI.
133
Santos Cordone18902f2016-03-22 17:16:04 -0700134 public static final int AIRPLANE_ON = 1;
135 public static final int AIRPLANE_OFF = 0;
136
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137 /**
138 * Allowable values for the wake lock code.
139 * SLEEP means the device can be put to sleep.
140 * PARTIAL means wake the processor, but we display can be kept off.
141 * FULL means wake both the processor and the display.
142 */
143 public enum WakeState {
144 SLEEP,
145 PARTIAL,
146 FULL
147 }
148
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149 private static PhoneGlobals sMe;
150
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700152 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700153 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800154 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700155 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800156 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000157 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000158 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800159 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700160
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530161 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700162
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 static boolean sVoiceCapable = true;
164
Santos Cordonc593d002015-06-03 15:41:15 -0700165 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166 CdmaPhoneCallState cdmaPhoneCallState;
167
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 // The currently-active PUK entry activity and progress dialog.
169 // Normally, these are the Emergency Dialer and the subsequent
170 // progress dialog. null if there is are no such objects in
171 // the foreground.
172 private Activity mPUKEntryActivity;
173 private ProgressDialog mPUKEntryProgressDialog;
174
Jordan Liuff2ccd72019-07-23 15:54:41 -0700175 /** @hide */
176 @Retention(RetentionPolicy.SOURCE)
177 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
178 value = {
179 ROAMING_NOTIFICATION_NO_NOTIFICATION,
180 ROAMING_NOTIFICATION_CONNECTED,
181 ROAMING_NOTIFICATION_DISCONNECTED})
182 public @interface RoamingNotification {}
183
184 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
185 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
186 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
187
188 @RoamingNotification
189 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700190
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private WakeState mWakeState = WakeState.SLEEP;
192
193 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private PowerManager.WakeLock mWakeLock;
195 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Jack Yu1a2fc352017-07-14 17:14:37 -0700198 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
199 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
200
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 // Broadcast receiver for various intent broadcasts (see onCreate())
202 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
203
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700204 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
205 new CarrierVvmPackageInstalledReceiver();
206
Jack Yu1a2fc352017-07-14 17:14:37 -0700207 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100208 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700209
Nazish Tabassum160d2112019-12-23 17:31:33 +0530210 private static class EventSimStateChangedBag {
211 final int mPhoneId;
212 final String mIccStatus;
213
214 EventSimStateChangedBag(int phoneId, String iccStatus) {
215 mPhoneId = phoneId;
216 mIccStatus = iccStatus;
217 }
218 }
219
Jordan Liu06bdef12021-03-24 17:25:46 -0700220 // Some carrier config settings disable the network lock screen, so we call handleSimLock
221 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
222 // we still do the right thing
223 private void handleSimLock(int subType, Phone phone) {
224 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
225 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
226 // If we only have the default carrier config just return, to avoid popping up the
227 // the SIM lock screen when it's disabled by the carrier.
228 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
229 return;
230 }
231 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
232 // Some products don't have the concept of a "SIM network lock"
233 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
234 return;
235 }
236
237 // if passed in subType is unknown, retrieve it here.
238 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000239 final UiccPort uiccPort = phone.getUiccPort();
240 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700241 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000242 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700243 return;
244 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000245 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700246 if (uiccProfile == null) {
247 Log.e(LOG_TAG,
248 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
249 return;
250 }
251 subType = uiccProfile.getApplication(
252 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
253 }
254 // Normal case: show the "SIM network unlock" PIN entry screen.
255 // The user won't be able to do anything else until
256 // they enter a valid SIM network PIN.
257 Log.i(LOG_TAG, "show sim depersonal panel");
258 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
259 }
260
261 private boolean isSimLocked(Phone phone) {
262 TelephonyManager tm = getSystemService(TelephonyManager.class);
263 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
264 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
265 }
266
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267 Handler mHandler = new Handler() {
268 @Override
269 public void handleMessage(Message msg) {
270 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700271 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 // TODO: This event should be handled by the lock screen, just
274 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
275 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700276 int subType = (Integer) ((AsyncResult) msg.obj).result;
277 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
278 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 break;
280
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700282 notificationMgr.showDataRoamingNotification(msg.arg1, false);
283 break;
284
285 case EVENT_DATA_ROAMING_CONNECTED:
286 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 break;
288
289 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700290 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 break;
292
293 case MMI_COMPLETE:
294 onMMIComplete((AsyncResult) msg.obj);
295 break;
296
297 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800298 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 break;
300
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301 case EVENT_SIM_STATE_CHANGED:
302 // Marks the event where the SIM goes into ready state.
303 // Right now, this is only used for the PUK-unlocking
304 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530305 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700306 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530307 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
308 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
309 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 // when the right event is triggered and there
311 // are UI objects in the foreground, we close
312 // them to display the lock panel.
313 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700314 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 mPUKEntryActivity.finish();
316 mPUKEntryActivity = null;
317 }
318 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700319 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 mPUKEntryProgressDialog.dismiss();
321 mPUKEntryProgressDialog = null;
322 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530323 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530324 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 }
326 break;
327
328 case EVENT_UNSOL_CDMA_INFO_RECORD:
329 //TODO: handle message here;
330 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700331 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
332 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
333 updateDataRoamingStatus();
334 break;
Lei Liu863eac02020-06-24 20:12:55 +0800335 case EVENT_CARRIER_CONFIG_CHANGED:
336 int subId = (Integer) msg.obj;
337 // The voicemail number could be overridden by carrier config, so need to
338 // refresh the message waiting (voicemail) indicator.
339 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700340 phone = getPhone(subId);
341 if (phone != null && isSimLocked(phone)) {
342 // pass in subType=-1 so handleSimLock can find the actual subType if
343 // needed. This is safe as valid values for subType are >= 0
344 handleSimLock(-1, phone);
345 }
Lei Liu863eac02020-06-24 20:12:55 +0800346 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 }
348 }
349 };
350
351 public PhoneGlobals(Context context) {
352 super(context);
353 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700354 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 }
356
357 public void onCreate() {
358 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
359
360 ContentResolver resolver = getContentResolver();
361
Hall Liuaa4211e2021-01-20 15:43:39 -0800362 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
363 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 // Cache the "voice capable" flag.
366 // This flag currently comes from a resource (which is
367 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800368 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
369 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 // ...but this might eventually become a PackageManager "system
371 // feature" instead, in which case we'd do something like:
372 // sVoiceCapable =
373 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
374
Stuart Scottdcf40a92014-12-09 10:45:01 -0800375 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800376 // Initialize AnomalyReporter early so that it can be used
377 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800378
Youming Ye47a6adc2018-11-19 15:33:36 -0800379 // Inject telephony component factory if configured using other jars.
380 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
381 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 // Initialize the telephony framework
383 PhoneFactory.makeDefaultPhones(this);
384
Brad Ebinger05f52c22019-12-05 13:03:21 -0800385 // Only bring up ImsResolver if the device supports having an IMS stack.
386 if (getPackageManager().hasSystemFeature(
387 PackageManager.FEATURE_TELEPHONY_IMS)) {
388 // Get the package name of the default IMS implementation.
389 String defaultImsMmtelPackage = getResources().getString(
390 R.string.config_ims_mmtel_package);
391 String defaultImsRcsPackage = getResources().getString(
392 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000393 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700394 defaultImsRcsPackage, PhoneFactory.getPhones().length,
395 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000396 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800397
398 // With the IMS phone created, load static config.xml values from the phone process
399 // so that it can be provided to the ImsPhoneCallTracker.
400 for (Phone p : PhoneFactory.getPhones()) {
401 Phone imsPhone = p.getImsPhone();
402 if (imsPhone != null && imsPhone instanceof ImsPhone) {
403 ImsPhone theImsPhone = (ImsPhone) imsPhone;
404 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
405 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
406 theImsPhone.getCallTracker();
407
408 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
409 config.isD2DCommunicationSupported = getResources().getBoolean(
410 R.bool.config_use_device_to_device_communication);
411 ict.setConfig(config);
412 }
413 }
414 }
Hui Wang068ab862020-10-31 05:12:53 +0000415 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800416 }
417
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 // Start TelephonyDebugService After the default phone is created.
419 Intent intent = new Intent(this, TelephonyDebugService.class);
420 startService(intent);
421
422 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
424 // Create the NotificationMgr singleton, which is used to display
425 // status bar icons and control other status bar behavior.
426 notificationMgr = NotificationMgr.init(this);
427
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700428 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
429 cdmaPhoneCallState = new CdmaPhoneCallState();
430 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 // before registering for phone state changes
433 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
434 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
435 // lock used to keep the processor awake, when we don't care for the display.
436 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
437 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438
439 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
440
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800441 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700442
James.cf Linaf3183c2019-10-24 00:59:00 +0800443 imsRcsController = ImsRcsController.init(this);
444
James.cf Linc9f35a42020-01-15 02:35:22 +0800445 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000446 mImsStateCallbackController =
447 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800448 mTelephonyRcsService = new TelephonyRcsService(this,
449 PhoneFactory.getPhones().length);
450 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800451 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000452 mImsProvisioningController =
453 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800454 }
455
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800456 configLoader = CarrierConfigLoader.init(this);
457
Jack Yu1a2fc352017-07-14 17:14:37 -0700458 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 // asynchronous events from the telephony layer (like
460 // launching the incoming-call UI when an incoming call comes
461 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800462 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463
Stuart Scottdcf40a92014-12-09 10:45:01 -0800464 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465
466 // register for MMI/USSD
467 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
468
Qiong Liucc3fe812019-09-23 15:25:44 +0800469 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900470 handleAirplaneModeChange(
471 Settings.Global.getInt(
472 getContentResolver(),
473 Settings.Global.AIRPLANE_MODE_ON,
474 AIRPLANE_OFF)
475 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800476
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 // Register for misc other intent broadcasts.
478 IntentFilter intentFilter =
479 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
481 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
482 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
483 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700484 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
485 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 registerReceiver(mReceiver, intentFilter);
487
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700488 mCarrierVvmPackageInstalledReceiver.register(this);
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 }
493
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 // XXX pre-load the SimProvider so that it's ready
495 resolver.getType(Uri.parse("content://icc/adn"));
496
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 // TODO: Register for Cdma Information Records
498 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
499
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 // Read HAC settings and configure audio hardware
501 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800502 int hac = android.provider.Settings.System.getInt(
503 getContentResolver(),
504 android.provider.Settings.System.HEARING_AID,
505 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700507 audioManager.setParameters(
508 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
509 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100511
512 // Start tracking Binder latency for the phone process.
513 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
514 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100515 new BinderCallsStats(
516 new BinderCallsStats.Injector(),
517 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * Returns the singleton instance of the PhoneApp.
522 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800523 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 if (sMe == null) {
525 throw new IllegalStateException("No PhoneGlobals here!");
526 }
527 return sMe;
528 }
529
530 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800531 * Returns the default phone.
532 *
Andrew Lee385019f2014-11-24 14:19:50 -0800533 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 */
Andrew Lee83383e42014-10-31 12:42:28 -0700535 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800536 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 }
538
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800539 public static Phone getPhone(int subId) {
540 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800541 }
542
Santos Cordonde10b752013-09-19 04:11:33 -0700543 /* package */ CallManager getCallManager() {
544 return mCM;
545 }
546
Chris Manton4e9fa912015-06-19 11:26:57 -0700547 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800548 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700549 }
550
Chris Manton4e9fa912015-06-19 11:26:57 -0700551 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800552 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
553 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700554 }
555
Jack Yu1a2fc352017-07-14 17:14:37 -0700556 private void registerSettingsObserver() {
557 mSettingsObserver.unobserve();
558 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
559 String mobileDataSetting = Settings.Global.MOBILE_DATA;
560 if (TelephonyManager.getDefault().getSimCount() > 1) {
561 int subId = mDefaultDataSubId;
562 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
563 dataRoamingSetting += subId;
564 mobileDataSetting += subId;
565 }
566 }
567
568 // Listen for user data roaming setting changed event
569 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
570 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
571
572 // Listen for mobile data setting changed event
573 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
574 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
575 }
576
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 * Sets the activity responsible for un-PUK-blocking the device
579 * so that we may close it when we receive a positive result.
580 * mPUKEntryActivity is also used to indicate to the device that
581 * we are trying to un-PUK-lock the phone. In other words, iff
582 * it is NOT null, then we are trying to unlock and waiting for
583 * the SIM to move to READY state.
584 *
585 * @param activity is the activity to close when PUK has
586 * finished unlocking. Can be set to null to indicate the unlock
587 * or SIM READYing process is over.
588 */
589 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700590 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 mPUKEntryActivity = activity;
592 }
593
594 Activity getPUKEntryActivity() {
595 return mPUKEntryActivity;
596 }
597
598 /**
599 * Sets the dialog responsible for notifying the user of un-PUK-
600 * blocking - SIM READYing progress, so that we may dismiss it
601 * when we receive a positive result.
602 *
603 * @param dialog indicates the progress dialog informing the user
604 * of the state of the device. Dismissed upon completion of
605 * READYing process
606 */
607 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700608 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
609 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610 mPUKEntryProgressDialog = dialog;
611 }
612
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 KeyguardManager getKeyguardManager() {
614 return mKeyguardManager;
615 }
616
617 private void onMMIComplete(AsyncResult r) {
618 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
619 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800620 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 }
622
fionaxu80126972017-02-01 17:01:26 -0800623 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 }
627
Taesu Lee62f826d2020-08-10 16:01:18 +0900628 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
629 int cellState =
630 Settings.Global.getInt(
631 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800632 switch (cellState) {
633 case PhoneConstants.CELL_OFF_FLAG:
634 // Airplane mode does not affect the cell radio if user
635 // has turned it off.
636 break;
637 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900638 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800639 break;
640 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900641 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800642 break;
643 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700644 for (Phone phone : PhoneFactory.getPhones()) {
645 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
646 }
Chris Mantona09f3632016-02-09 14:48:42 -0800647 }
648
649 /*
650 * Returns true if the radio must be turned off when entering airplane mode.
651 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900652 private boolean isCellOffInAirplaneMode() {
653 String airplaneModeRadios =
654 Settings.Global.getString(
655 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800656 return airplaneModeRadios == null
657 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
658 }
659
Taesu Lee62f826d2020-08-10 16:01:18 +0900660 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800661 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900662 Settings.Global.putInt(
663 getContentResolver(),
664 Settings.Global.CELL_ON,
665 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800666 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900667 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800668 PhoneUtils.setRadioPower(false);
669 }
670
Taesu Lee62f826d2020-08-10 16:01:18 +0900671 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800672 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900673 Settings.Global.putInt(
674 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
675 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700676 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800677 PhoneUtils.setRadioPower(true);
678 }
679
Taesu Lee62f826d2020-08-10 16:01:18 +0900680 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800681 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700682 // If we are trying to turn off the radio, make sure there are no active
683 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900684 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700685
686 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700687 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700688 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900689 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700690 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700691 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
692 .show();
693 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900694 } else if (isCellOffInAirplaneMode()) {
695 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700696 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800697 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700698 }
Chris Mantona09f3632016-02-09 14:48:42 -0800699 }
700 }
701
Taesu Lee62f826d2020-08-10 16:01:18 +0900702 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800703 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900704 setRadioPowerOn();
Santos Cordone18902f2016-03-22 17:16:04 -0700705 }
706 }
707
Santos Cordon593ab382013-08-06 21:58:23 -0700708 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709 * Receiver for misc intent broadcasts the Phone app cares about.
710 */
711 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
712 @Override
713 public void onReceive(Context context, Intent intent) {
714 String action = intent.getAction();
715 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900716 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900717 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700718 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
719 // re-register as it may be a new IccCard
720 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
721 SubscriptionManager.INVALID_PHONE_INDEX);
722 if (SubscriptionManager.isValidPhoneId(phoneId)) {
723 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
724 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
725 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530726 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
727 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
728 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700729 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
730 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800731 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
732 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
734 handleServiceStateChanged(intent);
735 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530736 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530737 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530738 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
739 if (phoneInEcm != null) {
740 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
741 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
742 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800743 if (intent.getBooleanExtra(
744 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530745 context.startService(new Intent(context,
746 EmergencyCallbackModeService.class));
747 } else {
748 phoneInEcm = null;
749 }
750 } else {
751 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
752 // on a device that doesn't support ECM in the first place.
753 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
754 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
755 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700756 }
757 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530758 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700759 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700760 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
761 // Roaming status could be overridden by carrier config, so we need to update it.
762 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
763 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700764 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800765 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
766 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
767 if (SubscriptionManager.isValidSubscriptionId(subId)) {
768 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
769 new Integer(subId)));
770 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700771 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
772 // We also need to pay attention when default data subscription changes.
773 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
774 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
775 registerSettingsObserver();
776 Phone phone = getPhone(mDefaultDataSubId);
777 if (phone != null) {
778 updateDataRoamingStatus();
779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 }
781 }
782 }
783
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 private void handleServiceStateChanged(Intent intent) {
785 /**
786 * This used to handle updating EriTextWidgetProvider this routine
787 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
788 * be removed. But leaving just in case it might be needed in the near
789 * future.
790 */
791
Jack Yu1a2fc352017-07-14 17:14:37 -0700792 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700794 Bundle extras = intent.getExtras();
795 if (extras != null) {
796 ServiceState ss = ServiceState.newFromBundle(extras);
797 if (ss != null) {
798 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700799 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
800 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
801 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700802
803 if (VDBG) {
804 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
805 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
806 }
807 if (subId == mDefaultDataSubId) {
808 updateDataRoamingStatus();
809 }
Santos Cordonc593d002015-06-03 15:41:15 -0700810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700811 }
812 }
813
Jack Yu1a2fc352017-07-14 17:14:37 -0700814 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700815 * @return whether or not we should show a notification when connecting to data roaming if the
816 * user has data roaming enabled
817 */
818 private boolean shouldShowDataConnectedRoaming(int subId) {
819 PersistableBundle config = getCarrierConfigForSubId(subId);
820 return config.getBoolean(CarrierConfigManager
821 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
822 }
823
824 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700825 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
826 * to notify the user so they can enable it through settings. Vise versa if the condition
827 * changes, we need to dismiss the notification.
828 */
829 private void updateDataRoamingStatus() {
830 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
831 Phone phone = getPhone(mDefaultDataSubId);
832 if (phone == null) {
833 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
834 return;
835 }
836
837 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800838 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700839 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
840 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700841 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
842 // No need to show it again if we never cancelled it explicitly.
843 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700844 // If the only reason of no data is data roaming disabled, then we notify the user
845 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700846 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700847 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700848 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700849 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
850 msg.arg1 = mDefaultDataSubId;
851 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700852 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
853 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
854 // No need to show it again if we never cancelled it explicitly, or carrier config
855 // indicates this is not needed.
856 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
857 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
858 Log.d(LOG_TAG, "Show roaming connected notification");
859 mDataRoamingNotifLog.log("Show roaming on.");
860 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
861 msg.arg1 = mDefaultDataSubId;
862 msg.sendToTarget();
863 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
864 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
865 // is not the only data disable reason. In this case we dismiss the notification we
866 // showed earlier.
867 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
868 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700869 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
870 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
871 }
872 }
873
Jordan Liuff2ccd72019-07-23 15:54:41 -0700874 /**
875 *
876 * @param subId to check roaming on
877 * @return whether we have transitioned to dataRoaming
878 */
879 private boolean dataIsNowRoaming(int subId) {
880 return getPhone(subId).getServiceState().getDataRoaming();
881 }
882
chen xubaf9fe52019-07-02 17:28:24 -0700883 private void updateLimitedSimFunctionForDualSim() {
884 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
885 // check conditions to display limited SIM function notification under dual SIM
886 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
887 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
888 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
889 if (subList != null && subList.size() > 1) {
890 CarrierConfigManager configMgr = (CarrierConfigManager)
891 getSystemService(Context.CARRIER_CONFIG_SERVICE);
892 for (SubscriptionInfo info : subList) {
893 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
894 if (b != null) {
895 if (b.getBoolean(CarrierConfigManager
896 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
897 notificationMgr.showLimitedSimFunctionWarningNotification(
898 info.getSubscriptionId(),
899 info.getDisplayName().toString());
900 } else {
901 notificationMgr.dismissLimitedSimFunctionWarningNotification(
902 info.getSubscriptionId());
903 }
904 }
905 }
906 } else {
907 // cancel notifications for all subs
908 notificationMgr.dismissLimitedSimFunctionWarningNotification(
909 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
910 }
911 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
912
913 }
914
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530915 public Phone getPhoneInEcm() {
916 return phoneInEcm;
917 }
918
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700919 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800920 * Triggers a refresh of the message waiting (voicemail) indicator.
921 *
922 * @param subId the subscription id we should refresh the notification for.
923 */
924 public void refreshMwiIndicator(int subId) {
925 notificationMgr.refreshMwi(subId);
926 }
927
928 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700929 * Called when the network selection on the subscription {@code subId} is changed by the user.
930 *
931 * @param subId the subscription id.
932 */
933 public void onNetworkSelectionChanged(int subId) {
934 Phone phone = getPhone(subId);
935 if (phone != null) {
936 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
937 } else {
938 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
939 }
940 }
941
942 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +0800943 * @return whether the device supports RCS User Capability Exchange or not.
944 */
945 public boolean getDeviceUceEnabled() {
946 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
947 }
948
949 /**
950 * Set the device supports RCS User Capability Exchange.
951 * @param isEnabled true if the device supports UCE.
952 */
953 public void setDeviceUceEnabled(boolean isEnabled) {
954 if (mTelephonyRcsService != null) {
955 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
956 }
957 }
958
959 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700960 * Dump the state of the object, add calls to other objects as desired.
961 *
962 * @param fd File descriptor
963 * @param printWriter Print writer
964 * @param args Arguments
965 */
966 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
967 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
968 pw.println("------- PhoneGlobals -------");
969 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700970 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700971 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
972 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700973 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700974 pw.increaseIndent();
975 mDataRoamingNotifLog.dump(fd, pw, args);
976 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -0800977 pw.println("ImsResolver:");
978 pw.increaseIndent();
979 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +0000980 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800981 } catch (Exception e) {
982 e.printStackTrace();
983 }
984 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -0800985 pw.println("RcsService:");
986 try {
987 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
988 } catch (Exception e) {
989 e.printStackTrace();
990 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +0000991 pw.println("ImsStateCallbackController:");
992 try {
993 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
994 } catch (Exception e) {
995 e.printStackTrace();
996 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700997 pw.decreaseIndent();
998 pw.println("------- End PhoneGlobals -------");
999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000}