blob: 426c473b705a8a2678d0cbcb4c6532c56a0f105e [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 Yu3e2ac6e2022-03-26 13:59:45 -070069import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Jack Yu1a2fc352017-07-14 17:14:37 -070070import com.android.internal.telephony.dataconnection.DataConnectionReasons;
71import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
Brad Ebinger05f52c22019-12-05 13:03:21 -080072import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080073import com.android.internal.telephony.imsphone.ImsPhone;
74import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000075import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070076import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070077import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080078import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070079import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080080import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
Jack Yu1a2fc352017-07-14 17:14:37 -070082import java.io.FileDescriptor;
83import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070084import java.lang.annotation.Retention;
85import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070086import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070087
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088/**
89 * Global state for the telephony subsystem when running in the primary
90 * phone process.
91 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070092public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070093 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094
95 /**
96 * Phone app-wide debug level:
97 * 0 - no debug logging
98 * 1 - normal debug logging if ro.debuggable is set (which is true in
99 * "eng" and "userdebug" builds but not "user" builds)
100 * 2 - ultra-verbose debug logging
101 *
102 * Most individual classes in the phone app have a local DBG constant,
103 * typically set to
104 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
105 * or else
106 * (PhoneApp.DBG_LEVEL >= 2)
107 * depending on the desired verbosity.
108 *
109 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
110 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700111 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112
113 private static final boolean DBG =
114 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
115 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
116
117 // Message codes; see mHandler below.
118 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700121 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
122 private static final int EVENT_DATA_ROAMING_OK = 12;
123 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700124 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
125 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800126 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127
128 // The MMI codes are also used by the InCallScreen.
129 public static final int MMI_INITIATE = 51;
130 public static final int MMI_COMPLETE = 52;
131 public static final int MMI_CANCEL = 53;
132 // Don't use message codes larger than 99 here; those are reserved for
133 // the individual Activities of the Phone UI.
134
Santos Cordone18902f2016-03-22 17:16:04 -0700135 public static final int AIRPLANE_ON = 1;
136 public static final int AIRPLANE_OFF = 0;
137
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 /**
139 * Allowable values for the wake lock code.
140 * SLEEP means the device can be put to sleep.
141 * PARTIAL means wake the processor, but we display can be kept off.
142 * FULL means wake both the processor and the display.
143 */
144 public enum WakeState {
145 SLEEP,
146 PARTIAL,
147 FULL
148 }
149
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 private static PhoneGlobals sMe;
151
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700153 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700154 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800155 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700156 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800157 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000158 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000159 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800160 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700161
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530162 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700163
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 static boolean sVoiceCapable = true;
165
Santos Cordonc593d002015-06-03 15:41:15 -0700166 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 CdmaPhoneCallState cdmaPhoneCallState;
168
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 // The currently-active PUK entry activity and progress dialog.
170 // Normally, these are the Emergency Dialer and the subsequent
171 // progress dialog. null if there is are no such objects in
172 // the foreground.
173 private Activity mPUKEntryActivity;
174 private ProgressDialog mPUKEntryProgressDialog;
175
Jordan Liuff2ccd72019-07-23 15:54:41 -0700176 /** @hide */
177 @Retention(RetentionPolicy.SOURCE)
178 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
179 value = {
180 ROAMING_NOTIFICATION_NO_NOTIFICATION,
181 ROAMING_NOTIFICATION_CONNECTED,
182 ROAMING_NOTIFICATION_DISCONNECTED})
183 public @interface RoamingNotification {}
184
185 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
186 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
187 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
188
189 @RoamingNotification
190 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private WakeState mWakeState = WakeState.SLEEP;
193
194 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 private PowerManager.WakeLock mWakeLock;
196 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
Jack Yu1a2fc352017-07-14 17:14:37 -0700199 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
200 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
201
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 // Broadcast receiver for various intent broadcasts (see onCreate())
203 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
204
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700205 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
206 new CarrierVvmPackageInstalledReceiver();
207
Jack Yu1a2fc352017-07-14 17:14:37 -0700208 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100209 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700210
Nazish Tabassum160d2112019-12-23 17:31:33 +0530211 private static class EventSimStateChangedBag {
212 final int mPhoneId;
213 final String mIccStatus;
214
215 EventSimStateChangedBag(int phoneId, String iccStatus) {
216 mPhoneId = phoneId;
217 mIccStatus = iccStatus;
218 }
219 }
220
Jordan Liu06bdef12021-03-24 17:25:46 -0700221 // Some carrier config settings disable the network lock screen, so we call handleSimLock
222 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
223 // we still do the right thing
224 private void handleSimLock(int subType, Phone phone) {
225 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
226 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
227 // If we only have the default carrier config just return, to avoid popping up the
228 // the SIM lock screen when it's disabled by the carrier.
229 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
230 return;
231 }
232 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
233 // Some products don't have the concept of a "SIM network lock"
234 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
235 return;
236 }
237
238 // if passed in subType is unknown, retrieve it here.
239 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000240 final UiccPort uiccPort = phone.getUiccPort();
241 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700242 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700244 return;
245 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000246 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700247 if (uiccProfile == null) {
248 Log.e(LOG_TAG,
249 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
250 return;
251 }
252 subType = uiccProfile.getApplication(
253 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
254 }
255 // Normal case: show the "SIM network unlock" PIN entry screen.
256 // The user won't be able to do anything else until
257 // they enter a valid SIM network PIN.
258 Log.i(LOG_TAG, "show sim depersonal panel");
259 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
260 }
261
262 private boolean isSimLocked(Phone phone) {
263 TelephonyManager tm = getSystemService(TelephonyManager.class);
264 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
265 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
266 }
267
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 Handler mHandler = new Handler() {
269 @Override
270 public void handleMessage(Message msg) {
271 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700272 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 // TODO: This event should be handled by the lock screen, just
275 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
276 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700277 int subType = (Integer) ((AsyncResult) msg.obj).result;
278 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
279 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 break;
281
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700283 notificationMgr.showDataRoamingNotification(msg.arg1, false);
284 break;
285
286 case EVENT_DATA_ROAMING_CONNECTED:
287 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 break;
289
290 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700291 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 break;
293
294 case MMI_COMPLETE:
295 onMMIComplete((AsyncResult) msg.obj);
296 break;
297
298 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800299 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 break;
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 case EVENT_SIM_STATE_CHANGED:
303 // Marks the event where the SIM goes into ready state.
304 // Right now, this is only used for the PUK-unlocking
305 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530306 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700307 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530308 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
309 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
310 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 // when the right event is triggered and there
312 // are UI objects in the foreground, we close
313 // them to display the lock panel.
314 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700315 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 mPUKEntryActivity.finish();
317 mPUKEntryActivity = null;
318 }
319 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700320 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 mPUKEntryProgressDialog.dismiss();
322 mPUKEntryProgressDialog = null;
323 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530324 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530325 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 }
327 break;
328
329 case EVENT_UNSOL_CDMA_INFO_RECORD:
330 //TODO: handle message here;
331 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700332 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
333 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
334 updateDataRoamingStatus();
335 break;
Lei Liu863eac02020-06-24 20:12:55 +0800336 case EVENT_CARRIER_CONFIG_CHANGED:
337 int subId = (Integer) msg.obj;
338 // The voicemail number could be overridden by carrier config, so need to
339 // refresh the message waiting (voicemail) indicator.
340 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700341 phone = getPhone(subId);
342 if (phone != null && isSimLocked(phone)) {
343 // pass in subType=-1 so handleSimLock can find the actual subType if
344 // needed. This is safe as valid values for subType are >= 0
345 handleSimLock(-1, phone);
346 }
Lei Liu863eac02020-06-24 20:12:55 +0800347 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 }
349 }
350 };
351
352 public PhoneGlobals(Context context) {
353 super(context);
354 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700355 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 }
357
358 public void onCreate() {
359 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
360
361 ContentResolver resolver = getContentResolver();
362
Hall Liuaa4211e2021-01-20 15:43:39 -0800363 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
364 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 // Cache the "voice capable" flag.
367 // This flag currently comes from a resource (which is
368 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800369 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
370 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 // ...but this might eventually become a PackageManager "system
372 // feature" instead, in which case we'd do something like:
373 // sVoiceCapable =
374 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
375
Stuart Scottdcf40a92014-12-09 10:45:01 -0800376 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800377 // Initialize AnomalyReporter early so that it can be used
378 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800379
Youming Ye47a6adc2018-11-19 15:33:36 -0800380 // Inject telephony component factory if configured using other jars.
381 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
382 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // Initialize the telephony framework
384 PhoneFactory.makeDefaultPhones(this);
385
Brad Ebinger05f52c22019-12-05 13:03:21 -0800386 // Only bring up ImsResolver if the device supports having an IMS stack.
387 if (getPackageManager().hasSystemFeature(
388 PackageManager.FEATURE_TELEPHONY_IMS)) {
389 // Get the package name of the default IMS implementation.
390 String defaultImsMmtelPackage = getResources().getString(
391 R.string.config_ims_mmtel_package);
392 String defaultImsRcsPackage = getResources().getString(
393 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000394 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700395 defaultImsRcsPackage, PhoneFactory.getPhones().length,
396 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000397 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800398
399 // With the IMS phone created, load static config.xml values from the phone process
400 // so that it can be provided to the ImsPhoneCallTracker.
401 for (Phone p : PhoneFactory.getPhones()) {
402 Phone imsPhone = p.getImsPhone();
403 if (imsPhone != null && imsPhone instanceof ImsPhone) {
404 ImsPhone theImsPhone = (ImsPhone) imsPhone;
405 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
406 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
407 theImsPhone.getCallTracker();
408
409 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
410 config.isD2DCommunicationSupported = getResources().getBoolean(
411 R.bool.config_use_device_to_device_communication);
412 ict.setConfig(config);
413 }
414 }
415 }
Hui Wang068ab862020-10-31 05:12:53 +0000416 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800417 }
418
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 // Start TelephonyDebugService After the default phone is created.
420 Intent intent = new Intent(this, TelephonyDebugService.class);
421 startService(intent);
422
423 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
425 // Create the NotificationMgr singleton, which is used to display
426 // status bar icons and control other status bar behavior.
427 notificationMgr = NotificationMgr.init(this);
428
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700429 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
430 cdmaPhoneCallState = new CdmaPhoneCallState();
431 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 // before registering for phone state changes
434 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
435 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
436 // lock used to keep the processor awake, when we don't care for the display.
437 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
438 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439
440 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
441
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800442 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700443
James.cf Linaf3183c2019-10-24 00:59:00 +0800444 imsRcsController = ImsRcsController.init(this);
445
James.cf Linc9f35a42020-01-15 02:35:22 +0800446 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000447 mImsStateCallbackController =
448 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800449 mTelephonyRcsService = new TelephonyRcsService(this,
450 PhoneFactory.getPhones().length);
451 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800452 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000453 mImsProvisioningController =
454 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800455 }
456
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800457 configLoader = CarrierConfigLoader.init(this);
458
Jack Yu1a2fc352017-07-14 17:14:37 -0700459 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 // asynchronous events from the telephony layer (like
461 // launching the incoming-call UI when an incoming call comes
462 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800463 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464
Stuart Scottdcf40a92014-12-09 10:45:01 -0800465 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466
467 // register for MMI/USSD
468 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
469
Qiong Liucc3fe812019-09-23 15:25:44 +0800470 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900471 handleAirplaneModeChange(
472 Settings.Global.getInt(
473 getContentResolver(),
474 Settings.Global.AIRPLANE_MODE_ON,
475 AIRPLANE_OFF)
476 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800477
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 // Register for misc other intent broadcasts.
479 IntentFilter intentFilter =
480 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
482 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
483 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
484 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700485 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
486 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 registerReceiver(mReceiver, intentFilter);
488
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700489 mCarrierVvmPackageInstalledReceiver.register(this);
490
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 }
494
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495 // XXX pre-load the SimProvider so that it's ready
496 resolver.getType(Uri.parse("content://icc/adn"));
497
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 // TODO: Register for Cdma Information Records
499 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
500
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 // Read HAC settings and configure audio hardware
502 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800503 int hac = android.provider.Settings.System.getInt(
504 getContentResolver(),
505 android.provider.Settings.System.HEARING_AID,
506 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700508 audioManager.setParameters(
509 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
510 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100512
513 // Start tracking Binder latency for the phone process.
514 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
515 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100516 new BinderCallsStats(
517 new BinderCallsStats.Injector(),
518 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * Returns the singleton instance of the PhoneApp.
523 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800524 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 if (sMe == null) {
526 throw new IllegalStateException("No PhoneGlobals here!");
527 }
528 return sMe;
529 }
530
531 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800532 * Returns the default phone.
533 *
Andrew Lee385019f2014-11-24 14:19:50 -0800534 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 */
Andrew Lee83383e42014-10-31 12:42:28 -0700536 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800537 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 }
539
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800540 public static Phone getPhone(int subId) {
541 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800542 }
543
Santos Cordonde10b752013-09-19 04:11:33 -0700544 /* package */ CallManager getCallManager() {
545 return mCM;
546 }
547
Chris Manton4e9fa912015-06-19 11:26:57 -0700548 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800549 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700550 }
551
Chris Manton4e9fa912015-06-19 11:26:57 -0700552 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800553 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
554 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700555 }
556
Jack Yu1a2fc352017-07-14 17:14:37 -0700557 private void registerSettingsObserver() {
558 mSettingsObserver.unobserve();
559 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
560 String mobileDataSetting = Settings.Global.MOBILE_DATA;
561 if (TelephonyManager.getDefault().getSimCount() > 1) {
562 int subId = mDefaultDataSubId;
563 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
564 dataRoamingSetting += subId;
565 mobileDataSetting += subId;
566 }
567 }
568
569 // Listen for user data roaming setting changed event
570 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
571 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
572
573 // Listen for mobile data setting changed event
574 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
575 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
576 }
577
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 * Sets the activity responsible for un-PUK-blocking the device
580 * so that we may close it when we receive a positive result.
581 * mPUKEntryActivity is also used to indicate to the device that
582 * we are trying to un-PUK-lock the phone. In other words, iff
583 * it is NOT null, then we are trying to unlock and waiting for
584 * the SIM to move to READY state.
585 *
586 * @param activity is the activity to close when PUK has
587 * finished unlocking. Can be set to null to indicate the unlock
588 * or SIM READYing process is over.
589 */
590 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700591 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 mPUKEntryActivity = activity;
593 }
594
595 Activity getPUKEntryActivity() {
596 return mPUKEntryActivity;
597 }
598
599 /**
600 * Sets the dialog responsible for notifying the user of un-PUK-
601 * blocking - SIM READYing progress, so that we may dismiss it
602 * when we receive a positive result.
603 *
604 * @param dialog indicates the progress dialog informing the user
605 * of the state of the device. Dismissed upon completion of
606 * READYing process
607 */
608 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700609 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
610 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 mPUKEntryProgressDialog = dialog;
612 }
613
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 KeyguardManager getKeyguardManager() {
615 return mKeyguardManager;
616 }
617
618 private void onMMIComplete(AsyncResult r) {
619 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
620 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800621 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 }
623
fionaxu80126972017-02-01 17:01:26 -0800624 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 }
628
Taesu Lee62f826d2020-08-10 16:01:18 +0900629 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
630 int cellState =
631 Settings.Global.getInt(
632 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800633 switch (cellState) {
634 case PhoneConstants.CELL_OFF_FLAG:
635 // Airplane mode does not affect the cell radio if user
636 // has turned it off.
637 break;
638 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900639 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800640 break;
641 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900642 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800643 break;
644 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700645 for (Phone phone : PhoneFactory.getPhones()) {
646 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
647 }
Chris Mantona09f3632016-02-09 14:48:42 -0800648 }
649
650 /*
651 * Returns true if the radio must be turned off when entering airplane mode.
652 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900653 private boolean isCellOffInAirplaneMode() {
654 String airplaneModeRadios =
655 Settings.Global.getString(
656 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800657 return airplaneModeRadios == null
658 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
659 }
660
Taesu Lee62f826d2020-08-10 16:01:18 +0900661 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800662 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900663 Settings.Global.putInt(
664 getContentResolver(),
665 Settings.Global.CELL_ON,
666 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800667 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900668 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800669 PhoneUtils.setRadioPower(false);
670 }
671
Taesu Lee62f826d2020-08-10 16:01:18 +0900672 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800673 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900674 Settings.Global.putInt(
675 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
676 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700677 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800678 PhoneUtils.setRadioPower(true);
679 }
680
Taesu Lee62f826d2020-08-10 16:01:18 +0900681 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800682 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700683 // If we are trying to turn off the radio, make sure there are no active
684 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900685 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700686
687 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700688 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700689 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900690 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700691 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700692 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
693 .show();
694 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900695 } else if (isCellOffInAirplaneMode()) {
696 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700697 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800698 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700699 }
Chris Mantona09f3632016-02-09 14:48:42 -0800700 }
701 }
702
Taesu Lee62f826d2020-08-10 16:01:18 +0900703 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800704 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900705 setRadioPowerOn();
Santos Cordone18902f2016-03-22 17:16:04 -0700706 }
707 }
708
Santos Cordon593ab382013-08-06 21:58:23 -0700709 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700710 * Receiver for misc intent broadcasts the Phone app cares about.
711 */
712 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
713 @Override
714 public void onReceive(Context context, Intent intent) {
715 String action = intent.getAction();
716 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900717 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900718 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700719 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
720 // re-register as it may be a new IccCard
721 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
722 SubscriptionManager.INVALID_PHONE_INDEX);
723 if (SubscriptionManager.isValidPhoneId(phoneId)) {
724 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
725 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
726 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530727 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
728 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
729 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700730 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
731 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800732 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
733 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
735 handleServiceStateChanged(intent);
736 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530737 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530738 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530739 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
740 if (phoneInEcm != null) {
741 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
742 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
743 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800744 if (intent.getBooleanExtra(
745 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530746 context.startService(new Intent(context,
747 EmergencyCallbackModeService.class));
748 } else {
749 phoneInEcm = null;
750 }
751 } else {
752 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
753 // on a device that doesn't support ECM in the first place.
754 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
755 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
756 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 }
758 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530759 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700761 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
762 // Roaming status could be overridden by carrier config, so we need to update it.
763 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
764 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700765 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800766 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
767 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
768 if (SubscriptionManager.isValidSubscriptionId(subId)) {
769 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
770 new Integer(subId)));
771 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700772 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
773 // We also need to pay attention when default data subscription changes.
774 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
775 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
776 registerSettingsObserver();
777 Phone phone = getPhone(mDefaultDataSubId);
778 if (phone != null) {
779 updateDataRoamingStatus();
780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 }
782 }
783 }
784
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785 private void handleServiceStateChanged(Intent intent) {
786 /**
787 * This used to handle updating EriTextWidgetProvider this routine
788 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
789 * be removed. But leaving just in case it might be needed in the near
790 * future.
791 */
792
Jack Yu1a2fc352017-07-14 17:14:37 -0700793 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700794 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700795 Bundle extras = intent.getExtras();
796 if (extras != null) {
797 ServiceState ss = ServiceState.newFromBundle(extras);
798 if (ss != null) {
799 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700800 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
801 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
802 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700803
804 if (VDBG) {
805 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
806 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
807 }
808 if (subId == mDefaultDataSubId) {
809 updateDataRoamingStatus();
810 }
Santos Cordonc593d002015-06-03 15:41:15 -0700811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 }
813 }
814
Jack Yu1a2fc352017-07-14 17:14:37 -0700815 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700816 * @return whether or not we should show a notification when connecting to data roaming if the
817 * user has data roaming enabled
818 */
819 private boolean shouldShowDataConnectedRoaming(int subId) {
820 PersistableBundle config = getCarrierConfigForSubId(subId);
821 return config.getBoolean(CarrierConfigManager
822 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
823 }
824
825 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700826 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
827 * to notify the user so they can enable it through settings. Vise versa if the condition
828 * changes, we need to dismiss the notification.
829 */
830 private void updateDataRoamingStatus() {
831 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
832 Phone phone = getPhone(mDefaultDataSubId);
833 if (phone == null) {
834 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
835 return;
836 }
837
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700838 boolean dataAllowed;
839 boolean notAllowedDueToRoamingOff;
840 if (phone.isUsingNewDataStack()) {
841 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
842 .getInternetDataDisallowedReasons();
843 dataAllowed = reasons.isEmpty();
844 notAllowedDueToRoamingOff = (reasons.size() == 1
845 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
846 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
847 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
848 } else {
849 DataConnectionReasons reasons = new DataConnectionReasons();
850 dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
851 notAllowedDueToRoamingOff = reasons.containsOnly(
852 DataDisallowedReasonType.ROAMING_DISABLED);
853 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
854 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
855 }
856
857 if (!dataAllowed && notAllowedDueToRoamingOff) {
Jordan Liuff2ccd72019-07-23 15:54:41 -0700858 // No need to show it again if we never cancelled it explicitly.
859 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700860 // If the only reason of no data is data roaming disabled, then we notify the user
861 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700862 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700863 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700864 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700865 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
866 msg.arg1 = mDefaultDataSubId;
867 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700868 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
869 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
870 // No need to show it again if we never cancelled it explicitly, or carrier config
871 // indicates this is not needed.
872 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
873 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
874 Log.d(LOG_TAG, "Show roaming connected notification");
875 mDataRoamingNotifLog.log("Show roaming on.");
876 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
877 msg.arg1 = mDefaultDataSubId;
878 msg.sendToTarget();
879 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
880 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
881 // is not the only data disable reason. In this case we dismiss the notification we
882 // showed earlier.
883 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
884 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700885 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
Jack Yu1a2fc352017-07-14 17:14:37 -0700886 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
887 }
888 }
889
Jordan Liuff2ccd72019-07-23 15:54:41 -0700890 /**
891 *
892 * @param subId to check roaming on
893 * @return whether we have transitioned to dataRoaming
894 */
895 private boolean dataIsNowRoaming(int subId) {
896 return getPhone(subId).getServiceState().getDataRoaming();
897 }
898
chen xubaf9fe52019-07-02 17:28:24 -0700899 private void updateLimitedSimFunctionForDualSim() {
900 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
901 // check conditions to display limited SIM function notification under dual SIM
902 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
903 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
904 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
905 if (subList != null && subList.size() > 1) {
906 CarrierConfigManager configMgr = (CarrierConfigManager)
907 getSystemService(Context.CARRIER_CONFIG_SERVICE);
908 for (SubscriptionInfo info : subList) {
909 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
910 if (b != null) {
911 if (b.getBoolean(CarrierConfigManager
912 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
913 notificationMgr.showLimitedSimFunctionWarningNotification(
914 info.getSubscriptionId(),
915 info.getDisplayName().toString());
916 } else {
917 notificationMgr.dismissLimitedSimFunctionWarningNotification(
918 info.getSubscriptionId());
919 }
920 }
921 }
922 } else {
923 // cancel notifications for all subs
924 notificationMgr.dismissLimitedSimFunctionWarningNotification(
925 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
926 }
927 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
928
929 }
930
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530931 public Phone getPhoneInEcm() {
932 return phoneInEcm;
933 }
934
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800936 * Triggers a refresh of the message waiting (voicemail) indicator.
937 *
938 * @param subId the subscription id we should refresh the notification for.
939 */
940 public void refreshMwiIndicator(int subId) {
941 notificationMgr.refreshMwi(subId);
942 }
943
944 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700945 * Called when the network selection on the subscription {@code subId} is changed by the user.
946 *
947 * @param subId the subscription id.
948 */
949 public void onNetworkSelectionChanged(int subId) {
950 Phone phone = getPhone(subId);
951 if (phone != null) {
952 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
953 } else {
954 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
955 }
956 }
957
958 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +0800959 * @return whether the device supports RCS User Capability Exchange or not.
960 */
961 public boolean getDeviceUceEnabled() {
962 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
963 }
964
965 /**
966 * Set the device supports RCS User Capability Exchange.
967 * @param isEnabled true if the device supports UCE.
968 */
969 public void setDeviceUceEnabled(boolean isEnabled) {
970 if (mTelephonyRcsService != null) {
971 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
972 }
973 }
974
975 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700976 * Dump the state of the object, add calls to other objects as desired.
977 *
978 * @param fd File descriptor
979 * @param printWriter Print writer
980 * @param args Arguments
981 */
982 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
983 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
984 pw.println("------- PhoneGlobals -------");
985 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700986 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700987 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
988 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700989 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700990 pw.increaseIndent();
991 mDataRoamingNotifLog.dump(fd, pw, args);
992 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -0800993 pw.println("ImsResolver:");
994 pw.increaseIndent();
995 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +0000996 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800997 } catch (Exception e) {
998 e.printStackTrace();
999 }
1000 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001001 pw.println("RcsService:");
1002 try {
1003 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1004 } catch (Exception e) {
1005 e.printStackTrace();
1006 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001007 pw.println("ImsStateCallbackController:");
1008 try {
1009 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1010 } catch (Exception e) {
1011 e.printStackTrace();
1012 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001013 pw.decreaseIndent();
1014 pw.println("------- End PhoneGlobals -------");
1015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016}