blob: eec50efba200c8cde0c3fbf521def569b669c79a [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
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Shuo Qiandee53402020-05-29 14:08:15 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800764 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
Shuo Qian4a594052020-01-23 11:59:30 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 if (callForwardResults.length > 1
925 && ((callForwardResults[1]
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
927 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800928 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
929 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
930 } else {
931 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
932 }
933 } else {
934 if (ar.result == null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
936 }
937 if (ar.exception != null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
939 }
940 if (ar.exception instanceof CommandException) {
941 CommandException.Error error =
942 ((CommandException) (ar.exception)).getCommandError();
943 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
944 callForwardingStatus =
945 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
946 }
947 }
948 }
949 request.result = callForwardingStatus;
950 notifyRequester(request);
951 break;
952
953 case CMD_SET_CALL_WAITING:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
956 boolean isEnable = (Boolean) request.argument;
957 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
958 break;
959
960 case EVENT_SET_CALL_WAITING_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null) {
964 request.result = true;
965 } else {
966 request.result = false;
967 loge("setCallWaiting exception: " + ar.exception);
968 }
969 notifyRequester(request);
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case EVENT_PERFORM_NETWORK_SCAN_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 CellNetworkScanResult cellScanResult;
976 if (ar.exception == null && ar.result != null) {
977 cellScanResult = new CellNetworkScanResult(
978 CellNetworkScanResult.STATUS_SUCCESS,
979 (List<OperatorInfo>) ar.result);
980 } else {
981 if (ar.result == null) {
982 loge("getCellNetworkScanResults: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("getCellNetworkScanResults: Exception: " + ar.exception);
986 }
987 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.GENERIC_FAILURE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
995 }
996 }
997 cellScanResult = new CellNetworkScanResult(errorCode, null);
998 }
999 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1004 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 ManualNetworkSelectionArgument selArg =
1006 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1008 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1010 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 break;
1012
1013 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 loge("setNetworkSelectionModeManual " + ar.exception);
1021 }
1022 notifyRequester(request);
1023 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001024 break;
1025
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 case CMD_GET_MODEM_ACTIVITY_INFO:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001029 if (defaultPhone != null) {
1030 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian1d931ee2020-02-20 17:12:10 -08001031 } else {
1032 ResultReceiver result = (ResultReceiver) request.argument;
1033 Bundle bundle = new Bundle();
1034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1035 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1036 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001037 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 break;
1039
1040 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Shuo Qian1d931ee2020-02-20 17:12:10 -08001043 ResultReceiver result = (ResultReceiver) request.argument;
1044
1045 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001046 if (ar.exception == null && ar.result != null) {
Shuo Qian1d931ee2020-02-20 17:12:10 -08001047 // Update the last modem activity info and the result of the request.
1048 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1049 if (isModemActivityInfoValid(info)) {
1050 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1051 int[] txTimeMs = info.getTransmitTimeMillis();
1052 int[] lastModemTxTimeMs = mLastModemActivityInfo
1053 .getTransmitTimeMillis();
1054 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1055 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1056 }
1057 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1058 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1059 + mLastModemActivityInfo.getSleepTimeMillis());
1060 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1061 + mLastModemActivityInfo.getIdleTimeMillis());
1062 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1063 mLastModemActivityInfo.setReceiveTimeMillis(
1064 info.getReceiveTimeMillis()
1065 + mLastModemActivityInfo.getReceiveTimeMillis());
1066 }
1067 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1068 mLastModemActivityInfo.getSleepTimeMillis(),
1069 mLastModemActivityInfo.getIdleTimeMillis(),
1070 mLastModemActivityInfo.getTransmitTimeMillis(),
1071 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001072 } else {
1073 if (ar.result == null) {
1074 loge("queryModemActivityInfo: Empty response");
1075 } else if (ar.exception instanceof CommandException) {
1076 loge("queryModemActivityInfo: CommandException: " +
1077 ar.exception);
1078 } else {
1079 loge("queryModemActivityInfo: Unknown exception");
1080 }
1081 }
Shuo Qian1d931ee2020-02-20 17:12:10 -08001082 Bundle bundle = new Bundle();
1083 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1084 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 case CMD_SET_ALLOWED_CARRIERS:
1089 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001090 CarrierRestrictionRules argument =
1091 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001093 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 break;
1095
1096 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result;
1101 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001102 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 loge("setAllowedCarriers: CommandException: " + ar.exception);
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result =
1109 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 } else {
1112 loge("setAllowedCarriers: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case CMD_GET_ALLOWED_CARRIERS:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001121 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001122 break;
1123
1124 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null && ar.result != null) {
1128 request.result = ar.result;
1129 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001130 request.result = new IllegalStateException(
1131 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 if (ar.result == null) {
1133 loge("getAllowedCarriers: Empty response");
1134 } else if (ar.exception instanceof CommandException) {
1135 loge("getAllowedCarriers: CommandException: " +
1136 ar.exception);
1137 } else {
1138 loge("getAllowedCarriers: Unknown exception");
1139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
Nathan Haroldb3014052017-01-25 15:57:32 -08001144 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
1150 request.result = new IllegalArgumentException(
1151 "Failed to retrieve Forbidden Plmns");
1152 if (ar.result == null) {
1153 loge("getForbiddenPlmns: Empty response");
1154 } else {
1155 loge("getForbiddenPlmns: Unknown exception");
1156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001159 break;
1160
1161 case CMD_GET_FORBIDDEN_PLMNS:
1162 request = (MainThreadRequest) msg.obj;
1163 uiccCard = getUiccCardFromRequest(request);
1164 if (uiccCard == null) {
1165 loge("getForbiddenPlmns() UiccCard is null");
1166 request.result = new IllegalArgumentException(
1167 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001169 break;
1170 }
1171 Integer appType = (Integer) request.argument;
1172 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1173 if (uiccApp == null) {
1174 loge("getForbiddenPlmns() no app with specified type -- "
1175 + appType);
1176 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001178 break;
1179 } else {
1180 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1181 + " specified type -- " + appType);
1182 }
1183 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1184 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1185 onCompleted);
1186 break;
1187
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 case CMD_SWITCH_SLOTS:
1189 request = (MainThreadRequest) msg.obj;
1190 int[] physicalSlots = (int[]) request.argument;
1191 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1192 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1193 break;
1194
1195 case EVENT_SWITCH_SLOTS_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
1200 break;
1201 case CMD_GET_NETWORK_SELECTION_MODE:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1204 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1205 break;
1206
1207 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception != null) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1212 } else {
1213 int mode = ((int[]) ar.result)[0];
1214 if (mode == 0) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1216 } else {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 notifyRequester(request);
1221 break;
1222 case CMD_GET_CDMA_ROAMING_MODE:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1225 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1226 break;
1227 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception != null) {
1231 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1232 } else {
1233 request.result = ((int[]) ar.result)[0];
1234 }
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_ROAMING_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1240 int mode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
1248 break;
1249 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1252 int subscriptionMode = (int) request.argument;
1253 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1254 break;
1255 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 request.result = ar.exception == null;
1259 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001260 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 case CMD_GET_ALL_CELL_INFO:
1262 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001264 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 case EVENT_GET_ALL_CELL_INFO_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001269 // If a timeout occurs, the response will be null
1270 request.result = (ar.exception == null && ar.result != null)
1271 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 synchronized (request) {
1273 request.notifyAll();
1274 }
1275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case CMD_REQUEST_CELL_INFO_UPDATE:
1277 request = (MainThreadRequest) msg.obj;
1278 request.phone.requestCellInfoUpdate(request.workSource,
1279 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1280 break;
1281 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1285 try {
1286 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001288 cb.onError(
1289 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1290 ar.exception.getClass().getName(),
1291 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001294 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else {
1296 // use the result as returned
1297 cb.onCellInfo((List<CellInfo>) ar.result);
1298 }
1299 } catch (RemoteException re) {
1300 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1301 }
1302 break;
1303 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request = (MainThreadRequest) msg.obj;
1305 WorkSource ws = (WorkSource) request.argument;
1306 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001307 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = ar.result;
1314 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001315 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001317 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 }
1319
1320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001324 case CMD_MODEM_REBOOT:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001328 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001329 case EVENT_CMD_MODEM_REBOOT_DONE:
1330 handleNullReturnEvent(msg, "rebootModem");
1331 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001332 case CMD_REQUEST_ENABLE_MODEM:
1333 request = (MainThreadRequest) msg.obj;
1334 boolean enable = (boolean) request.argument;
1335 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001336 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 PhoneConfigurationManager.getInstance()
1338 .enablePhone(request.phone, enable, onCompleted);
1339 break;
1340 case EVENT_ENABLE_MODEM_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001344 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001345 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 if ((boolean) request.result) {
1347 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1348 updateModemStateMetrics();
1349 } else {
1350 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1351 + ar.exception);
1352 }
1353 notifyRequester(request);
1354 break;
1355 case CMD_GET_MODEM_STATUS:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1358 PhoneConfigurationManager.getInstance()
1359 .getPhoneStatusFromModem(request.phone, onCompleted);
1360 break;
1361 case EVENT_GET_MODEM_STATUS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 int id = request.phone.getPhoneId();
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 //update the cache as modem status has changed
1368 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1369 (boolean) request.result);
1370 } else {
1371 // Return true if modem status cannot be retrieved. For most cases,
1372 // modem status is on. And for older version modems, GET_MODEM_STATUS
1373 // and disable modem are not supported. Modem is always on.
1374 // TODO: this should be fixed in R to support a third
1375 // status UNKNOWN b/131631629
1376 request.result = true;
1377 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1378 + ar.exception);
1379 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 notifyRequester(request);
1381 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001382 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1388 break;
1389 }
1390 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1394 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1395 args.second.accept(ar.exception == null);
1396 notifyRequester(request);
1397 break;
1398 }
yincheng zhao2737e882019-09-06 17:06:54 -07001399 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
1405 request.result = -1;
1406 loge("Failed to set Forbidden Plmns");
1407 if (ar.result == null) {
1408 loge("setForbidenPlmns: Empty response");
1409 } else if (ar.exception != null) {
1410 loge("setForbiddenPlmns: Exception: " + ar.exception);
1411 request.result = -1;
1412 } else {
1413 loge("setForbiddenPlmns: Unknown exception");
1414 }
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_FORBIDDEN_PLMNS:
1419 request = (MainThreadRequest) msg.obj;
1420 uiccCard = getUiccCardFromRequest(request);
1421 if (uiccCard == null) {
1422 loge("setForbiddenPlmns: UiccCard is null");
1423 request.result = -1;
1424 notifyRequester(request);
1425 break;
1426 }
1427 Pair<Integer, List<String>> setFplmnsArgs =
1428 (Pair<Integer, List<String>>) request.argument;
1429 appType = setFplmnsArgs.first;
1430 List<String> fplmns = setFplmnsArgs.second;
1431 uiccApp = uiccCard.getApplicationByType(appType);
1432 if (uiccApp == null) {
1433 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1434 request.result = -1;
1435 loge("Failed to get UICC App");
1436 notifyRequester(request);
1437 } else {
1438 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1439 ((SIMRecords) uiccApp.getIccRecords())
1440 .setForbiddenPlmns(onCompleted, fplmns);
1441 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001442 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001443 case CMD_ERASE_MODEM_CONFIG:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1446 defaultPhone.eraseModemConfig(onCompleted);
1447 break;
1448 case EVENT_ERASE_MODEM_CONFIG_DONE:
1449 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001450 break;
zoey chene02881a2019-12-30 16:11:23 +08001451
1452 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1455 Pair<String, String> changed = (Pair<String, String>) request.argument;
1456 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1457 changed.first, changed.second, onCompleted);
1458 break;
1459 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1464 } else {
1465 request.result = msg.arg1;
1466 }
1467 notifyRequester(request);
1468 break;
1469
1470 case CMD_SET_ICC_LOCK_ENABLED:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1473 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1474 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1475 enabled.first, enabled.second, onCompleted);
1476 break;
1477 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1482 } else {
1483 request.result = msg.arg1;
1484 }
1485 notifyRequester(request);
1486 break;
1487
Peter Wangdafb9ac2020-01-15 14:13:38 -08001488 case MSG_NOTIFY_USER_ACTIVITY:
1489 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001490 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1492 getDefaultPhone().getContext().sendBroadcastAsUser(
1493 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1494 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 default:
1496 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1497 break;
1498 }
1499 }
Jake Hambye994d462014-02-03 13:10:13 -08001500
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 private void notifyRequester(MainThreadRequest request) {
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 }
1506
Jake Hambye994d462014-02-03 13:10:13 -08001507 private void handleNullReturnEvent(Message msg, String command) {
1508 AsyncResult ar = (AsyncResult) msg.obj;
1509 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = true;
1512 } else {
1513 request.result = false;
1514 if (ar.exception instanceof CommandException) {
1515 loge(command + ": CommandException: " + ar.exception);
1516 } else {
1517 loge(command + ": Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001530 return sendRequest(
1531 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
1539 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1540 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001541 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 /**
1545 * Posts the specified command to be executed on the main thread,
1546 * waits for the request to complete, and returns the result.
1547 * @see #sendRequestAsync
1548 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001549 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001550 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001551 }
1552
1553 /**
1554 * Posts the specified command to be executed on the main thread,
1555 * waits for the request to complete, and returns the result.
1556 * @see #sendRequestAsync
1557 */
Nathan Harold92bed182018-10-12 18:16:49 -07001558 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1559 return sendRequest(command, argument, subId, null, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1568 return sendRequest(
1569 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(
1578 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1580 throw new RuntimeException("This method will deadlock if called from the main thread.");
1581 }
1582
Nathan Harold92bed182018-10-12 18:16:49 -07001583 MainThreadRequest request = null;
1584 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1585 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1586 } else if (phone != null) {
1587 request = new MainThreadRequest(argument, phone, workSource);
1588 } else {
1589 request = new MainThreadRequest(argument, subId, workSource);
1590 }
1591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 Message msg = mMainThreadHandler.obtainMessage(command, request);
1593 msg.sendToTarget();
1594
1595 // Wait for the request to complete
1596 synchronized (request) {
1597 while (request.result == null) {
1598 try {
1599 request.wait();
1600 } catch (InterruptedException e) {
1601 // Do nothing, go back and wait until the request is complete
1602 }
1603 }
1604 }
1605 return request.result;
1606 }
1607
1608 /**
1609 * Asynchronous ("fire and forget") version of sendRequest():
1610 * Posts the specified command to be executed on the main thread, and
1611 * returns immediately.
1612 * @see #sendRequest
1613 */
1614 private void sendRequestAsync(int command) {
1615 mMainThreadHandler.sendEmptyMessage(command);
1616 }
1617
1618 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001620 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 */
1622 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 sendRequestAsync(command, argument, null, null);
1624 }
1625
1626 /**
1627 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1628 * @see {@link #sendRequest(int,Object)}
1629 */
1630 private void sendRequestAsync(
1631 int command, Object argument, Phone phone, WorkSource workSource) {
1632 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001633 Message msg = mMainThreadHandler.obtainMessage(command, request);
1634 msg.sendToTarget();
1635 }
1636
1637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 * Initialize the singleton PhoneInterfaceManager instance.
1639 * This is only done once, at startup, from PhoneApp.onCreate().
1640 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001641 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 synchronized (PhoneInterfaceManager.class) {
1643 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } else {
1646 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1647 }
1648 return sInstance;
1649 }
1650 }
1651
1652 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001653 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001656 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001657 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1659 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001660 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001661 mTelephonySharedPreferences =
1662 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001663 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001664 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001665 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 publish();
1668 }
1669
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001670 private Phone getDefaultPhone() {
1671 Phone thePhone = getPhone(getDefaultSubscription());
1672 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 private void publish() {
1676 if (DBG) log("publish: " + this);
1677
Peter Wangc035ce42020-01-08 21:00:22 -08001678 TelephonyFrameworkInitializer
1679 .getTelephonyServiceManager()
1680 .getTelephonyServiceRegisterer()
1681 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
Stuart Scott584921c2015-01-15 17:10:34 -08001684 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001685 if (request.phone != null) {
1686 return request.phone;
1687 } else {
1688 return getPhoneFromSubId(request.subId);
1689 }
1690 }
1691
1692 private Phone getPhoneFromSubId(int subId) {
1693 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1694 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001695 }
1696
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001697 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1698 Phone phone = getPhoneFromRequest(request);
1699 return phone == null ? null :
1700 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001705 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Naina Nallurid63128d2019-09-17 14:10:30 -07001708 private void sendEraseModemConfig(Phone phone) {
1709 if (phone != null) {
1710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1711 mApp, phone.getSubId(), "eraseModemConfig");
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1715 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
1718 }
1719 }
1720 }
1721
Peter Wang44b186e2020-01-13 23:33:09 -08001722 private boolean isImsAvailableOnDevice() {
1723 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1724 if (pm == null) {
1725 // For some reason package manger is not available.. This will fail internally anyway,
1726 // so do not throw error and allow.
1727 return true;
1728 }
1729 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 if (DBG) log("dial: " + number);
1738 // No permission check needed here: This is just a wrapper around the
1739 // ACTION_DIAL intent, which is available to any app since it puts up
1740 // the UI before it does anything.
1741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 String url = createTelUrl(number);
1745 if (url == null) {
1746 return;
1747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 // PENDING: should we just silently fail if phone is offhook or ringing?
1750 PhoneConstants.State state = mCM.getState(subId);
1751 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1752 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1754 mApp.startActivity(intent);
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759 }
1760
1761 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 if (DBG) log("call: " + number);
1767
1768 // This is just a wrapper around the ACTION_CALL intent, but we still
1769 // need to do a permission check since we're calling startActivity()
1770 // from the context of the phone app.
1771 enforceCallPermission();
1772
Jordan Liu1617b712019-07-10 15:06:26 -07001773 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 != AppOpsManager.MODE_ALLOWED) {
1775 return;
1776 }
1777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 String url = createTelUrl(number);
1781 if (url == null) {
1782 return;
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 boolean isValid = false;
1786 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1787 if (slist != null) {
1788 for (SubscriptionInfo subInfoRecord : slist) {
1789 if (subInfoRecord.getSubscriptionId() == subId) {
1790 isValid = true;
1791 break;
1792 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001793 }
Wink Saville08874612014-08-31 19:19:58 -07001794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 if (!isValid) {
1796 return;
1797 }
Wink Saville08874612014-08-31 19:19:58 -07001798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1800 intent.putExtra(SUBSCRIPTION_KEY, subId);
1801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1802 mApp.startActivity(intent);
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
1805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807
Wink Savilleb564aae2014-10-23 10:18:09 -07001808 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001809 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001810 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001815 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1816 }
1817
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820
1821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1824 checkSimPin.start();
1825 return checkSimPin.unlockSim(null, pin);
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Wink Savilleb564aae2014-10-23 10:18:09 -07001831 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1837 checkSimPuk.start();
1838 return checkSimPuk.unlockSim(puk, pin);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
1844 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001845 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 * a synchronous one.
1847 */
1848 private static class UnlockSim extends Thread {
1849
1850 private final IccCard mSimCard;
1851
1852 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001853 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1854 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855
1856 // For replies from SimCard interface
1857 private Handler mHandler;
1858
1859 // For async handler to identify request type
1860 private static final int SUPPLY_PIN_COMPLETE = 100;
1861
1862 public UnlockSim(IccCard simCard) {
1863 mSimCard = simCard;
1864 }
1865
1866 @Override
1867 public void run() {
1868 Looper.prepare();
1869 synchronized (UnlockSim.this) {
1870 mHandler = new Handler() {
1871 @Override
1872 public void handleMessage(Message msg) {
1873 AsyncResult ar = (AsyncResult) msg.obj;
1874 switch (msg.what) {
1875 case SUPPLY_PIN_COMPLETE:
1876 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1877 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001878 mRetryCount = msg.arg1;
1879 if (ar.exception != null) {
1880 if (ar.exception instanceof CommandException &&
1881 ((CommandException)(ar.exception)).getCommandError()
1882 == CommandException.Error.PASSWORD_INCORRECT) {
1883 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1884 } else {
1885 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1886 }
1887 } else {
1888 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 mDone = true;
1891 UnlockSim.this.notifyAll();
1892 }
1893 break;
1894 }
1895 }
1896 };
1897 UnlockSim.this.notifyAll();
1898 }
1899 Looper.loop();
1900 }
1901
1902 /*
1903 * Use PIN or PUK to unlock SIM card
1904 *
1905 * If PUK is null, unlock SIM card with PIN
1906 *
1907 * If PUK is not null, unlock SIM card with PUK and set PIN code
1908 */
Wink Saville9de0f752013-10-22 19:04:03 -07001909 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910
1911 while (mHandler == null) {
1912 try {
1913 wait();
1914 } catch (InterruptedException e) {
1915 Thread.currentThread().interrupt();
1916 }
1917 }
1918 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1919
1920 if (puk == null) {
1921 mSimCard.supplyPin(pin, callback);
1922 } else {
1923 mSimCard.supplyPuk(puk, pin, callback);
1924 }
1925
1926 while (!mDone) {
1927 try {
1928 Log.d(LOG_TAG, "wait for done");
1929 wait();
1930 } catch (InterruptedException e) {
1931 // Restore the interrupted status
1932 Thread.currentThread().interrupt();
1933 }
1934 }
1935 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001936 int[] resultArray = new int[2];
1937 resultArray[0] = mResult;
1938 resultArray[1] = mRetryCount;
1939 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941 }
1942
1943 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001944 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001945
1946 }
1947
Wink Savilleb564aae2014-10-23 10:18:09 -07001948 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 // No permission check needed here: this call is harmless, and it's
1950 // needed for the ServiceState.requestStateUpdate() call (which is
1951 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001952 final long identity = Binder.clearCallingIdentity();
1953 try {
1954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 phone.updateServiceLocation();
1957 }
1958 } finally {
1959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001963 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 @Override
1965 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001966 return isRadioOnWithFeature(callingPackage, null);
1967 }
1968
1969
1970 @Override
1971 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1972 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1973 callingFeatureId);
1974 }
1975
1976 @Deprecated
1977 @Override
1978 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1979 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001980 }
1981
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001983 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1984 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001986 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001987 return false;
1988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989
1990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 return isRadioOnForSubscriber(subId);
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
1995 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001996 }
1997
1998 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 final long identity = Binder.clearCallingIdentity();
2000 try {
2001 final Phone phone = getPhone(subId);
2002 if (phone != null) {
2003 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2004 } else {
2005 return false;
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002013 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
Wink Saville36469e72014-06-11 15:17:00 -07002015
Wink Savilleb564aae2014-10-23 10:18:09 -07002016 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2024 }
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 }
Wink Saville36469e72014-06-11 15:17:00 -07002028 }
2029
2030 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002031 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002032 }
2033
Wink Savilleb564aae2014-10-23 10:18:09 -07002034 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 final Phone phone = getPhone(subId);
2040 if (phone == null) {
2041 return false;
2042 }
2043 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2044 toggleRadioOnOffForSubscriber(subId);
2045 }
2046 return true;
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 }
Wink Saville36469e72014-06-11 15:17:00 -07002051
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002052 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002053 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 /*
2055 * If any of the Radios are available, it will need to be
2056 * shutdown. So return true if any Radio is available.
2057 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2061 Phone phone = PhoneFactory.getPhone(i);
2062 if (phone != null && phone.isRadioAvailable()) return true;
2063 }
2064 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2065 return false;
2066 } finally {
2067 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
2070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002072 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073 enforceModifyPermission();
2074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2078 logv("Shutting down Phone " + i);
2079 shutdownRadioUsingPhoneId(i);
2080 }
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002083 }
2084 }
2085
2086 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002087 Phone phone = PhoneFactory.getPhone(phoneId);
2088 if (phone != null && phone.isRadioAvailable()) {
2089 phone.shutdownRadio();
2090 }
2091 }
2092
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002094 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095
2096 final long identity = Binder.clearCallingIdentity();
2097 try {
2098 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2099 if (defaultPhone != null) {
2100 defaultPhone.setRadioPower(turnOn);
2101 return true;
2102 } else {
2103 loge("There's no default phone.");
2104 return false;
2105 }
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002108 }
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
Wink Savilleb564aae2014-10-23 10:18:09 -07002111 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 phone.setRadioPower(turnOn);
2119 return true;
2120 } else {
2121 return false;
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Wink Saville36469e72014-06-11 15:17:00 -07002128 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002129 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 public boolean enableDataConnectivity() {
2131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 int subId = mSubscriptionController.getDefaultDataSubId();
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002138 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 return true;
2140 } else {
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public boolean disableDataConnectivity() {
2151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 int subId = mSubscriptionController.getDefaultDataSubId();
2156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002158 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 return true;
2160 } else {
2161 return false;
2162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002169 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002174 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175 } else {
2176 return false;
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002184 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
pkanwarae03a6b2016-11-06 20:37:09 -08002187 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 enforceCallPermission();
2189
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2193 return;
2194 }
2195 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2196 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
2199 }
pkanwar32d516d2016-10-14 19:37:38 -07002200 };
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2208 return false;
2209 }
2210 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002217 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002220 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 Phone phone = PhoneFactory.getPhone(slotIndex);
2224 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2225 PhoneConstantConversions.convertCallState(phone.getState());
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002232 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002233 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2234 }
2235
2236 @Override
2237 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002240 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 if (phone != null) {
2242 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2243 } else {
2244 return PhoneConstantConversions.convertDataState(
2245 PhoneConstants.DataState.DISCONNECTED);
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002253 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002254 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2255 }
2256
2257 @Override
2258 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002261 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 if (phone != null) {
2263 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2264 } else {
2265 return TelephonyManager.DATA_ACTIVITY_NONE;
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002273 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002274 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002275 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002276
2277 LocationAccessPolicy.LocationPermissionResult locationResult =
2278 LocationAccessPolicy.checkLocationPermission(mApp,
2279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002282 .setCallingPid(Binder.getCallingPid())
2283 .setCallingUid(Binder.getCallingUid())
2284 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2287 .build());
2288 switch (locationResult) {
2289 case DENIED_HARD:
2290 throw new SecurityException("Not allowed to access cell location");
2291 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002292 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2293 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002300 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002301 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Svetoslav64fad262015-04-14 14:35:21 -07002305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002308 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002309 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2310 // registered cell info, so return a NULL country instead.
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002313 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2314 // Get default phone in this case.
2315 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2316 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002319 if (phone == null) return "";
2320 ServiceStateTracker sst = phone.getServiceStateTracker();
2321 if (sst == null) return "";
2322 LocaleTracker lt = sst.getLocaleTracker();
2323 if (lt == null) return "";
2324 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2325 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2326 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002330 }
2331
2332 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002334 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mApp.enforceCallingOrSelfPermission(
2340 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 final Phone phone = getPhone(subId);
2345 if (phone != null) {
2346 phone.enableLocationUpdates();
2347 }
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
2353 @Override
2354 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002355 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002359 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 mApp.enforceCallingOrSelfPermission(
2361 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362
2363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 final Phone phone = getPhone(subId);
2366 if (phone != null) {
2367 phone.disableLocationUpdates();
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Nathan Harold31d7ff32018-10-15 20:20:30 -07002374 /**
2375 * Returns the target SDK version number for a given package name.
2376 *
Nathan Haroldec184742019-07-10 17:04:16 -07002377 * This call MUST be invoked before clearing the calling UID.
2378 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 * @return target SDK if the package is found or INT_MAX.
2380 */
2381 private int getTargetSdk(String packageName) {
2382 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002383 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002384 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002385 if (ai != null) return ai.targetSdkVersion;
2386 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002387 loge("Failed to get package info for pkg="
2388 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 }
2390 return Integer.MAX_VALUE;
2391 }
2392
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 @Override
2394 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002395 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2396 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002397 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002398 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2399 throw new SecurityException(
2400 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2401 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002402
Jordan Liu1617b712019-07-10 15:06:26 -07002403 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2405 return null;
2406 }
Svetoslav64fad262015-04-14 14:35:21 -07002407
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002408 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002410 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412
Nathan Haroldf180aac2018-06-01 18:43:55 -07002413 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2414 for (CellInfo ci : info) {
2415 if (ci instanceof CellInfoGsm) {
2416 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2417 } else if (ci instanceof CellInfoWcdma) {
2418 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002421 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002424 private List<CellInfo> getCachedCellInfo() {
2425 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2426 for (Phone phone : PhoneFactory.getPhones()) {
2427 List<CellInfo> info = phone.getAllCellInfo();
2428 if (info != null) cellInfos.addAll(info);
2429 }
2430 return cellInfos;
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
2433 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002434 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002435 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002436 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002437
2438 LocationAccessPolicy.LocationPermissionResult locationResult =
2439 LocationAccessPolicy.checkLocationPermission(mApp,
2440 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2441 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002442 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002443 .setCallingPid(Binder.getCallingPid())
2444 .setCallingUid(Binder.getCallingUid())
2445 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002446 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002447 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2448 .build());
2449 switch (locationResult) {
2450 case DENIED_HARD:
2451 throw new SecurityException("Not allowed to access cell info");
2452 case DENIED_SOFT:
2453 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002456 final int targetSdk = getTargetSdk(callingPackage);
2457 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2458 return getCachedCellInfo();
2459 }
2460
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002461 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2466 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002467 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002468 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 if (info != null) cellInfos.addAll(info);
2470 }
2471 return cellInfos;
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 }
2475 }
2476
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002477 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2479 String callingFeatureId) {
2480 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2481 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002482 }
2483
2484 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002485 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2486 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002487 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002488 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002489 }
2490
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002491 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2492 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002493 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002494 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002495
2496 LocationAccessPolicy.LocationPermissionResult locationResult =
2497 LocationAccessPolicy.checkLocationPermission(mApp,
2498 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2499 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002501 .setCallingPid(Binder.getCallingPid())
2502 .setCallingUid(Binder.getCallingUid())
2503 .setMethod("requestCellInfoUpdate")
2504 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2505 .build());
2506 switch (locationResult) {
2507 case DENIED_HARD:
2508 throw new SecurityException("Not allowed to access cell info");
2509 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002510 try {
2511 cb.onCellInfo(new ArrayList<CellInfo>());
2512 } catch (RemoteException re) {
2513 // Drop without consequences
2514 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002515 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002516 }
2517
Nathan Harolda939a962019-05-09 10:13:47 -07002518
2519 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002520 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2521
2522 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2523 }
2524
2525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002527 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002528 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002532 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 } finally {
2534 Binder.restoreCallingIdentity(identity);
2535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
Shishir Agrawala9f32182016-04-12 12:00:16 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 Phone phone = PhoneFactory.getPhone(slotIndex);
2541 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002542 return null;
2543 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002544 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002545 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002546 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002547 return null;
2548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 return phone.getImei();
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002556 }
2557
2558 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002559 public String getTypeAllocationCodeForSlot(int slotIndex) {
2560 Phone phone = PhoneFactory.getPhone(slotIndex);
2561 String tac = null;
2562 if (phone != null) {
2563 String imei = phone.getImei();
2564 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2565 }
2566 return tac;
2567 }
2568
2569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002570 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002571 Phone phone = PhoneFactory.getPhone(slotIndex);
2572 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002573 return null;
2574 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002575
Jeff Davidson913390f2018-02-23 17:11:49 -08002576 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002577 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002578 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 return null;
2580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return phone.getMeid();
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
2587 }
Jack Yu2af8d712017-03-15 17:14:14 -07002588 }
2589
2590 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002591 public String getManufacturerCodeForSlot(int slotIndex) {
2592 Phone phone = PhoneFactory.getPhone(slotIndex);
2593 String manufacturerCode = null;
2594 if (phone != null) {
2595 String meid = phone.getMeid();
2596 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2597 }
2598 return manufacturerCode;
2599 }
2600
2601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002602 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2603 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002604 Phone phone = PhoneFactory.getPhone(slotIndex);
2605 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002606 return null;
2607 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 int subId = phone.getSubId();
2609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 mApp, subId, callingPackage, callingFeatureId,
2611 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 return null;
2613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 return phone.getDeviceSvn();
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
2620 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002621 }
2622
fionaxu43304da2017-11-27 22:51:16 -08002623 @Override
2624 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 final Phone phone = getPhone(subId);
2628 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
fionaxu43304da2017-11-27 22:51:16 -08002632 }
2633
2634 @Override
2635 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 return phone == null ? null : phone.getCarrierName();
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
fionaxu43304da2017-11-27 22:51:16 -08002643 }
2644
calvinpanffe225e2018-11-01 19:43:06 +08002645 @Override
chen xu0026ca62019-03-06 15:28:50 -08002646 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002651 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
2655 }
2656
2657 @Override
chen xu0026ca62019-03-06 15:28:50 -08002658 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002662 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
2666 }
2667
chen xu651eec72018-11-11 19:03:44 -08002668 @Override
chen xu864e11c2018-12-06 22:10:03 -08002669 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2670 if (!isSubscriptionMccMnc) {
2671 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2672 }
chen xu651eec72018-11-11 19:03:44 -08002673 final Phone phone = PhoneFactory.getPhone(slotIndex);
2674 if (phone == null) {
2675 return TelephonyManager.UNKNOWN_CARRIER_ID;
2676 }
2677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
2683 }
2684
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 //
2686 // Internal helper methods.
2687 //
2688
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002689 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2691 *
2692 * @throws SecurityException if the caller does not have the required permission
2693 */
2694 private void enforceModifyPermission() {
2695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2696 }
2697
Shuo Qiancd19c462020-01-16 20:51:11 -08002698 /**
2699 * Make sure the caller is system.
2700 *
2701 * @throws SecurityException if the caller is not system.
2702 */
2703 private void enforceSystemCaller() {
2704 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2705 throw new SecurityException("Caller must be system");
2706 }
2707 }
2708
Shuo Qian3b6ee772019-11-13 17:43:31 -08002709 private void enforceActiveEmergencySessionPermission() {
2710 mApp.enforceCallingOrSelfPermission(
2711 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2712 }
2713
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 /**
2715 * Make sure the caller has the CALL_PHONE permission.
2716 *
2717 * @throws SecurityException if the caller does not have the required permission
2718 */
2719 private void enforceCallPermission() {
2720 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2721 }
2722
paulhu5a773602019-08-23 19:17:33 +08002723 private void enforceSettingsPermission() {
2724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002725 }
2726
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 private String createTelUrl(String number) {
2728 if (TextUtils.isEmpty(number)) {
2729 return null;
2730 }
2731
Jake Hambye994d462014-02-03 13:10:13 -08002732 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
2734
Ihab Awadf9e92732013-12-05 18:02:52 -08002735 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2737 }
2738
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002739 private static void logv(String msg) {
2740 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2741 }
2742
Ihab Awadf9e92732013-12-05 18:02:52 -08002743 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2745 }
2746
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002747 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002749 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002750 }
2751
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002753 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 final Phone phone = PhoneFactory.getPhone(slotIndex);
2757 if (phone == null) {
2758 return PhoneConstants.PHONE_TYPE_NONE;
2759 } else {
2760 return phone.getPhoneType();
2761 }
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
2767 /**
2768 * Returns the CDMA ERI icon index to display
2769 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2772 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2773 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002774 }
2775
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002777 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002780 mApp, subId, callingPackage, callingFeatureId,
2781 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002782 return -1;
2783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784
2785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 final Phone phone = getPhone(subId);
2788 if (phone != null) {
2789 return phone.getCdmaEriIconIndex();
2790 } else {
2791 return -1;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
2798 /**
2799 * Returns the CDMA ERI icon mode,
2800 * 0 - ON
2801 * 1 - FLASHING
2802 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002804 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2805 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2806 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002807 }
2808
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002810 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2811 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002813 mApp, subId, callingPackage, callingFeatureId,
2814 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 return -1;
2816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
2822 return phone.getCdmaEriIconMode();
2823 } else {
2824 return -1;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830
2831 /**
2832 * Returns the CDMA ERI text,
2833 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002834 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2836 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2837 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002838 }
2839
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002841 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002844 mApp, subId, callingPackage, callingFeatureId,
2845 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 return null;
2847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 final Phone phone = getPhone(subId);
2852 if (phone != null) {
2853 return phone.getCdmaEriText();
2854 } else {
2855 return null;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002863 * Returns the CDMA MDN.
2864 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002866 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2868 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 return phone.getLine1Number();
2875 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 return null;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002881 }
2882 }
2883
2884 /**
2885 * Returns the CDMA MIN.
2886 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002887 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002888 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2890 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
2895 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2896 return phone.getCdmaMin();
2897 } else {
2898 return null;
2899 }
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002902 }
2903 }
2904
Hall Liud892bec2018-11-30 14:51:45 -08002905 @Override
2906 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2907 INumberVerificationCallback callback, String callingPackage) {
2908 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2909 != PERMISSION_GRANTED) {
2910 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2911 }
2912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2913
2914 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2915 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2916 throw new SecurityException("Calling package must be configured in the device config");
2917 }
2918
2919 if (range == null) {
2920 throw new NullPointerException("Range must be non-null");
2921 }
2922
2923 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002924 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002925
2926 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2927 }
2928
Junda Liuca05d5d2014-08-14 22:36:34 -07002929 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 * Returns true if CDMA provisioning needs to run.
2931 */
2932 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
2941 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002942 * Sets the voice mail number of a given subId.
2943 */
2944 @Override
2945 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002946 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2947 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2952 new Pair<String, String>(alphaTag, number), new Integer(subId));
2953 return success;
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002957 }
2958
Ta-wei Yen87c49842016-05-13 21:19:52 -07002959 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002960 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2961 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002962 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2963 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002964 if (!TextUtils.equals(callingPackage, systemDialer)) {
2965 throw new SecurityException("caller must be system dialer");
2966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2971 if (phoneAccountHandle == null) {
2972 return null;
2973 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 } finally {
2976 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002977 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002978 }
2979
2980 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002981 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2982 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002985 mApp, subId, callingPackage, callingFeatureId,
2986 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002987 return null;
2988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002990 final long identity = Binder.clearCallingIdentity();
2991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002996 }
2997
2998 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002999 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3000 VisualVoicemailSmsFilterSettings settings) {
3001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002
3003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003010 }
3011
3012 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003013 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003019 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003023 }
3024
3025 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003026 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3027 String callingPackage, int subId) {
3028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003037 }
3038
3039 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003050 }
3051
3052 @Override
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003053 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3054 String callingAttributionTag, int subId, String number, int port, String text,
3055 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003057 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003058 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003059 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003060 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3061 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003062 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003063
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003064 /**
fionaxu0152e512016-11-14 13:36:14 -08003065 * Sets the voice activation state of a given subId.
3066 */
3067 @Override
3068 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3070 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 final Phone phone = getPhone(subId);
3075 if (phone != null) {
3076 phone.setVoiceActivationState(activationState);
3077 } else {
3078 loge("setVoiceActivationState fails with invalid subId: " + subId);
3079 }
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003082 }
3083 }
3084
3085 /**
3086 * Sets the data activation state of a given subId.
3087 */
3088 @Override
3089 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3091 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 if (phone != null) {
3097 phone.setDataActivationState(activationState);
3098 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003099 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003103 }
3104 }
3105
3106 /**
3107 * Returns the voice activation state of a given subId.
3108 */
3109 @Override
3110 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
fionaxu0152e512016-11-14 13:36:14 -08003113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 if (phone != null) {
3117 return phone.getVoiceActivationState();
3118 } else {
3119 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003123 }
3124 }
3125
3126 /**
3127 * Returns the data activation state of a given subId.
3128 */
3129 @Override
3130 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132
fionaxu0152e512016-11-14 13:36:14 -08003133 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 if (phone != null) {
3137 return phone.getDataActivationState();
3138 } else {
3139 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003143 }
3144 }
3145
3146 /**
Wink Saville36469e72014-06-11 15:17:00 -07003147 * Returns the unread count of voicemails for a subId
3148 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003150 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3151 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003153 mApp, subId, callingPackage, callingFeatureId,
3154 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003155 return 0;
3156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 final Phone phone = getPhone(subId);
3160 if (phone != null) {
3161 return phone.getVoiceMessageCount();
3162 } else {
3163 return 0;
3164 }
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169
3170 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003171 * returns true, if the device is in a state where both voice and data
3172 * are supported simultaneously. This can change based on location or network condition.
3173 */
3174 @Override
3175 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 final Phone phone = getPhone(subId);
3179 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003183 }
3184
3185 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003186 * Send the dialer code if called from the current default dialer or the caller has
3187 * carrier privilege.
3188 * @param inputCode The dialer code to send
3189 */
3190 @Override
3191 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003194 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3195 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003196 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003197 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003198 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003203 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
fionaxu235cc5e2017-03-06 22:25:57 -08003207 }
3208
Pengquan Menga1bb6272018-09-06 09:59:22 -07003209 @Override
3210 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003211 TelephonyPermissions
3212 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3213 mApp, subId, "getNetworkSelectionMode");
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 if (!isActiveSubscription(subId)) {
3217 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3218 }
3219 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003222 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003223 }
3224
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003226 public boolean isInEmergencySmsMode() {
3227 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 for (Phone phone : PhoneFactory.getPhones()) {
3231 if (phone.isInEmergencySmsMode()) {
3232 return true;
3233 }
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
3238 return false;
3239 }
3240
shilu366312e2019-12-17 09:28:10 -08003241 /**
3242 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3243 * @param subId The subscription to use to check the configuration.
3244 * @param c The callback that will be used to send the result.
3245 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003246 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003247 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3248 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003249 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3250 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003251
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003252 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3253 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3254 "IMS not available on device.");
3255 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 final long token = Binder.clearCallingIdentity();
3257 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003259 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(token);
3265 }
3266 }
3267
shilu366312e2019-12-17 09:28:10 -08003268 /**
3269 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3270 * @param subId The subscription to use to check the configuration.
3271 * @param c The callback that will be used to send the result.
3272 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003274 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003275 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3276 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003277 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3278 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3279 }
Meng Wangafbc5852019-09-19 17:37:13 -07003280 final long token = Binder.clearCallingIdentity();
3281 try {
3282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3283 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3284 .removeRegistrationCallbackForSubscription(c, subId);
3285 } catch (ImsException e) {
3286 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3287 + "is inactive, ignoring unregister.");
3288 // If the subscription is no longer active, just return, since the callback
3289 // will already have been removed internally.
3290 } finally {
3291 Binder.restoreCallingIdentity(token);
3292 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 }
3294
Brad Ebingera34a6c22019-10-22 17:36:18 -07003295 /**
3296 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3297 */
3298 @Override
3299 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3300 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3301 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3302 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3303 "IMS not available on device.");
3304 }
3305 final long token = Binder.clearCallingIdentity();
3306 try {
3307 Phone phone = getPhone(subId);
3308 if (phone == null) {
3309 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3310 + subId + "'");
3311 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3312 }
3313 phone.getImsRegistrationState(regState -> {
3314 try {
3315 consumer.accept((regState == null)
3316 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3317 } catch (RemoteException e) {
3318 // Ignore if the remote process is no longer available to call back.
3319 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3320 }
3321 });
3322 } finally {
3323 Binder.restoreCallingIdentity(token);
3324 }
3325 }
3326
3327 /**
3328 * Get the transport type for the IMS service registration state.
3329 */
3330 @Override
3331 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003332 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3333 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3336 "IMS not available on device.");
3337 }
3338 final long token = Binder.clearCallingIdentity();
3339 try {
3340 Phone phone = getPhone(subId);
3341 if (phone == null) {
3342 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3343 + subId + "'");
3344 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3345 }
3346 phone.getImsRegistrationTech(regTech -> {
3347 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3348 int regTechConverted = (regTech == null)
3349 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3350 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3351 regTechConverted);
3352 try {
3353 consumer.accept(regTechConverted);
3354 } catch (RemoteException e) {
3355 // Ignore if the remote process is no longer available to call back.
3356 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3357 }
3358 });
3359 } finally {
3360 Binder.restoreCallingIdentity(token);
3361 }
3362 }
3363
shilu366312e2019-12-17 09:28:10 -08003364 /**
3365 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3366 * @param subId The subscription to use to check the configuration.
3367 * @param c The callback that will be used to send the result.
3368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003370 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3371 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003372 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3373 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003374 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3375 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3376 "IMS not available on device.");
3377 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3379 final long token = Binder.clearCallingIdentity();
3380 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003381 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003383 } catch (ImsException e) {
3384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 } finally {
3386 Binder.restoreCallingIdentity(token);
3387 }
3388 }
3389
shilu366312e2019-12-17 09:28:10 -08003390 /**
3391 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3392 * @param subId The subscription to use to check the configuration.
3393 * @param c The callback that will be used to send the result.
3394 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003396 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003397 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3398 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003399 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3400 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3401 }
Meng Wangafbc5852019-09-19 17:37:13 -07003402
3403 final long token = Binder.clearCallingIdentity();
3404 try {
3405 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3406 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003407 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003408 } catch (ImsException e) {
3409 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3410 + "is inactive, ignoring unregister.");
3411 // If the subscription is no longer active, just return, since the callback
3412 // will already have been removed internally.
3413 } finally {
3414 Binder.restoreCallingIdentity(token);
3415 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 }
3417
3418 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003419 public boolean isCapable(int subId, int capability, int regTech) {
3420 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3422 final long token = Binder.clearCallingIdentity();
3423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3428 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003429 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003430 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3431 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 } finally {
3433 Binder.restoreCallingIdentity(token);
3434 }
3435 }
3436
3437 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003438 public boolean isAvailable(int subId, int capability, int regTech) {
3439 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 final long token = Binder.clearCallingIdentity();
3441 try {
3442 Phone phone = getPhone(subId);
3443 if (phone == null) return false;
3444 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003445 } catch (com.android.ims.ImsException e) {
3446 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3447 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 } finally {
3449 Binder.restoreCallingIdentity(token);
3450 }
3451 }
3452
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003453 /**
3454 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3455 * subscription.
3456 * @param subId The subscription to use to check the configuration.
3457 * @param callback The callback that will be used to send the result.
3458 * @param capability The MmTelFeature capability that will be used to send the result.
3459 * @param transportType The transport type of the MmTelFeature capability.
3460 */
3461 @Override
3462 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3463 int transportType) {
3464 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3465 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3466 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3467 "IMS not available on device.");
3468 }
3469 final long token = Binder.clearCallingIdentity();
3470 try {
3471 int slotId = getSlotIndex(subId);
3472 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3473 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3474 + subId + "'");
3475 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3476 }
3477 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3478 transportType, aBoolean -> {
3479 try {
3480 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3481 } catch (RemoteException e) {
3482 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3483 + "running. Ignore");
3484 }
3485 });
3486 } finally {
3487 Binder.restoreCallingIdentity(token);
3488 }
3489 }
3490
shilu366312e2019-12-17 09:28:10 -08003491 /**
3492 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3493 * @param subId The subscription to use to check the configuration.
3494 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 @Override
3496 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003497 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3498 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003499
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3501 final long token = Binder.clearCallingIdentity();
3502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003505 } catch (ImsException e) {
3506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 } finally {
3508 Binder.restoreCallingIdentity(token);
3509 }
3510 }
3511
3512 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003513 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003515 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003521 } catch (ImsException e) {
3522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
shilu366312e2019-12-17 09:28:10 -08003528 /**
3529 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3530 * @param subId The subscription to use to check the configuration.
3531 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003533 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003534 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3535 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003539 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3540 } catch (ImsException e) {
3541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
3545 }
3546
3547 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003548 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003550 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003554 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003555 } catch (ImsException e) {
3556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
3560 }
3561
shilu366312e2019-12-17 09:28:10 -08003562 /**
3563 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3564 * @param subId The subscription to use to check the configuration.
3565 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 @Override
3567 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003568 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3569 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003573 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003575 } catch (ImsException e) {
3576 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
3582 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003583 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003585 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003589 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003590 } catch (ImsException e) {
3591 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 } finally {
3593 Binder.restoreCallingIdentity(identity);
3594 }
3595 }
3596
shilu366312e2019-12-17 09:28:10 -08003597 /**
3598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3599 * @param subId The subscription to use to check the configuration.
3600 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 @Override
3602 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003603 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3604 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003610 } catch (ImsException e) {
3611 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
3615 }
3616
3617 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003618 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003620 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003624 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003626 } catch (ImsException e) {
3627 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
3631 }
3632
3633 @Override
3634 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3636 "setVoWiFiNonPersistent");
3637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003641 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003642 } catch (ImsException e) {
3643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
3647 }
3648
shilu366312e2019-12-17 09:28:10 -08003649 /**
3650 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3651 * @param subId The subscription to use to check the configuration.
3652 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 @Override
3654 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003655 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3656 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003660 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (ImsException e) {
3663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
3667 }
3668
3669 @Override
3670 public void setVoWiFiModeSetting(int subId, int mode) {
3671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3672 "setVoWiFiModeSetting");
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003678 } catch (ImsException e) {
3679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public int getVoWiFiRoamingModeSetting(int subId) {
3687 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003693 } catch (ImsException e) {
3694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3703 "setVoWiFiRoamingModeSetting");
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003707 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003709 } catch (ImsException e) {
3710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3719 "setRttCapabilityEnabled");
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
shilu366312e2019-12-17 09:28:10 -08003731 /**
3732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3733 * @param subId The subscription to use to check the configuration.
3734 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 @Override
3736 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
3745 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003751 @Override
3752 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3753 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3754 final long identity = Binder.clearCallingIdentity();
3755 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003756 if (!isImsAvailableOnDevice()) {
3757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3758 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003759 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003761 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003762 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003763 } catch (ImsException e) {
3764 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
3768 }
3769
3770 @Override
3771 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3772 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3773 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003774 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3775 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3776 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003777 try {
3778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003780 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003781 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003782 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3783 + "is inactive, ignoring unregister.");
3784 // If the subscription is no longer active, just return, since the callback will already
3785 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
3789 }
3790
allenwtsu99c623b2020-01-03 18:24:23 +08003791
3792 private void checkModifyPhoneStatePermission(int subId, String message) {
3793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3794 message);
3795 }
3796
3797 private boolean isImsProvisioningRequired(int subId, int capability,
3798 boolean isMmtelCapability) {
3799 Phone phone = getPhone(subId);
3800 if (phone == null) {
3801 loge("phone instance null for subid " + subId);
3802 return false;
3803 }
3804 if (isMmtelCapability) {
3805 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3806 return false;
3807 }
3808 } else {
3809 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3810 return false;
3811 }
3812 }
3813 return true;
3814 }
3815
3816 @Override
3817 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3818 boolean isProvisioned) {
3819 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3824 if (!isImsProvisioningRequired(subId, capability, false)) {
3825 return;
3826 }
3827
3828 // this capability requires provisioning, route to the correct API.
3829 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3830 switch (capability) {
3831 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3832 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3833 ims.setEabProvisioned(isProvisioned);
3834 break;
3835 default: {
3836 throw new IllegalArgumentException("Tried to set provisioning for "
3837 + "rcs capability '" + capability + "', which does not require "
3838 + "provisioning.");
3839 }
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
3844
3845 }
3846
3847
3848 @Override
3849 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3850 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3854 if (!isImsProvisioningRequired(subId, capability, false)) {
3855 return true;
3856 }
3857
3858 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3859 switch (capability) {
3860 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3862 return ims.isEabProvisionedOnDevice();
3863
3864 default: {
3865 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3866 + "capability '" + capability + "', which does not require "
3867 + "provisioning.");
3868 }
3869 }
3870
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003876 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003877 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3878 boolean isProvisioned) {
3879 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3880 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3881 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3882 }
allenwtsu99c623b2020-01-03 18:24:23 +08003883 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003887 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003888 return;
3889 }
3890
3891 // this capability requires provisioning, route to the correct API.
3892 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3893 switch (capability) {
3894 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3895 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3896 ims.setVolteProvisioned(isProvisioned);
3897 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3898 ims.setWfcProvisioned(isProvisioned);
3899 }
3900 break;
3901 }
3902 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3903 // There is currently no difference in VT provisioning type.
3904 ims.setVtProvisioned(isProvisioned);
3905 break;
3906 }
3907 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3908 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3909 // change the capability of the feature instead if needed.
3910 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3911 == isProvisioned) {
3912 // No change in provisioning.
3913 return;
3914 }
3915 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3916 try {
3917 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003918 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003919 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3920 + ", Exception" + e.getMessage());
3921 }
3922 break;
3923 }
3924 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003925 throw new IllegalArgumentException("Tried to set provisioning for "
3926 + "MmTel capability '" + capability + "', which does not require "
3927 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003928 }
3929 }
3930
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
3934 }
3935
3936 @Override
3937 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3938 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3939 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3940 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3941 }
3942 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003946 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003947 return true;
3948 }
3949
3950 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3951 switch (capability) {
3952 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3953 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3954 return ims.isVolteProvisionedOnDevice();
3955 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3956 return ims.isWfcProvisionedOnDevice();
3957 }
3958 // This should never happen, since we are checking tech above to make sure it
3959 // is either LTE or IWLAN.
3960 throw new IllegalArgumentException("Invalid radio technology for voice "
3961 + "capability.");
3962 }
3963 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3964 // There is currently no difference in VT provisioning type.
3965 return ims.isVtProvisionedOnDevice();
3966 }
3967 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3968 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3969 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3970 }
3971 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003972 throw new IllegalArgumentException(
3973 "Tried to get provisioning for MmTel capability '" + capability
3974 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003975 }
3976 }
3977
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
3981 }
3982
3983 @Override
3984 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3985 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3986 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3987 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3988 }
3989 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3990 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3991 return (provisionedBits & capability) > 0;
3992 }
3993
3994 @Override
3995 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3996 boolean isProvisioned) {
3997 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3998 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3999 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4000 }
4001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4002 "setProvisioningStatusForCapability");
4003 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4004 // If the current provisioning status for capability already matches isProvisioned,
4005 // do nothing.
4006 if (((provisionedBits & capability) > 0) == isProvisioned) {
4007 return;
4008 }
4009 if (isProvisioned) {
4010 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4011 } else {
4012 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4013 }
4014 }
4015
4016 /**
4017 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4018 * technology. The bitfield should mirror the bitfield defined by
4019 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4020 */
4021 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4022 String key = getMmTelProvisioningKey(subId, tech);
4023 // Default is no capabilities are provisioned.
4024 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4025 }
4026
4027 /**
4028 * Sets the MmTel capability provisioning bitfield (defined by
4029 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4030 * technology specified.
4031 *
4032 * Note: This is a synchronous command and should not be called on UI thread.
4033 */
4034 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4035 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4036 String key = getMmTelProvisioningKey(subId, tech);
4037 editor.putInt(key, newField);
4038 editor.commit();
4039 }
4040
4041 private static String getMmTelProvisioningKey(int subId, int tech) {
4042 // resulting key is provision_ims_mmtel_{subId}_{tech}
4043 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4044 }
4045
4046 /**
4047 * Query CarrierConfig to see if the specified capability requires provisioning for the
4048 * carrier associated with the subscription id.
4049 */
4050 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4051 int capability) {
4052 CarrierConfigManager configManager = new CarrierConfigManager(context);
4053 PersistableBundle c = configManager.getConfigForSubId(subId);
4054 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004055 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004056 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4057 false);
4058 boolean requireVoiceVtProvisioning = c.getBoolean(
4059 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4060
4061 // First check to make sure that the capability requires provisioning.
4062 switch (capability) {
4063 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4064 // intentional fallthrough
4065 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4066 if (requireVoiceVtProvisioning) {
4067 // Voice and Video requires provisioning
4068 return true;
4069 }
4070 break;
4071 }
4072 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4073 if (requireUtProvisioning) {
4074 // UT requires provisioning
4075 return true;
4076 }
4077 break;
4078 }
4079 }
4080 return false;
4081 }
4082
allenwtsu99c623b2020-01-03 18:24:23 +08004083 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4084 int capability) {
4085 CarrierConfigManager configManager = new CarrierConfigManager(context);
4086 PersistableBundle c = configManager.getConfigForSubId(subId);
4087
4088 boolean requireRcsProvisioning = c.getBoolean(
4089 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4090
4091 // First check to make sure that the capability requires provisioning.
4092 switch (capability) {
4093 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4094 // intentional fallthrough
4095 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4096 if (requireRcsProvisioning) {
4097 // OPTION or PRESENCE requires provisioning
4098 return true;
4099 }
4100 break;
4101 }
4102 }
4103 return false;
4104 }
4105
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004106 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004107 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004108 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4109 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4110 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004111 enforceReadPrivilegedPermission("getImsProvisioningInt");
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004115 int slotId = getSlotIndex(subId);
4116 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4117 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4118 + subId + "' for key:" + key);
4119 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4120 }
4121 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004122 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004123 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4124 + subId + "' for key:" + key);
4125 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
4131 @Override
4132 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004133 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4134 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4135 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004136 enforceReadPrivilegedPermission("getImsProvisioningString");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004140 int slotId = getSlotIndex(subId);
4141 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4142 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4143 + subId + "' for key:" + key);
4144 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4145 }
4146 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004148 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4149 + subId + "' for key:" + key);
4150 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
4154 }
4155
4156 @Override
4157 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004158 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4159 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4160 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4162 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004166 int slotId = getSlotIndex(subId);
4167 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4168 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4169 + subId + "' for key:" + key);
4170 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4171 }
4172 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004174 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4175 + "' for key:" + key);
4176 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
4180 }
4181
4182 @Override
4183 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4185 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4186 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4188 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004192 int slotId = getSlotIndex(subId);
4193 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4194 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4195 + subId + "' for key:" + key);
4196 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4197 }
4198 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004200 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4201 + "' for key:" + key);
4202 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 int slotId = SubscriptionManager.getSlotIndex(subId);
4210 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4212 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 }
4214 return slotId;
4215 }
4216
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004217 private int getSlotIndex(int subId) {
4218 int slotId = SubscriptionManager.getSlotIndex(subId);
4219 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4220 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4221 }
4222 return slotId;
4223 }
4224
Wink Saville36469e72014-06-11 15:17:00 -07004225 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004226 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004227 */
4228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004229 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4230 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004231 final int targetSdk = getTargetSdk(callingPackage);
4232 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004234 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004235 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId,
4237 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4239 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 final Phone phone = getPhone(subId);
4244 if (phone != null) {
4245 return phone.getServiceState().getDataNetworkType();
4246 } else {
4247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4248 }
4249 } finally {
4250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004252 }
4253
4254 /**
4255 * Returns the data network type
4256 */
4257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004258 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4259 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4260 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004261 }
4262
4263 /**
4264 * Returns the data network type for a subId
4265 */
4266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004267 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4268 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 mApp, subId, callingPackage, callingFeatureId,
4271 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004272 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4273 }
4274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 final Phone phone = getPhone(subId);
4278 if (phone != null) {
4279 return phone.getServiceState().getDataNetworkType();
4280 } else {
4281 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4282 }
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004286 }
4287
4288 /**
Wink Saville36469e72014-06-11 15:17:00 -07004289 * Returns the Voice network type for a subId
4290 */
4291 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004292 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4293 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004295 mApp, subId, callingPackage, callingFeatureId,
4296 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004297 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4298 }
4299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 final Phone phone = getPhone(subId);
4303 if (phone != null) {
4304 return phone.getServiceState().getVoiceNetworkType();
4305 } else {
4306 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4307 }
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004311 }
4312
4313 /**
4314 * @return true if a ICC card is present
4315 */
4316 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004317 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004318 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4319 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004320 }
4321
4322 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004323 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004324 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004325 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004326 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 final Phone phone = PhoneFactory.getPhone(slotIndex);
4330 if (phone != null) {
4331 return phone.getIccCard().hasIccCard();
4332 } else {
4333 return false;
4334 }
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004338 }
4339
4340 /**
4341 * Return if the current radio is LTE on CDMA. This
4342 * is a tri-state return value as for a period of time
4343 * the mode may be unknown.
4344 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004345 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004346 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004347 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004348 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004350 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4351 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4352 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004353 }
4354
Sanket Padawe356d7632015-06-22 14:03:32 -07004355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004356 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4357 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004358 try {
4359 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4360 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004361 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4362 }
4363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 final long identity = Binder.clearCallingIdentity();
4365 try {
4366 final Phone phone = getPhone(subId);
4367 if (phone == null) {
4368 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4369 } else {
4370 return phone.getLteOnCdmaMode();
4371 }
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004374 }
Wink Saville36469e72014-06-11 15:17:00 -07004375 }
4376
Wink Saville36469e72014-06-11 15:17:00 -07004377 /**
4378 * {@hide}
4379 * Returns Default subId, 0 in the case of single standby.
4380 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004381 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004382 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004383 }
4384
Shishir Agrawala9f32182016-04-12 12:00:16 -07004385 private int getSlotForDefaultSubscription() {
4386 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4387 }
4388
Wink Savilleb564aae2014-10-23 10:18:09 -07004389 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004390 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004391 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004392
Pengquan Menge92a50d2018-09-21 15:54:48 -07004393 private boolean isActiveSubscription(int subId) {
4394 return mSubscriptionController.isActiveSubId(subId);
4395 }
4396
Ihab Awadf2177b72013-11-25 13:33:23 -08004397 /**
4398 * @see android.telephony.TelephonyManager.WifiCallingChoices
4399 */
4400 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004403 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4405 getWhenToMakeWifiCallsDefaultPreference());
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004409 }
4410
4411 /**
4412 * @see android.telephony.TelephonyManager.WifiCallingChoices
4413 */
4414 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 final long identity = Binder.clearCallingIdentity();
4416 try {
4417 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004418 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004423 }
4424
Sailesh Nepald1e68152013-12-12 19:08:02 -08004425 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004426 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004427 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004428 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004429
Jordan Liu4c733742019-02-28 12:03:40 -08004430 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4431 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4432 if (phoneId == -1) {
4433 throw new IllegalArgumentException("Given slot index: " + slotIndex
4434 + " does not correspond to an active phone");
4435 }
4436 return PhoneFactory.getPhone(phoneId);
4437 }
4438
Shishir Agrawal566b7612013-10-28 14:41:00 -07004439 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004440 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4441 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4443 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004445 if (DBG) {
4446 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4447 }
4448 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4449 p2);
4450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004451
Jordan Liu4c733742019-02-28 12:03:40 -08004452
4453 @Override
4454 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4455 int slotIndex, String callingPackage, String aid, int p2) {
4456 enforceModifyPermission();
4457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4458 if (DBG) {
4459 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4460 }
4461 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4462 callingPackage, aid, p2);
4463 }
4464
4465 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4466 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 if (TextUtils.equals(ISDR_AID, aid)) {
4470 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004471 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4472 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 if (bestComponent == null
4474 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4475 loge("The calling package is not allowed to access ISD-R.");
4476 throw new SecurityException(
4477 "The calling package is not allowed to access ISD-R.");
4478 }
Derek Tan740e1672017-06-27 14:56:27 -07004479 }
Derek Tan740e1672017-06-27 14:56:27 -07004480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004482 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4483 null /* workSource */);
4484 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 return response;
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004489 }
4490
4491 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004492 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004495 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4496 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4497 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004498
Jordan Liu4c733742019-02-28 12:03:40 -08004499 @Override
4500 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4501 enforceModifyPermission();
4502 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4503 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4504 channel);
4505 }
4506
4507 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 final long identity = Binder.clearCallingIdentity();
4509 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 if (channel < 0) {
4511 return false;
4512 }
Jordan Liu4c733742019-02-28 12:03:40 -08004513 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4514 null /* workSource */);
4515 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 return success;
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
4521
4522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004523 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004524 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004527 if (DBG) {
4528 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4529 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4530 + p3 + " data=" + data);
4531 }
4532 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4533 command, p1, p2, p3, data);
4534 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004535
Jordan Liu4c733742019-02-28 12:03:40 -08004536 @Override
4537 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4538 int command, int p1, int p2, int p3, String data) {
4539 enforceModifyPermission();
4540 if (DBG) {
4541 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4542 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4543 + p3 + " data=" + data);
4544 }
4545 return iccTransmitApduLogicalChannelWithPermission(
4546 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4547 data);
4548 }
4549
4550 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4551 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 final long identity = Binder.clearCallingIdentity();
4553 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004554 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 return "";
4556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004559 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4560 null /* workSource */);
4561 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 // Append the returned status code to the end of the response payload.
4564 String s = Integer.toHexString(
4565 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4566 if (response.payload != null) {
4567 s = IccUtils.bytesToHexString(response.payload) + s;
4568 }
4569 return s;
4570 } finally {
4571 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004572 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004573 }
Jake Hambye994d462014-02-03 13:10:13 -08004574
Evan Charltonc66da362014-05-16 14:06:40 -07004575 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004576 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4577 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4579 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004581 if (DBG) {
4582 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4583 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4584 }
4585 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4586 cla, command, p1, p2, p3, data);
4587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004588
Jordan Liu4c733742019-02-28 12:03:40 -08004589 @Override
4590 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4591 int command, int p1, int p2, int p3, String data) {
4592 enforceModifyPermission();
4593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4594 if (DBG) {
4595 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4596 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4597 + " data=" + data);
4598 }
4599
4600 return iccTransmitApduBasicChannelWithPermission(
4601 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4602 p2, p3, data);
4603 }
4604
4605 // open APDU basic channel assuming the caller has sufficient permissions
4606 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4607 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4611 && TextUtils.equals(ISDR_AID, data)) {
4612 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004613 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4614 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 if (bestComponent == null
4616 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4617 loge("The calling package is not allowed to select ISD-R.");
4618 throw new SecurityException(
4619 "The calling package is not allowed to select ISD-R.");
4620 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004621 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004624 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4625 null /* workSource */);
4626 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 // Append the returned status code to the end of the response payload.
4629 String s = Integer.toHexString(
4630 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4631 if (response.payload != null) {
4632 s = IccUtils.bytesToHexString(response.payload) + s;
4633 }
4634 return s;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004637 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004638 }
4639
4640 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004641 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004642 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4644 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 if (DBG) {
4649 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4650 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4651 }
4652
4653 IccIoResult response =
4654 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4655 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4656 subId);
4657
4658 if (DBG) {
4659 log("Exchange SIM_IO [R]" + response);
4660 }
4661
4662 byte[] result = null;
4663 int length = 2;
4664 if (response.payload != null) {
4665 length = 2 + response.payload.length;
4666 result = new byte[length];
4667 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4668 } else {
4669 result = new byte[length];
4670 }
4671
4672 result[length - 1] = (byte) response.sw2;
4673 result[length - 2] = (byte) response.sw1;
4674 return result;
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004677 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678 }
4679
Nathan Haroldb3014052017-01-25 15:57:32 -08004680 /**
4681 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4682 * on a particular subscription
4683 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004684 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4685 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004687 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004688 return null;
4689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 if (appType != TelephonyManager.APPTYPE_USIM
4694 && appType != TelephonyManager.APPTYPE_SIM) {
4695 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4696 return null;
4697 }
4698 Object response = sendRequest(
4699 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4700 if (response instanceof String[]) {
4701 return (String[]) response;
4702 }
yincheng zhao2737e882019-09-06 17:06:54 -07004703 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004705 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004708 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004709 }
4710
yincheng zhao2737e882019-09-06 17:06:54 -07004711 /**
4712 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4713 * subscription.
4714 *
4715 * @param subId the id of the subscription.
4716 * @param appType the uicc app type, must be USIM or SIM.
4717 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4718 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004719 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004720 * @return number of fplmns that is successfully written to the SIM.
4721 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004722 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4723 String callingFeatureId) {
4724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4725 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004726 if (DBG) logv("no permissions for setForbiddenplmns");
4727 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4728 }
4729 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4730 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4731 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4732 }
4733 if (fplmns == null) {
4734 throw new IllegalArgumentException("Fplmn List provided is null");
4735 }
4736 for (String fplmn : fplmns) {
4737 if (!CellIdentity.isValidPlmn(fplmn)) {
4738 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4739 }
4740 }
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 Object response = sendRequest(
4744 CMD_SET_FORBIDDEN_PLMNS,
4745 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4746 subId);
4747 return (int) response;
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
4750 }
4751 }
4752
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004753 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004754 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4756 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4761 if (response.payload == null) {
4762 return "";
4763 }
Evan Charltonc66da362014-05-16 14:06:40 -07004764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 // Append the returned status code to the end of the response payload.
4766 String s = Integer.toHexString(
4767 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4768 s = IccUtils.bytesToHexString(response.payload) + s;
4769 return s;
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
Evan Charltonc66da362014-05-16 14:06:40 -07004773 }
4774
Jake Hambye994d462014-02-03 13:10:13 -08004775 /**
4776 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4777 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4778 *
4779 * @param itemID the ID of the item to read
4780 * @return the NV item as a String, or null on error.
4781 */
4782 @Override
4783 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4786 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787
4788 final long identity = Binder.clearCallingIdentity();
4789 try {
4790 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004791 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4793 return value;
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
Jake Hambye994d462014-02-03 13:10:13 -08004797 }
4798
4799 /**
4800 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4801 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4802 *
4803 * @param itemID the ID of the item to read
4804 * @param itemValue the value to write, as a String
4805 * @return true on success; false on any failure
4806 */
4807 @Override
4808 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004809 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4811 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
4813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4816 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004817 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4819 return success;
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Jake Hambye994d462014-02-03 13:10:13 -08004823 }
4824
4825 /**
4826 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4827 * Used for device configuration by some CDMA operators.
4828 *
4829 * @param preferredRoamingList byte array containing the new PRL
4830 * @return true on success; false on any failure
4831 */
4832 @Override
4833 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4835 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836
4837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4840 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4841 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4842 return success;
4843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
Jake Hambye994d462014-02-03 13:10:13 -08004846 }
4847
4848 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004849 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004850 * Used for device configuration by some CDMA operators.
4851 *
chen xu6dac5ab2018-10-26 17:39:23 -07004852 * @param slotIndex - device slot.
4853 *
Jake Hambye994d462014-02-03 13:10:13 -08004854 * @return true on success; false on any failure
4855 */
4856 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004857 public boolean resetModemConfig(int slotIndex) {
4858 Phone phone = PhoneFactory.getPhone(slotIndex);
4859 if (phone != null) {
4860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4861 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862
chen xu6dac5ab2018-10-26 17:39:23 -07004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4866 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4867 return success;
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
4870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 }
chen xu6dac5ab2018-10-26 17:39:23 -07004872 return false;
4873 }
4874
4875 /**
4876 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4877 *
4878 * @param slotIndex - device slot.
4879 *
4880 * @return true on success; false on any failure
4881 */
4882 @Override
4883 public boolean rebootModem(int slotIndex) {
4884 Phone phone = PhoneFactory.getPhone(slotIndex);
4885 if (phone != null) {
4886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4887 mApp, phone.getSubId(), "rebootModem");
4888
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4892 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4893 return success;
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
4897 }
4898 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004899 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004900
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004901 public String[] getPcscfAddress(String apnType, String callingPackage,
4902 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004903 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4905 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004906 return new String[0];
4907 }
4908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004911 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
Wink Saville36469e72014-06-11 15:17:00 -07004915 }
4916
Brad Ebinger51f743a2017-01-23 13:50:20 -08004917 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004918 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4919 * {@link #disableIms(int)}.
4920 * @param slotIndex device slot.
4921 */
4922 public void resetIms(int slotIndex) {
4923 enforceModifyPermission();
4924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (mImsResolver == null) {
4928 // may happen if the does not support IMS.
4929 return;
4930 }
4931 mImsResolver.disableIms(slotIndex);
4932 mImsResolver.enableIms(slotIndex);
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004939 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4940 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004941 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004942 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004947 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004948 // may happen if the device does not support IMS.
4949 return;
4950 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004951 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004955 }
4956
4957 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004958 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4959 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004960 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004961 public void disableIms(int slotId) {
4962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963
4964 final long identity = Binder.clearCallingIdentity();
4965 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004966 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004967 // may happen if the device does not support IMS.
4968 return;
4969 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004970 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004974 }
4975
4976 /**
4977 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4978 * feature or {@link null} if the service is not available. If the feature is available, the
4979 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4980 */
4981 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004982 IImsServiceFeatureCallback callback) {
4983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004987 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004988 // may happen if the device does not support IMS.
4989 return null;
4990 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004991 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004995 }
4996
4997 /**
4998 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4999 * feature during emergency calling or {@link null} if the service is not available. If the
5000 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5001 * listener for feature updates.
5002 */
5003 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005008 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005009 // may happen if the device does not support IMS.
5010 return null;
5011 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005012 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005016 }
5017
Brad Ebinger5f64b052017-12-14 14:26:15 -08005018 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005019 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5020 */
5021 public void unregisterImsFeatureCallback(int slotId, int featureType,
5022 IImsServiceFeatureCallback callback) {
5023 enforceModifyPermission();
5024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 if (mImsResolver == null) return;
5028 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
5032 }
5033
5034 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005035 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005036 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005037 */
5038 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040
5041 final long identity = Binder.clearCallingIdentity();
5042 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005043 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005044 // may happen if the device does not support IMS.
5045 return null;
5046 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005051 }
5052
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005053 /**
5054 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005055 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005056 */
5057 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059
5060 final long identity = Binder.clearCallingIdentity();
5061 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005062 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005063 // may happen if the device does not support IMS.
5064 return null;
5065 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005066 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005070 }
5071
Brad Ebinger884c07b2018-02-15 16:17:40 -08005072 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005073 * Sets the ImsService Package Name that Telephony will bind to.
5074 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005075 * @param slotIndex the slot ID that the ImsService should bind for.
5076 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005077 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 * @param featureTypes An integer array of feature types associated with a packageName.
5079 * @param packageName The name of the package that the current configuration will be replaced
5080 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005082 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005083 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5084 int[] featureTypes, String packageName) {
5085 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5088 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005089 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005093 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005094 // may happen if the device does not support IMS.
5095 return false;
5096 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005097 Map<Integer, String> featureConfig = new HashMap<>();
5098 for (int featureType : featureTypes) {
5099 featureConfig.put(featureType, packageName);
5100 }
5101 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5102 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005106 }
5107
5108 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005109 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005110 *
5111 * @param slotId The slot that the ImsService is associated with.
5112 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5113 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005114 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005115 * @return the package name of the ImsService configuration.
5116 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005117 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5118 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005119 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005120 TelephonyPermissions
5121 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5122 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5123 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 final long identity = Binder.clearCallingIdentity();
5126 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005127 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005128 // may happen if the device does not support IMS.
5129 return "";
5130 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005131 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005132 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5133 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005137 }
5138
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005139 /**
5140 * Get the MmTelFeature state associated with the requested subscription id.
5141 * @param subId The subscription that the MmTelFeature is associated with.
5142 * @param callback A callback with an integer containing the
5143 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5144 */
5145 @Override
5146 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5147 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5148 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5150 "IMS not available on device.");
5151 }
5152 final long token = Binder.clearCallingIdentity();
5153 try {
5154 int slotId = getSlotIndex(subId);
5155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5156 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5157 + subId + "'");
5158 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5159 }
5160 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5161 try {
5162 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5163 } catch (RemoteException e) {
5164 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5165 + "Ignore");
5166 }
5167 });
5168 } finally {
5169 Binder.restoreCallingIdentity(token);
5170 }
5171 }
5172
Wink Saville36469e72014-06-11 15:17:00 -07005173 public void setImsRegistrationState(boolean registered) {
5174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175
5176 final long identity = Binder.clearCallingIdentity();
5177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005178 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
Wink Saville36469e72014-06-11 15:17:00 -07005182 }
5183
5184 /**
Stuart Scott54788802015-03-30 13:18:01 -07005185 * Set the network selection mode to automatic.
5186 *
5187 */
5188 @Override
5189 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192
5193 final long identity = Binder.clearCallingIdentity();
5194 try {
shilufc958392020-01-20 11:36:01 -08005195 if (!isActiveSubscription(subId)) {
5196 return;
5197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5199 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Stuart Scott54788802015-03-30 13:18:01 -07005203 }
5204
Pengquan Mengea84e042018-09-20 14:57:26 -07005205 /**
5206 * Ask the radio to connect to the input network and change selection mode to manual.
5207 *
5208 * @param subId the id of the subscription.
5209 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5210 * the operator to attach to.
5211 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5212 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5213 * normal network selection next time.
5214 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005215 */
5216 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005217 public boolean setNetworkSelectionModeManual(
5218 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005221
5222 if (!isActiveSubscription(subId)) {
5223 return false;
5224 }
5225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005228 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005230 if (DBG) {
5231 log("setNetworkSelectionModeManual: subId: " + subId
5232 + " operator: " + operatorInfo);
5233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005238 }
shilu84f6e8b2019-12-19 13:58:01 -08005239 /**
5240 * Get the manual network selection
5241 *
5242 * @param subId the id of the subscription.
5243 *
5244 * @return the previously saved user selected PLMN
5245 */
5246 @Override
5247 public String getManualNetworkSelectionPlmn(int subId) {
5248 TelephonyPermissions
5249 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5250 mApp, subId, "getManualNetworkSelectionPlmn");
5251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 if (!isActiveSubscription(subId)) {
5255 return "";
5256 }
5257
5258 final Phone phone = getPhone(subId);
5259 if (phone == null) {
5260 return "";
5261 }
5262 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5263 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5264 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
5268 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005269
5270 /**
5271 * Scans for available networks.
5272 */
5273 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005274 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5275 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005278 LocationAccessPolicy.LocationPermissionResult locationResult =
5279 LocationAccessPolicy.checkLocationPermission(mApp,
5280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5281 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005282 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005283 .setCallingPid(Binder.getCallingPid())
5284 .setCallingUid(Binder.getCallingUid())
5285 .setMethod("getCellNetworkScanResults")
5286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5287 .build());
5288 switch (locationResult) {
5289 case DENIED_HARD:
5290 throw new SecurityException("Not allowed to access scan results -- location");
5291 case DENIED_SOFT:
5292 return null;
5293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294
Pengquan Menga1bb6272018-09-06 09:59:22 -07005295 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 try {
5297 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005298 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005303 }
5304
5305 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005306 * Get the call forwarding info, given the call forwarding reason.
5307 */
5308 @Override
5309 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5310 enforceReadPrivilegedPermission("getCallForwarding");
5311 long identity = Binder.clearCallingIdentity();
5312 try {
5313 if (DBG) {
5314 log("getCallForwarding: subId " + subId
5315 + " callForwardingReason" + callForwardingReason);
5316 }
5317 return (CallForwardingInfo) sendRequest(
5318 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
5322 }
5323
5324 /**
5325 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5326 * reason, the number to forward, and the timeout before the forwarding is attempted.
5327 */
5328 @Override
5329 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5330 enforceModifyPermission();
5331 long identity = Binder.clearCallingIdentity();
5332 try {
5333 if (DBG) {
5334 log("setCallForwarding: subId " + subId
5335 + " callForwardingInfo" + callForwardingInfo);
5336 }
5337 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 /**
5344 * Get the call forwarding info, given the call forwarding reason.
5345 */
5346 @Override
5347 public int getCallWaitingStatus(int subId) {
5348 enforceReadPrivilegedPermission("getCallForwarding");
5349 long identity = Binder.clearCallingIdentity();
5350 try {
5351 if (DBG) log("getCallWaitingStatus: subId " + subId);
5352 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
5356 }
5357
5358 /**
5359 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5360 * reason, the number to forward, and the timeout before the forwarding is attempted.
5361 */
5362 @Override
5363 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5364 enforceModifyPermission();
5365 long identity = Binder.clearCallingIdentity();
5366 try {
5367 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5368 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5369 } finally {
5370 Binder.restoreCallingIdentity(identity);
5371 }
5372 }
5373
5374 /**
yinxub1bed742017-04-17 11:45:04 -07005375 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005376 *
yinxub1bed742017-04-17 11:45:04 -07005377 * @param subId id of the subscription
5378 * @param request contains the radio access networks with bands/channels to scan
5379 * @param messenger callback messenger for scan results or errors
5380 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005381 * @return the id of the requested scan which can be used to stop the scan.
5382 */
5383 @Override
5384 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005385 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5387 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005388 LocationAccessPolicy.LocationPermissionResult locationResult =
5389 LocationAccessPolicy.checkLocationPermission(mApp,
5390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5391 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005392 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005393 .setCallingPid(Binder.getCallingPid())
5394 .setCallingUid(Binder.getCallingUid())
5395 .setMethod("requestNetworkScan")
5396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5397 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005398 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005399 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005400 if (e != null) {
5401 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5402 throw e;
5403 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005404 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005405 return TelephonyScanManager.INVALID_SCAN_ID;
5406 }
5407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 }
Hall Liu912dfd32019-04-25 14:02:26 -07005409 int callingUid = Binder.getCallingUid();
5410 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 return mNetworkScanRequestTracker.startNetworkScan(
5414 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005415 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005416 } finally {
5417 Binder.restoreCallingIdentity(identity);
5418 }
yinxu504e1392017-04-12 16:03:22 -07005419 }
5420
Hall Liub2ac8ef2019-02-28 15:56:23 -08005421 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005422 NetworkScanRequest request, int subId) {
5423 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5424 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5425 boolean hasNetworkScanPermission =
5426 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5427 == PERMISSION_GRANTED;
5428
5429 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5430 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5431 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005432 }
5433
5434 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5435 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005436 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5437 return new SecurityException("Specific channels must not be"
5438 + " scanned without location access.");
5439 }
5440 }
5441 }
5442
Hall Liub2ac8ef2019-02-28 15:56:23 -08005443 return null;
5444 }
5445
yinxu504e1392017-04-12 16:03:22 -07005446 /**
5447 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005448 *
5449 * @param subId id of the subscription
5450 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005451 */
5452 @Override
5453 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5455 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456
Hall Liu912dfd32019-04-25 14:02:26 -07005457 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 final long identity = Binder.clearCallingIdentity();
5459 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005460 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
yinxu504e1392017-04-12 16:03:22 -07005464 }
5465
5466 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005467 * Get the calculated preferred network type.
5468 * Used for debugging incorrect network type.
5469 *
5470 * @return the preferred network type, defined in RILConstants.java.
5471 */
5472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005473 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005474 final Phone defaultPhone = getDefaultPhone();
5475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005476 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005477 return RILConstants.PREFERRED_NETWORK_MODE;
5478 }
5479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005483 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
Junda Liu84d15a22014-07-02 11:21:04 -07005487 }
5488
5489 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005490 * Get the preferred network type.
5491 * Used for device configuration by some CDMA operators.
5492 *
5493 * @return the preferred network type, defined in RILConstants.java.
5494 */
5495 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005496 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005497 TelephonyPermissions
5498 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5499 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
5503 if (DBG) log("getPreferredNetworkType");
5504 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5505 int networkType = (result != null ? result[0] : -1);
5506 if (DBG) log("getPreferredNetworkType: " + networkType);
5507 return networkType;
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005511 }
5512
5513 /**
5514 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005515 *
5516 * @param networkType the preferred network type, defined in RILConstants.java.
5517 * @return true on success; false on any failure.
5518 */
5519 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005520 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005526 Settings.Global.putInt(mApp.getContentResolver(),
5527 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005528
5529 Boolean success = (Boolean) sendRequest(
5530 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5531 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5532 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005535 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005536 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005537
5538 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005539 * Get the allowed network types that store in the telephony provider.
5540 *
5541 * @param subId the id of the subscription.
5542 * @return allowedNetworkTypes the allowed network types.
5543 */
5544 @Override
5545 public long getAllowedNetworkTypes(int subId) {
5546 TelephonyPermissions
5547 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5548 mApp, subId, "getAllowedNetworkTypes");
5549
5550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 return SubscriptionManager.getLongSubscriptionProperty(
5553 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
5557 }
5558
5559 /**
5560 * Set the allowed network types.
5561 *
5562 * @param subId the id of the subscription.
5563 * @param allowedNetworkTypes the allowed network types.
5564 * @return true on success; false on any failure.
5565 */
5566 @Override
5567 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5569 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005570
calvinpan8ed33732020-03-12 14:17:55 +08005571 SubscriptionManager.setSubscriptionProperty(subId,
5572 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5573 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005574
calvinpan8ed33732020-03-12 14:17:55 +08005575 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5576 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5577 RILConstants.PREFERRED_NETWORK_MODE);
5578 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005579 }
5580
5581 /**
Miaoa84611c2019-03-15 09:21:10 +08005582 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005583 *
Miaoa84611c2019-03-15 09:21:10 +08005584 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005585 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005586 * @hide
5587 */
5588 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005589 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005592 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 try {
Miaoa84611c2019-03-15 09:21:10 +08005594 if (phone != null) {
5595 return phone.hasMatchedTetherApnSetting();
5596 } else {
5597 return false;
5598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005601 }
Junda Liu475951f2014-11-07 16:45:03 -08005602 }
5603
5604 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005605 * Set mobile data enabled
5606 * Used by the user through settings etc to turn on/off mobile data
5607 *
5608 * @param enable {@code true} turn turn data on, else {@code false}
5609 */
5610 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005611 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 int phoneId = mSubscriptionController.getPhoneId(subId);
5618 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5619 Phone phone = PhoneFactory.getPhone(phoneId);
5620 if (phone != null) {
5621 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005622 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005624 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 }
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005628 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005629 }
5630
5631 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005632 * Enable or disable always reporting signal strength changes from radio.
5633 *
5634 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5635 */
5636 @Override
5637 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5638 enforceModifyPermission();
5639 enforceSystemCaller();
5640
5641 final long identity = Binder.clearCallingIdentity();
5642 final Phone phone = getPhone(subId);
5643 try {
5644 if (phone != null) {
5645 if (DBG) {
5646 log("setAlwaysReportSignalStrength: subId=" + subId
5647 + " isEnable=" + isEnable);
5648 }
5649 phone.setAlwaysReportSignalStrength(isEnable);
5650 } else {
5651 loge("setAlwaysReportSignalStrength: no phone found for subId="
5652 + subId);
5653 }
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
5659 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005660 * Get the user enabled state of Mobile Data.
5661 *
5662 * TODO: remove and use isUserDataEnabled.
5663 * This can't be removed now because some vendor codes
5664 * calls through ITelephony directly while they should
5665 * use TelephonyManager.
5666 *
5667 * @return true on enabled
5668 */
5669 @Override
5670 public boolean getDataEnabled(int subId) {
5671 return isUserDataEnabled(subId);
5672 }
5673
5674 /**
5675 * Get whether mobile data is enabled per user setting.
5676 *
5677 * There are other factors deciding whether mobile data is actually enabled, but they are
5678 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005679 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005680 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005681 *
5682 * @return {@code true} if data is enabled else {@code false}
5683 */
5684 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005685 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005686 try {
5687 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5688 null);
5689 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 int phoneId = mSubscriptionController.getPhoneId(subId);
5697 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5698 Phone phone = PhoneFactory.getPhone(phoneId);
5699 if (phone != null) {
5700 boolean retVal = phone.isUserDataEnabled();
5701 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5702 return retVal;
5703 } else {
5704 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5705 return false;
5706 }
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005709 }
5710 }
5711
5712 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005713 * Checks if the device is capable of mobile data by considering whether whether the
5714 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5715 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005716 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005717 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005718 */
5719 @Override
5720 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005721 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 int phoneId = mSubscriptionController.getPhoneId(subId);
5726 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5727 Phone phone = PhoneFactory.getPhone(phoneId);
5728 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005729 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5731 return retVal;
5732 } else {
5733 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5734 return false;
5735 }
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005738 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005739 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005740
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005741 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005742 Phone phone) {
5743 //load access rules from carrier configs, and check those as well: b/139133814
5744 SubscriptionController subController = SubscriptionController.getInstance();
5745 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5746 || subController == null) return privilegeFromSim;
5747
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005748 PackageManager pkgMgr = phone.getContext().getPackageManager();
5749 String[] packages = pkgMgr.getPackagesForUid(uid);
5750
5751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5754 SubscriptionManager subManager = (SubscriptionManager)
5755 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5756 for (String pkg : packages) {
5757 if (subManager.canManageSubscription(subInfo, pkg)) {
5758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5759 }
5760 }
5761 return privilegeFromSim;
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
5765 }
5766
5767 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5768 String pkgName) {
5769 //load access rules from carrier configs, and check those as well: b/139133814
5770 SubscriptionController subController = SubscriptionController.getInstance();
5771 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5772 || subController == null) return privilegeFromSim;
5773
5774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5777 SubscriptionManager subManager = (SubscriptionManager)
5778 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5779 return subManager.canManageSubscription(subInfo, pkgName)
5780 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
5784 }
5785
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005787 public int getCarrierPrivilegeStatus(int subId) {
5788 final Phone phone = getPhone(subId);
5789 if (phone == null) {
5790 loge("getCarrierPrivilegeStatus: Invalid subId");
5791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5792 }
5793 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005794 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005795 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5797 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005798
5799 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5800 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005801 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005802 }
Junda Liu29340342014-07-10 15:23:27 -07005803
5804 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005805 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005806 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005807 final Phone phone = getPhone(subId);
5808 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005809 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5811 }
5812 UiccProfile profile =
5813 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5814 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005815 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5817 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005818 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005819 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005820 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005821 }
5822
5823 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005824 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5825 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005827 }
5828
5829 int phoneId = SubscriptionManager.getPhoneId(subId);
5830 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005831 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005832 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5834 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005835 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5836 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5837 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005838 }
5839
5840 @Override
5841 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005842 if (TextUtils.isEmpty(pkgName))
5843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005844 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5845 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5846 UiccCard card = UiccController.getInstance().getUiccCard(i);
5847 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005848 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005849 continue;
5850 }
5851
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005852 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5853 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5854 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005855 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5856 break;
5857 }
5858 }
5859
5860 return result;
Junda Liu29340342014-07-10 15:23:27 -07005861 }
Derek Tan89e89d42014-07-08 17:00:10 -07005862
5863 @Override
Junda Liue64de782015-04-16 17:19:16 -07005864 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5865 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5866 loge("phoneId " + phoneId + " is not valid.");
5867 return null;
5868 }
5869 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005870 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005871 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005872 return null ;
5873 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005874 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005875 }
5876
Amith Yamasani6e118872016-02-19 12:53:51 -08005877 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005878 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005879 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005880 List<String> privilegedPackages = new ArrayList<>();
5881 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005882 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5883 // has UICC in that slot.
5884 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005885 if (card.hasCarrierPrivilegeRules()) {
5886 if (packages == null) {
5887 // Only check packages in user 0 for now
5888 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005889 PackageManager.MATCH_DISABLED_COMPONENTS
5890 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005891 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005892 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005893 }
5894 for (int p = packages.size() - 1; p >= 0; p--) {
5895 PackageInfo pkgInfo = packages.get(p);
5896 if (pkgInfo != null && pkgInfo.packageName != null
5897 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005898 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005899 privilegedPackages.add(pkgInfo.packageName);
5900 }
5901 }
5902 }
5903 }
5904 return privilegedPackages;
5905 }
5906
chen xuf7e9fe82019-05-09 19:31:02 -07005907 @Override
5908 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005909 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5910
5911 final long identity = Binder.clearCallingIdentity();
5912
chen xuf7e9fe82019-05-09 19:31:02 -07005913 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005914 try {
5915 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5916 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5917 }
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005920 }
5921 return privilegedPackages;
5922 }
5923
Wink Savilleb564aae2014-10-23 10:18:09 -07005924 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005925 final Phone phone = getPhone(subId);
5926 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005927 if (card == null) {
5928 loge("getIccId: No UICC");
5929 return null;
5930 }
5931 String iccId = card.getIccId();
5932 if (TextUtils.isEmpty(iccId)) {
5933 loge("getIccId: ICC ID is null or empty.");
5934 return null;
5935 }
5936 return iccId;
5937 }
5938
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005939 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005940 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5941 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005942 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005943 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 final String iccId = getIccId(subId);
5948 final Phone phone = getPhone(subId);
5949 if (phone == null) {
5950 return false;
5951 }
5952 final String subscriberId = phone.getSubscriberId();
5953
5954 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005955 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 + subscriberId + " to " + number);
5957 }
5958
5959 if (TextUtils.isEmpty(iccId)) {
5960 return false;
5961 }
5962
5963 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5964
5965 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5966 if (alphaTag == null) {
5967 editor.remove(alphaTagPrefKey);
5968 } else {
5969 editor.putString(alphaTagPrefKey, alphaTag);
5970 }
5971
5972 // Record both the line number and IMSI for this ICCID, since we need to
5973 // track all merged IMSIs based on line number
5974 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5975 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5976 if (number == null) {
5977 editor.remove(numberPrefKey);
5978 editor.remove(subscriberPrefKey);
5979 } else {
5980 editor.putString(numberPrefKey, number);
5981 editor.putString(subscriberPrefKey, subscriberId);
5982 }
5983
5984 editor.commit();
5985 return true;
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005988 }
Derek Tan7226c842014-07-02 17:42:23 -07005989 }
5990
5991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005992 public String getLine1NumberForDisplay(int subId, String callingPackage,
5993 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005994 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005996 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005997 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005998 return null;
5999 }
Derek Tan97ebb422014-09-05 16:55:38 -07006000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 final long identity = Binder.clearCallingIdentity();
6002 try {
6003 String iccId = getIccId(subId);
6004 if (iccId != null) {
6005 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6006 if (DBG_MERGE) {
6007 log("getLine1NumberForDisplay returning "
6008 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6009 }
6010 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6013 return null;
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006016 }
Derek Tan7226c842014-07-02 17:42:23 -07006017 }
6018
6019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006020 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006023 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006024 return null;
6025 }
Derek Tan97ebb422014-09-05 16:55:38 -07006026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 final long identity = Binder.clearCallingIdentity();
6028 try {
6029 String iccId = getIccId(subId);
6030 if (iccId != null) {
6031 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6032 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6033 }
6034 return null;
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006037 }
Derek Tan7226c842014-07-02 17:42:23 -07006038 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006039
6040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006041 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6042 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006043 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6044 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006046 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006047 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006048 return null;
6049 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006050
Jordan Liub49b04b2019-05-06 14:45:15 -07006051 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6052 // the process, where TelephonyManager was instantiated.
6053 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006054 final long identity = Binder.clearCallingIdentity();
6055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006056 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 final TelephonyManager tele = TelephonyManager.from(context);
6058 final SubscriptionManager sub = SubscriptionManager.from(context);
6059
6060 // Figure out what subscribers are currently active
6061 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062
Jordan Liub49b04b2019-05-06 14:45:15 -07006063 // Only consider subs which match the current subId
6064 // This logic can be simplified. See b/131189269 for progress.
6065 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006066 activeSubscriberIds.add(tele.getSubscriberId(subId));
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 // First pass, find a number override for an active subscriber
6070 String mergeNumber = null;
6071 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6072 for (String key : prefs.keySet()) {
6073 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6074 final String subscriberId = (String) prefs.get(key);
6075 if (activeSubscriberIds.contains(subscriberId)) {
6076 final String iccId = key.substring(
6077 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6078 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6079 mergeNumber = (String) prefs.get(numberKey);
6080 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006081 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 + " for active subscriber " + subscriberId);
6083 }
6084 if (!TextUtils.isEmpty(mergeNumber)) {
6085 break;
6086 }
6087 }
6088 }
6089 }
6090
6091 // Shortcut when no active merged subscribers
6092 if (TextUtils.isEmpty(mergeNumber)) {
6093 return null;
6094 }
6095
6096 // Second pass, find all subscribers under that line override
6097 final ArraySet<String> result = new ArraySet<>();
6098 for (String key : prefs.keySet()) {
6099 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6100 final String number = (String) prefs.get(key);
6101 if (mergeNumber.equals(number)) {
6102 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6103 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6104 final String subscriberId = (String) prefs.get(subscriberKey);
6105 if (!TextUtils.isEmpty(subscriberId)) {
6106 result.add(subscriberId);
6107 }
6108 }
6109 }
6110 }
6111
6112 final String[] resultArray = result.toArray(new String[result.size()]);
6113 Arrays.sort(resultArray);
6114 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006115 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6117 }
6118 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006119 } finally {
6120 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006121 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006122 }
6123
6124 @Override
zoey chen38003472019-12-13 17:16:31 +08006125 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6126 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006127
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 final TelephonyManager telephonyManager = mApp.getSystemService(
6131 TelephonyManager.class);
6132 String subscriberId = telephonyManager.getSubscriberId(subId);
6133 if (subscriberId == null) {
6134 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006135 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006136 + subId);
6137 }
6138 return null;
6139 }
6140
6141 final SubscriptionInfo info = SubscriptionController.getInstance()
6142 .getSubscriptionInfo(subId);
6143 final ParcelUuid groupUuid = info.getGroupUuid();
6144 // If it doesn't belong to any group, return just subscriberId of itself.
6145 if (groupUuid == null) {
6146 return new String[]{subscriberId};
6147 }
6148
6149 // Get all subscriberIds from the group.
6150 final List<String> mergedSubscriberIds = new ArrayList<>();
6151 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006152 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006153 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006154 for (SubscriptionInfo subInfo : groupInfos) {
6155 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6156 if (subscriberId != null) {
6157 mergedSubscriberIds.add(subscriberId);
6158 }
6159 }
6160
6161 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164
6165 }
6166 }
6167
6168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006169 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006171 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 final Phone phone = getPhone(subId);
6176 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006180 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006181
6182 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006183 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006184 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6185 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6187 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 final Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 return false;
6194 }
6195 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6196 cdmaNonRoamingList);
6197 } finally {
6198 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006199 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006200 }
6201
6202 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006203 @Deprecated
6204 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6205 enforceModifyPermission();
6206
6207 int returnValue = 0;
6208 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006209 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006210 if(result.exception == null) {
6211 if (result.result != null) {
6212 byte[] responseData = (byte[])(result.result);
6213 if(responseData.length > oemResp.length) {
6214 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6215 responseData.length + "bytes. Buffer Size is " +
6216 oemResp.length + "bytes.");
6217 }
6218 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6219 returnValue = responseData.length;
6220 }
6221 } else {
6222 CommandException ex = (CommandException) result.exception;
6223 returnValue = ex.getCommandError().ordinal();
6224 if(returnValue > 0) returnValue *= -1;
6225 }
6226 } catch (RuntimeException e) {
6227 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6228 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6229 if(returnValue > 0) returnValue *= -1;
6230 }
6231
6232 return returnValue;
6233 }
6234
6235 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006236 public void setRadioCapability(RadioAccessFamily[] rafs) {
6237 try {
6238 ProxyController.getInstance().setRadioCapability(rafs);
6239 } catch (RuntimeException e) {
6240 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6241 }
6242 }
6243
6244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006245 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006246 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006247 try {
6248 TelephonyPermissions
6249 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6250 mApp, phone.getSubId(), "getRadioAccessFamily");
6251 } catch (SecurityException e) {
6252 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6253 throw e;
6254 }
chen xub97461a2018-10-26 14:17:57 -07006255 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006256 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006257 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
chen xub97461a2018-10-26 14:17:57 -07006261 TelephonyPermissions
6262 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6263 mApp, phone.getSubId(), "getRadioAccessFamily");
6264 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
chen xub97461a2018-10-26 14:17:57 -07006268 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006269 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006270
6271 @Override
6272 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006273 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
6277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006278 ImsManager.getInstance(defaultPhone.getContext(),
6279 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006283 }
6284
6285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006286 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6289 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006290 return false;
6291 }
Svet Ganovb320e182015-04-16 12:30:10 -07006292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 // Check the user preference and the system-level IMS setting. Even if the user has
6296 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6297 // In the long run, we may instead need to check if there exists a connection service
6298 // which can support video calling.
6299 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 return imsManager.isVtEnabledByPlatform()
6302 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6303 && imsManager.isVtEnabledByUser();
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
6306 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006307 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006308
Andrew Leea1239f22015-03-02 17:44:07 -08006309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006310 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6311 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006313 mApp, subId, callingPackage, callingFeatureId,
6314 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 return false;
6316 }
6317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 CarrierConfigManager configManager =
6321 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
Andrew Leea1239f22015-03-02 17:44:07 -08006327 }
6328
6329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006330 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006332 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 return false;
6334 }
6335
6336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 CarrierConfigManager configManager =
6339 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006340 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
Andrew Leea1239f22015-03-02 17:44:07 -08006345 }
6346
Andrew Lee9431b832015-03-09 18:46:45 -07006347 @Override
6348 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006349 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006350 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006351 }
6352
6353 @Override
6354 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 final long identity = Binder.clearCallingIdentity();
6356 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Andrew Lee9431b832015-03-09 18:46:45 -07006361 }
6362
Hall Liuf6668912018-10-31 17:05:23 -07006363 /**
6364 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6365 * support for the feature and device firmware support.
6366 *
6367 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6368 */
6369 @Override
6370 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006372 final Phone phone = getPhone(subscriptionId);
6373 if (phone == null) {
6374 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6375 return false;
6376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006378 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6380 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006381 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 return isCarrierSupported && isDeviceSupported;
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
Hall Liu98187582018-01-22 19:15:32 -08006386 }
6387
Hall Liuf6668912018-10-31 17:05:23 -07006388 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006389 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6390 * RTT setting, will return true if the device and carrier both support RTT.
6391 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006392 */
6393 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 final long identity = Binder.clearCallingIdentity();
6395 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006396 boolean isRttSupported = isRttSupported(subscriptionId);
6397 boolean isUserRttSettingOn = Settings.Secure.getInt(
6398 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6399 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6400 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6401 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006405 }
6406
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006407 @Deprecated
6408 @Override
6409 public String getDeviceId(String callingPackage) {
6410 return getDeviceIdWithFeature(callingPackage, null);
6411 }
6412
Sanket Padawe7310cc72015-01-14 09:53:20 -08006413 /**
6414 * Returns the unique device ID of phone, for example, the IMEI for
6415 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6416 *
6417 * <p>Requires Permission:
6418 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6419 */
6420 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006421 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006422 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006423 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006424 return null;
6425 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006426 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006427 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006428 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006429 return null;
6430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 return phone.getDeviceId();
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006438 }
6439
Ping Sunc67b7c22016-03-02 19:16:45 +08006440 /**
6441 * {@hide}
6442 * Returns the IMS Registration Status on a particular subid
6443 *
6444 * @param subId
6445 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006446 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006447 Phone phone = getPhone(subId);
6448 if (phone != null) {
6449 return phone.isImsRegistered();
6450 } else {
6451 return false;
6452 }
6453 }
6454
Santos Cordon7a1885b2015-02-03 11:15:19 -08006455 @Override
6456 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006463 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006464
Tyler Gunnf70ed162019-04-03 15:28:53 -07006465 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006466 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006467 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006469 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006470 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6471 }
6472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
6478 }
6479
6480 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006481 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 Phone phone = getPhone(subscriptionId);
6485 if (phone == null) {
6486 return null;
6487 }
6488 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
6492 }
6493
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006494 /**
6495 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006496 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006497 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 Phone phone = getPhone(subId);
6501 if (phone != null) {
6502 return phone.isWifiCallingEnabled();
6503 } else {
6504 return false;
6505 }
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006508 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006509 }
6510
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006511 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006512 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006513 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006514 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 Phone phone = getPhone(subId);
6518 if (phone != null) {
6519 return phone.isVideoEnabled();
6520 } else {
6521 return false;
6522 }
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006525 }
6526 }
6527
6528 /**
6529 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6530 * defined in {@link ImsRegistrationImplBase}.
6531 */
6532 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 Phone phone = getPhone(subId);
6536 if (phone != null) {
6537 return phone.getImsRegistrationTech();
6538 } else {
6539 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6540 }
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006543 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006544 }
6545
Stuart Scott8eef64f2015-04-08 15:13:54 -07006546 @Override
6547 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006548 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006549 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6550 return;
6551 }
6552
Svet Ganovcc087f82015-05-12 20:35:54 -07006553 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006554
Svet Ganovcc087f82015-05-12 20:35:54 -07006555 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006556 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6557 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006558 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006559 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006560 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006561 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6562 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006563 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006564 // There has been issues when Sms raw table somehow stores orphan
6565 // fragments. They lead to garbled message when new fragments come
6566 // in and combined with those stale ones. In case this happens again,
6567 // user can reset all network settings which will clean up this table.
6568 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006569 // Clean up IMS settings as well here.
6570 int slotId = getSlotIndex(subId);
6571 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6572 ImsManager.getInstance(mApp, slotId).factoryReset();
6573 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006574
6575 // Erase modem config if erase modem on network setting is enabled.
6576 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6577 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6578 if (configValue != null && Boolean.parseBoolean(configValue)) {
6579 sendEraseModemConfig(getDefaultPhone());
6580 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006581 } finally {
6582 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006583 }
6584 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006585
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006586 private void cleanUpSmsRawTable(Context context) {
6587 ContentResolver resolver = context.getContentResolver();
6588 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6589 resolver.delete(uri, null, null);
6590 }
6591
Narayan Kamath1c496c22015-04-16 14:40:19 +01006592 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006593 public String getSimLocaleForSubscriber(int subId) {
6594 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6595 final Phone phone = getPhone(subId);
6596 if (phone == null) {
6597 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006598 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 final long identity = Binder.clearCallingIdentity();
6601 try {
chen xu5d3637b2019-01-21 23:31:38 -08006602 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006603 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006604 if (info == null) {
6605 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6606 return null;
6607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 // Try and fetch the locale from the carrier properties or from the SIM language
6609 // preferences (EF-PL and EF-LI)...
6610 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006612 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6613 if (localeFromDefaultSim != null) {
6614 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6615 if (DBG) log("Using locale from subId: " + subId + " locale: "
6616 + localeFromDefaultSim);
6617 return localeFromDefaultSim.toLanguageTag();
6618 } else {
6619 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 }
6621 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 // The SIM language preferences only store a language (e.g. fr = French), not an
6624 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6625 // the SIM and carrier preferences does not include a country we add the country
6626 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006627 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006629 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 return mccLocale.toLanguageTag();
6631 }
6632
6633 if (DBG) log("No locale found - returning null");
6634 return null;
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006638 }
6639
6640 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006641 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006642 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006643 }
6644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 /**
6646 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6647 */
6648 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006649 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006650 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006651 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006652
Chenjie Yu1ba97252018-01-11 18:16:20 -08006653 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006654 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006655
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006656 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006657 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6658 * representing the state of the modem.
6659 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006660 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6661 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006662 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006663 */
6664 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006665 public void requestModemActivityInfo(ResultReceiver result) {
6666 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006667 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
Shuo Qian1d931ee2020-02-20 17:12:10 -08006671 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 } finally {
6673 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006674 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006675 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006676
Siddharth Rayb8114062018-06-17 15:02:38 -07006677 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6678 // less than total activity duration.
6679 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6680 if (info == null) {
6681 return false;
6682 }
6683 int activityDurationMs =
6684 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6685 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006686 int[] txTimeMs = info.getTransmitTimeMillis();
6687 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6688 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006689 }
6690 return (info.isValid()
6691 && (info.getSleepTimeMillis() <= activityDurationMs)
6692 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006693 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006694 && (totalTxTimeMs <= activityDurationMs));
6695 }
6696
Jack Yu85bd38a2015-11-09 11:34:32 -08006697 /**
6698 * {@hide}
6699 * Returns the service state information on specified subscription.
6700 */
6701 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006702 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6703 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006705 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006706 return null;
6707 }
6708
Hall Liuf19c44f2018-11-27 14:38:17 -08006709 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6710 LocationAccessPolicy.checkLocationPermission(mApp,
6711 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6712 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006713 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006714 .setCallingPid(Binder.getCallingPid())
6715 .setCallingUid(Binder.getCallingUid())
6716 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006717 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006718 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6719 .build());
6720
6721 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6722 LocationAccessPolicy.checkLocationPermission(mApp,
6723 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6724 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006725 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006726 .setCallingPid(Binder.getCallingPid())
6727 .setCallingUid(Binder.getCallingUid())
6728 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006729 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006730 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6731 .build());
6732 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6733 boolean hasFinePermission =
6734 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6735 boolean hasCoarsePermission =
6736 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 final long identity = Binder.clearCallingIdentity();
6739 try {
6740 final Phone phone = getPhone(subId);
6741 if (phone == null) {
6742 return null;
6743 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006744
Hall Liuf19c44f2018-11-27 14:38:17 -08006745 ServiceState ss = phone.getServiceState();
6746
6747 // Scrub out the location info in ServiceState depending on what level of access
6748 // the caller has.
6749 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006750 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6751 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 } finally {
6753 Binder.restoreCallingIdentity(identity);
6754 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006755 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006756
6757 /**
6758 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6759 *
6760 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6761 * voicemail ringtone.
6762 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6763 * PhoneAccount.
6764 */
6765 @Override
6766 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6770 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006771 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006778 }
6779
6780 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006781 * Sets the per-account voicemail ringtone.
6782 *
6783 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6784 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6785 *
6786 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6787 * voicemail ringtone.
6788 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6789 * PhoneAccount.
6790 */
6791 @Override
6792 public void setVoicemailRingtoneUri(String callingPackage,
6793 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006794 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006796 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6797 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6799 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6800 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802
6803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6806 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006807 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 }
6809 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006812 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006813 }
6814
6815 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006816 * Returns whether vibration is set for voicemail notification in Phone settings.
6817 *
6818 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6819 * voicemail vibration setting.
6820 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6821 */
6822 @Override
6823 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 final long identity = Binder.clearCallingIdentity();
6825 try {
6826 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6827 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006828 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006835 }
6836
Youhan Wange64578a2016-05-02 15:32:42 -07006837 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006838 * Sets the per-account voicemail vibration.
6839 *
6840 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6841 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6842 *
6843 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6844 * voicemail vibration setting.
6845 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6846 * specific PhoneAccount.
6847 */
6848 @Override
6849 public void setVoicemailVibrationEnabled(String callingPackage,
6850 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006851 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006853 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6854 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6856 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6857 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006858 }
6859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6863 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006864 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 }
6866 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006869 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006870 }
6871
6872 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006873 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6874 *
6875 * @throws SecurityException if the caller does not have the required permission
6876 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006877 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006878 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006879 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006880 }
6881
6882 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006883 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6884 * permission.
6885 *
6886 * @throws SecurityException if the caller does not have the required permission
6887 */
6888 private void enforceSendSmsPermission() {
6889 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6890 }
6891
6892 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006893 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006894 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006895 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006896 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006897 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 final long identity = Binder.clearCallingIdentity();
6899 try {
6900 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006901 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 if (componentName == null) {
6903 throw new SecurityException(
6904 "Caller not current active visual voicemail package[null]");
6905 }
6906 String vvmPackage = componentName.getPackageName();
6907 if (!callingPackage.equals(vvmPackage)) {
6908 throw new SecurityException("Caller not current active visual voicemail package["
6909 + vvmPackage + "]");
6910 }
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006913 }
6914 }
6915
6916 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006917 * Return the application ID for the app type.
6918 *
6919 * @param subId the subscription ID that this request applies to.
6920 * @param appType the uicc app type.
6921 * @return Application ID for specificied app type, or null if no uicc.
6922 */
6923 @Override
6924 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006925 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006926 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006929 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 if (phone == null) {
6931 return null;
6932 }
6933 String aid = null;
6934 try {
6935 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6936 .getApplicationByType(appType).getAid();
6937 } catch (Exception e) {
6938 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6939 }
6940 return aid;
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006943 }
Youhan Wange64578a2016-05-02 15:32:42 -07006944 }
6945
Youhan Wang4001d252016-05-11 10:29:41 -07006946 /**
6947 * Return the Electronic Serial Number.
6948 *
6949 * @param subId the subscription ID that this request applies to.
6950 * @return ESN or null if error.
6951 */
6952 @Override
6953 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006954 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006955 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956
6957 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006958 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 if (phone == null) {
6960 return null;
6961 }
6962 String esn = null;
6963 try {
6964 esn = phone.getEsn();
6965 } catch (Exception e) {
6966 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6967 }
6968 return esn;
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006971 }
Youhan Wang4001d252016-05-11 10:29:41 -07006972 }
6973
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006974 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006975 * Return the Preferred Roaming List Version.
6976 *
6977 * @param subId the subscription ID that this request applies to.
6978 * @return PRLVersion or null if error.
6979 */
6980 @Override
6981 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006982 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006983 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984
6985 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006986 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 if (phone == null) {
6988 return null;
6989 }
6990 String cdmaPrlVersion = null;
6991 try {
6992 cdmaPrlVersion = phone.getCdmaPrlVersion();
6993 } catch (Exception e) {
6994 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6995 }
6996 return cdmaPrlVersion;
6997 } finally {
6998 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006999 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007000 }
7001
7002 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007003 * Get snapshot of Telephony histograms
7004 * @return List of Telephony histograms
7005 * @hide
7006 */
7007 @Override
7008 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7010 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011
7012 final long identity = Binder.clearCallingIdentity();
7013 try {
7014 return RIL.getTelephonyRILTimingHistograms();
7015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007018 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007019
7020 /**
7021 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007022 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7023 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007024 * Require system privileges. In the future we may add this to carrier APIs.
7025 *
Michele Berionne482f8202018-11-27 18:57:59 -08007026 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007027 */
7028 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007029 @TelephonyManager.SetCarrierRestrictionResult
7030 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007031 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007033
Michele Berionne482f8202018-11-27 18:57:59 -08007034 if (carrierRestrictionRules == null) {
7035 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007036 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 final long identity = Binder.clearCallingIdentity();
7039 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007040 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007041 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007045 }
7046
7047 /**
7048 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007049 * Get the allowed carrier list and the excluded carrier list, including the priority between
7050 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007051 * Require system privileges. In the future we may add this to carrier APIs.
7052 *
Michele Berionne482f8202018-11-27 18:57:59 -08007053 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007054 */
7055 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007056 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007057 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007062 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7063 if (response instanceof CarrierRestrictionRules) {
7064 return (CarrierRestrictionRules) response;
7065 }
7066 // Response is an Exception of some kind,
7067 // which is signalled to the user as a NULL retval
7068 return null;
7069 } catch (Exception e) {
7070 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7071 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007075 }
7076
fionaxu59545b42016-05-25 15:53:37 -07007077 /**
7078 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7079 * @param subId the subscription ID that this action applies to.
7080 * @param enabled control enable or disable metered apns.
7081 * {@hide}
7082 */
7083 @Override
7084 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7085 enforceModifyPermission();
7086 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087
7088 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007089 if (phone == null) {
7090 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7091 return;
7092 }
7093 try {
7094 phone.carrierActionSetMeteredApnsEnabled(enabled);
7095 } catch (Exception e) {
7096 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 } finally {
7098 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007099 }
7100 }
7101
7102 /**
7103 * Action set from carrier signalling broadcast receivers to enable/disable radio
7104 * @param subId the subscription ID that this action applies to.
7105 * @param enabled control enable or disable radio.
7106 * {@hide}
7107 */
7108 @Override
7109 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7110 enforceModifyPermission();
7111 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112
7113 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007114 if (phone == null) {
7115 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7116 return;
7117 }
7118 try {
7119 phone.carrierActionSetRadioEnabled(enabled);
7120 } catch (Exception e) {
7121 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007124 }
7125 }
7126
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007127 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007128 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7129 * network status based on which carrier apps could apply actions accordingly,
7130 * enable/disable default url handler for example.
7131 *
7132 * @param subId the subscription ID that this action applies to.
7133 * @param report control start/stop reporting the default network status.
7134 * {@hide}
7135 */
7136 @Override
7137 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7138 enforceModifyPermission();
7139 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140
7141 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007142 if (phone == null) {
7143 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7144 return;
7145 }
7146 try {
7147 phone.carrierActionReportDefaultNetworkStatus(report);
7148 } catch (Exception e) {
7149 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 } finally {
7151 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007152 }
7153 }
7154
7155 /**
fionaxud9622282017-07-17 17:51:30 -07007156 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7157 * @param subId the subscription ID that this action applies to.
7158 * {@hide}
7159 */
7160 @Override
7161 public void carrierActionResetAll(int subId) {
7162 enforceModifyPermission();
7163 final Phone phone = getPhone(subId);
7164 if (phone == null) {
7165 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7166 return;
7167 }
7168 try {
7169 phone.carrierActionResetAll();
7170 } catch (Exception e) {
7171 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7172 }
7173 }
7174
7175 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007176 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7177 * bug report is being generated.
7178 */
7179 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007180 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007181 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7182 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007183 writer.println("Permission Denial: can't dump Phone from pid="
7184 + Binder.getCallingPid()
7185 + ", uid=" + Binder.getCallingUid()
7186 + "without permission "
7187 + android.Manifest.permission.DUMP);
7188 return;
7189 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007190 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007191 }
Jack Yueb89b242016-06-22 13:27:47 -07007192
Brad Ebingerdac2f002018-04-03 15:17:52 -07007193 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007194 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7195 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7196 @NonNull String[] args) {
7197 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7198 this, in.getFileDescriptor(), out.getFileDescriptor(),
7199 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007200 }
7201
Jack Yueb89b242016-06-22 13:27:47 -07007202 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007203 * Policy control of data connection. Usually used when data limit is passed.
7204 * @param enabled True if enabling the data, otherwise disabling.
7205 * @param subId Subscription index
7206 * {@hide}
7207 */
7208 @Override
7209 public void setPolicyDataEnabled(boolean enabled, int subId) {
7210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 Phone phone = getPhone(subId);
7215 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007216 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 }
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007220 }
7221 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007222
7223 /**
7224 * Get Client request stats
7225 * @return List of Client Request Stats
7226 * @hide
7227 */
7228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007229 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7230 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007232 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007233 return null;
7234 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007235 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 if (phone != null) {
7240 return phone.getClientRequestStats();
7241 }
7242
7243 return null;
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007247 }
7248
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007249 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007250 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007251 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007252 }
Jack Yueb4124c2017-02-16 15:32:43 -08007253
7254 /**
Grace Chen70990072017-03-24 17:21:30 -07007255 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007256 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007257 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007258 * @param state State of SIM (power down, power up, pass through)
7259 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7260 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7261 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007262 *
7263 **/
7264 @Override
Grace Chen70990072017-03-24 17:21:30 -07007265 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007266 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007267 Phone phone = PhoneFactory.getPhone(slotIndex);
7268
vagdeviaf9a5b92018-08-15 16:01:53 -07007269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007274 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 }
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007278 }
7279 }
Shuo Qiandd210312017-04-12 22:11:33 +00007280
Tyler Gunn65d45c22017-06-05 11:22:26 -07007281 private boolean isUssdApiAllowed(int subId) {
7282 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007283 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007284 if (configManager == null) {
7285 return false;
7286 }
7287 PersistableBundle pb = configManager.getConfigForSubId(subId);
7288 if (pb == null) {
7289 return false;
7290 }
7291 return pb.getBoolean(
7292 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7293 }
7294
Shuo Qiandd210312017-04-12 22:11:33 +00007295 /**
7296 * Check if phone is in emergency callback mode
7297 * @return true if phone is in emergency callback mode
7298 * @param subId sub id
7299 */
goneil9c5f4872017-12-05 14:07:56 -08007300 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007301 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007302 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007303 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 if (phone != null) {
7308 return phone.isInEcm();
7309 } else {
7310 return false;
7311 }
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007314 }
7315 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007316
7317 /**
7318 * Get the current signal strength information for the given subscription.
7319 * Because this information is not updated when the device is in a low power state
7320 * it should not be relied-upon to be current.
7321 * @param subId Subscription index
7322 * @return the most recent cached signal strength info from the modem
7323 */
7324 @Override
7325 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 Phone p = getPhone(subId);
7329 if (p == null) {
7330 return null;
7331 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 return p.getSignalStrength();
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
7336 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007337 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007338
Pengquan Meng77b7f132018-08-22 14:49:57 -07007339 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007340 * Get the current modem radio state for the given slot.
7341 * @param slotIndex slot index.
7342 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007344 * @return the current radio power state from the modem
7345 */
7346 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007348 Phone phone = PhoneFactory.getPhone(slotIndex);
7349 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7351 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007352 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7353 }
7354
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
7357 return phone.getRadioPowerState();
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
7361 }
7362 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7363 }
7364
7365 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007366 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7367 *
7368 * <p>Requires one of the following permissions:
7369 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7370 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7371 * privileges.
7372 *
7373 * @param subId subscription id
7374 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7375 * {@code false}.
7376 */
7377 @Override
7378 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007379 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7380 null /* message */);
7381
Pengquan Menga1bb6272018-09-06 09:59:22 -07007382 boolean isEnabled = false;
7383 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007384 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007385 Phone phone = getPhone(subId);
7386 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007387 } catch (Exception e) {
7388 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7389 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007390 } finally {
7391 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007392 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007393 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007394 }
7395
7396
7397 /**
7398 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7399 *
7400 * <p> Requires permission:
7401 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7402 * privileges.
7403 *
7404 * @param subId subscription id
7405 * @param isEnabled {@code true} means enable, {@code false} means disable.
7406 */
7407 @Override
7408 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7410 mApp, subId, "setDataRoamingEnabled");
7411
Pengquan Menga1bb6272018-09-06 09:59:22 -07007412 final long identity = Binder.clearCallingIdentity();
7413 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007414 Phone phone = getPhone(subId);
7415 if (phone != null) {
7416 phone.setDataRoamingEnabled(isEnabled);
7417 }
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007420 }
7421 }
7422
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007423 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007424 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007425 TelephonyPermissions
7426 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007427 mApp, subId, "isManualNetworkSelectionAllowed");
7428
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007429 boolean isAllowed = true;
7430 final long identity = Binder.clearCallingIdentity();
7431 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007432 Phone phone = getPhone(subId);
7433 if (phone != null) {
7434 isAllowed = phone.isCspPlmnEnabled();
7435 }
7436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
7439 return isAllowed;
7440 }
7441
7442 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007443 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007444 // Verify that tha callingPackage belongs to the calling UID
7445 mApp.getSystemService(AppOpsManager.class)
7446 .checkPackage(Binder.getCallingUid(), callingPackage);
7447
Jordan Liu1e142fc2019-04-22 15:10:43 -07007448 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007449 try {
7450 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007451 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007452 } catch (SecurityException e) {
7453 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7454 // has carrier privileges on an active UICC
7455 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7456 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007457 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007458 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007459 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007460
7461 final long identity = Binder.clearCallingIdentity();
7462 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007463 UiccController uiccController = UiccController.getInstance();
7464 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007465 if (hasReadPermission) {
7466 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007467 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007468
7469 // Remove private info if the caller doesn't have access
7470 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7471 for (UiccCardInfo cardInfo : cardInfos) {
7472 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7473 // is available
7474 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7475 if (card == null || card.getUiccProfile() == null) {
7476 // assume no access if the card or profile is unavailable
7477 filteredInfos.add(cardInfo.getUnprivileged());
7478 continue;
7479 }
7480 UiccProfile profile = card.getUiccProfile();
7481 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7482 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7483 filteredInfos.add(cardInfo);
7484 } else {
7485 filteredInfos.add(cardInfo.getUnprivileged());
7486 }
7487 }
7488 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
7492 }
7493
7494 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007495 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007496 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7501 if (slots == null) {
7502 Rlog.i(LOG_TAG, "slots is null.");
7503 return null;
7504 }
7505
7506 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7507 for (int i = 0; i < slots.length; i++) {
7508 UiccSlot slot = slots[i];
7509 if (slot == null) {
7510 continue;
7511 }
7512
Jordan Liu7be7e652019-05-06 18:55:02 +00007513 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 UiccCard card = slot.getUiccCard();
7515 if (card != null) {
7516 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007517 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007518 cardId = slot.getEid();
7519 if (TextUtils.isEmpty(cardId)) {
7520 cardId = slot.getIccId();
7521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 }
7523
Jordan Liu857451f2019-05-09 16:35:35 -07007524 if (cardId != null) {
7525 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7526 // if cardId is an EID, it's all digits so this is fine
7527 cardId = IccUtils.stripTrailingFs(cardId);
7528 }
7529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 int cardState = 0;
7531 switch (slot.getCardState()) {
7532 case CARDSTATE_ABSENT:
7533 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7534 break;
7535 case CARDSTATE_PRESENT:
7536 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7537 break;
7538 case CARDSTATE_ERROR:
7539 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7540 break;
7541 case CARDSTATE_RESTRICTED:
7542 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7543 break;
7544 default:
7545 break;
7546
7547 }
7548
7549 infos[i] = new UiccSlotInfo(
7550 slot.isActive(),
7551 slot.isEuicc(),
7552 cardId,
7553 cardState,
7554 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007555 slot.isExtendedApduSupported(),
7556 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 }
7558 return infos;
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007561 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007562 }
7563
7564 @Override
7565 public boolean switchSlots(int[] physicalSlots) {
7566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567
7568 final long identity = Binder.clearCallingIdentity();
7569 try {
7570 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007574 }
Jack Yu4c988042018-02-27 15:30:01 -08007575
7576 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007577 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 return UiccController.getInstance().getCardIdForDefaultEuicc();
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
7584 }
7585
Pengquan Meng85728fb2018-03-12 16:31:21 -07007586 /**
goneil47ffb6e2018-04-06 15:40:58 -07007587 * A test API to reload the UICC profile.
7588 *
7589 * <p>Requires that the calling app has permission
7590 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7591 * @hide
7592 */
7593 @Override
7594 public void refreshUiccProfile(int subId) {
7595 enforceModifyPermission();
7596
7597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = getPhone(subId);
7600 if (phone == null) {
7601 return;
7602 }
7603 UiccCard uiccCard = phone.getUiccCard();
7604 if (uiccCard == null) {
7605 return;
7606 }
7607 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7608 if (uiccProfile == null) {
7609 return;
7610 }
7611 uiccProfile.refresh();
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
7615 }
7616
7617 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007618 * Returns false if the mobile data is disabled by default, otherwise return true.
7619 */
7620 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007621 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007622 }
7623
7624 /**
7625 * Returns true if the data roaming is enabled by default, i.e the system property
7626 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7627 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7628 */
7629 private boolean getDefaultDataRoamingEnabled(int subId) {
7630 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007631 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007632 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007633 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7634 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7635 return isDataRoamingEnabled;
7636 }
7637
7638 /**
7639 * Returns the default network type for the given {@code subId}, if the default network type is
7640 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7641 */
7642 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007643 List<Integer> list = TelephonyProperties.default_network();
7644 int phoneId = mSubscriptionController.getPhoneId(subId);
7645 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7646 return list.get(phoneId);
7647 }
7648 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007649 }
fionaxua13278b2018-03-21 00:08:13 -07007650
7651 @Override
7652 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007653 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655
7656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 final Phone phone = getPhone(subId);
7659 if (phone == null) {
7660 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7661 return;
7662 }
chen xueaba88a2019-03-15 13:15:10 -07007663 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7664 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 } finally {
7666 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007667 }
fionaxua13278b2018-03-21 00:08:13 -07007668 }
7669
7670 @Override
7671 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007672 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 final Phone phone = getPhone(subId);
7677 if (phone == null) {
7678 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7679 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7680 }
7681 return phone.getCarrierIdListVersion();
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007684 }
fionaxua13278b2018-03-21 00:08:13 -07007685 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007686
7687 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007688 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7689 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007691 mApp, subId, callingPackage, callingFeatureId,
7692 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007693 return -1;
7694 }
7695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
7702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007703
7704 @Override
7705 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007706 TelephonyPermissions
7707 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007708 mApp, subId, "getCdmaRoamingMode");
7709
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
7716 }
7717
7718 @Override
7719 public boolean setCdmaRoamingMode(int subId, int mode) {
7720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7721 mApp, subId, "setCdmaRoamingMode");
7722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
7729 }
7730
7731 @Override
7732 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7734 mApp, subId, "setCdmaSubscriptionMode");
7735
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7739 } finally {
7740 Binder.restoreCallingIdentity(identity);
7741 }
7742 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007743
sqianc5eccab2018-10-19 18:46:41 -07007744 @Override
sqian8c685422019-02-22 15:55:18 -08007745 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007746 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007748 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7749 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007750 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7751 }
7752 final long identity = Binder.clearCallingIdentity();
7753 try {
sqian854d44b2018-12-12 16:48:18 -08007754 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7755 for (Phone phone: PhoneFactory.getPhones()) {
7756 if (phone.getEmergencyNumberTracker() != null
7757 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7758 emergencyNumberListInternal.put(
7759 phone.getSubId(),
7760 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7761 }
sqian11b7a0e2018-12-05 18:48:28 -08007762 }
sqian854d44b2018-12-12 16:48:18 -08007763 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
sqianc5eccab2018-10-19 18:46:41 -07007767 }
7768
7769 @Override
sqian8c685422019-02-22 15:55:18 -08007770 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007771 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007772 if (!exactMatch) {
7773 TelephonyPermissions
7774 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007775 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007776 }
7777 final long identity = Binder.clearCallingIdentity();
7778 try {
sqian854d44b2018-12-12 16:48:18 -08007779 for (Phone phone: PhoneFactory.getPhones()) {
7780 if (phone.getEmergencyNumberTracker() != null
7781 && phone.getEmergencyNumberTracker() != null) {
7782 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7783 number, exactMatch)) {
7784 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007785 }
7786 }
sqian11b7a0e2018-12-05 18:48:28 -08007787 }
7788 return false;
7789 } finally {
7790 Binder.restoreCallingIdentity(identity);
7791 }
7792 }
7793
sqianf4ca7ed2019-01-15 18:32:07 -08007794 /**
7795 * Update emergency number list for test mode.
7796 */
7797 @Override
7798 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7799 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7800 "updateEmergencyNumberListTestMode");
7801
7802 final long identity = Binder.clearCallingIdentity();
7803 try {
7804 for (Phone phone: PhoneFactory.getPhones()) {
7805 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7806 if (tracker != null) {
7807 tracker.executeEmergencyNumberTestModeCommand(action, num);
7808 }
7809 }
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
7812 }
7813 }
7814
7815 /**
7816 * Get the full emergency number list for test mode.
7817 */
7818 @Override
7819 public List<String> getEmergencyNumberListTestMode() {
7820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7821 "getEmergencyNumberListTestMode");
7822
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 Set<String> emergencyNumbers = new HashSet<>();
7826 for (Phone phone: PhoneFactory.getPhones()) {
7827 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7828 if (tracker != null) {
7829 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7830 emergencyNumbers.add(num.getNumber());
7831 }
7832 }
7833 }
7834 return new ArrayList<>(emergencyNumbers);
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
7839
chen xud6b45bd2018-10-30 22:27:10 -07007840 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007841 public int getEmergencyNumberDbVersion(int subId) {
7842 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7843
7844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 final Phone phone = getPhone(subId);
7847 if (phone == null) {
7848 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7849 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7850 }
7851 return phone.getEmergencyNumberDbVersion();
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
7854 }
7855 }
7856
7857 @Override
7858 public void notifyOtaEmergencyNumberDbInstalled() {
7859 enforceModifyPermission();
7860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 for (Phone phone: PhoneFactory.getPhones()) {
7864 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7865 if (tracker != null) {
7866 tracker.updateOtaEmergencyNumberDatabase();
7867 }
7868 }
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
7872 }
7873
7874 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007875 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007876 enforceActiveEmergencySessionPermission();
7877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 for (Phone phone: PhoneFactory.getPhones()) {
7881 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7882 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007883 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7884 }
7885 }
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
7888 }
7889 }
7890
7891 @Override
7892 public void resetOtaEmergencyNumberDbFilePath() {
7893 enforceActiveEmergencySessionPermission();
7894
7895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 for (Phone phone: PhoneFactory.getPhones()) {
7898 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7899 if (tracker != null) {
7900 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007901 }
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
7906 }
7907
7908 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007909 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7910 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7911 Phone phone = getPhone(subId);
7912 if (phone == null) {
7913 return null;
7914 }
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 UiccProfile profile = UiccController.getInstance()
7918 .getUiccProfileForPhone(phone.getPhoneId());
7919 if (profile != null) {
7920 return profile.getCertsFromCarrierPrivilegeAccessRules();
7921 }
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
7925 return null;
7926 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007927
7928 /**
7929 * Enable or disable a modem stack.
7930 */
7931 @Override
7932 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7933 enforceModifyPermission();
7934
7935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 Phone phone = PhoneFactory.getPhone(slotIndex);
7938 if (phone == null) {
7939 return false;
7940 } else {
7941 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7942 }
7943 } finally {
7944 Binder.restoreCallingIdentity(identity);
7945 }
7946 }
Michelecea4cf22018-12-21 15:00:11 -08007947
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007948 /**
7949 * Whether a modem stack is enabled or not.
7950 */
7951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007952 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7953 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007954 Phone phone = PhoneFactory.getPhone(slotIndex);
7955 if (phone == null) return false;
7956
7957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007958 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7959 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007960 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7961 }
7962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007965 try {
7966 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7967 } catch (NoSuchElementException ex) {
7968 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7969 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
7973 }
7974
Michelecea4cf22018-12-21 15:00:11 -08007975 @Override
Michele0ea7d782019-03-19 14:58:42 -07007976 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007977 enforceModifyPermission();
7978
7979 final long identity = Binder.clearCallingIdentity();
7980 try {
7981 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007982 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007983 .commit();
7984 } finally {
7985 Binder.restoreCallingIdentity(identity);
7986 }
7987 }
7988
7989 @Override
Michele0ea7d782019-03-19 14:58:42 -07007990 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007991 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007993 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7994 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007995 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007996 }
Michelecea4cf22018-12-21 15:00:11 -08007997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
Michele0ea7d782019-03-19 14:58:42 -07008000 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008001 } finally {
8002 Binder.restoreCallingIdentity(identity);
8003 }
8004 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008005
Michele0ea7d782019-03-19 14:58:42 -07008006 @TelephonyManager.IsMultiSimSupportedResult
8007 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008008 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8009 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8010 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008011 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8012 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008013 }
8014 // Check if the hardware supports multisim functionality. If usage of multisim is not
8015 // supported by the modem, indicate that it is restricted.
8016 PhoneCapability staticCapability =
8017 mPhoneConfigurationManager.getStaticPhoneCapability();
8018 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008019 loge("isMultiSimSupportedInternal: no static configuration available");
8020 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008021 }
Sarah Chin7caee492020-02-18 20:49:02 +00008022 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008023 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8024 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008025 }
8026 // Check if support of multiple SIMs is restricted by carrier
8027 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008028 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008029 }
8030
Michele0ea7d782019-03-19 14:58:42 -07008031 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008032 }
8033
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008034 /**
8035 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008036 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8037 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8038 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008039 * @param numOfSims number of active sims we want to switch to
8040 */
8041 @Override
8042 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008043 if (numOfSims == 1) {
8044 enforceModifyPermission();
8045 } else {
8046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8047 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8048 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008049 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008050
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008051 try {
Michele30b57b22019-03-01 12:01:14 -08008052 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008053 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008054 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8055 return;
8056 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008057 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
8061 }
8062
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008063 @Override
8064 public boolean isApplicationOnUicc(int subId, int appType) {
8065 enforceReadPrivilegedPermission("isApplicationOnUicc");
8066 Phone phone = getPhone(subId);
8067 if (phone == null) {
8068 return false;
8069 }
8070 final long identity = Binder.clearCallingIdentity();
8071 try {
8072 UiccCard uiccCard = phone.getUiccCard();
8073 if (uiccCard == null) {
8074 return false;
8075 }
8076 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8077 if (uiccProfile == null) {
8078 return false;
8079 }
8080 if (TelephonyManager.APPTYPE_SIM <= appType
8081 && appType <= TelephonyManager.APPTYPE_ISIM) {
8082 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8083 }
8084 return false;
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
8089
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008090 /**
chen xub4baa772019-04-03 10:23:41 -07008091 * Get whether making changes to modem configurations will trigger reboot.
8092 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008093 */
8094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008095 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8096 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008098 mApp, subId, callingPackage, callingFeatureId,
8099 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008100 return false;
8101 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008102 final long identity = Binder.clearCallingIdentity();
8103 try {
8104 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
8108 }
8109
Nathan Harold29f5f052019-02-15 13:41:57 -08008110 private void updateModemStateMetrics() {
8111 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8112 // TODO: check the state for each modem if the api is ready.
8113 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8114 }
8115
Pengquan Meng3889a572019-01-23 11:16:29 -08008116 @Override
8117 public int[] getSlotsMapping() {
8118 enforceReadPrivilegedPermission("getSlotsMapping");
8119
8120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8123 // All logical slots should have a mapping to a physical slot.
8124 int[] logicalSlotsMapping = new int[phoneCount];
8125 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8126 for (int i = 0; i < slotInfos.length; i++) {
8127 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8128 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8129 }
8130 }
8131 return logicalSlotsMapping;
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
8135 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008136
8137 /**
8138 * Get the IRadio HAL Version
8139 */
8140 @Override
8141 public int getRadioHalVersion() {
8142 Phone phone = getDefaultPhone();
8143 if (phone == null) return -1;
8144 HalVersion hv = phone.getHalVersion();
8145 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8146 return hv.major * 100 + hv.minor;
8147 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008148
8149 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008150 * Get the current calling package name.
8151 * @return the current calling package name
8152 */
8153 @Override
8154 public String getCurrentPackageName() {
8155 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8156 }
8157
8158 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008159 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8160 * corresponding network requests on a subId.
8161 *
8162 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008163 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008164 * 2) APN is un-metered for this subscription, or
8165 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008166 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008167 *
8168 * @return whether data is allowed for a apn type.
8169 *
8170 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008171 */
8172 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008173 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008174 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8175 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008176
8177 // Now that all security checks passes, perform the operation as ourselves.
8178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 Phone phone = getPhone(subId);
8181 if (phone == null) return false;
8182
Jack Yu41407ee2019-05-13 16:54:09 -07008183 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008184 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
8188 }
8189
8190 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008191 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008192 enforceReadPrivilegedPermission("isApnMetered");
8193
8194 // Now that all security checks passes, perform the operation as ourselves.
8195 final long identity = Binder.clearCallingIdentity();
8196 try {
8197 Phone phone = getPhone(subId);
8198 if (phone == null) return true; // By default return true.
8199
Jack Yu41407ee2019-05-13 16:54:09 -07008200 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
8204 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008205
8206 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008207 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8208 int subscriptionId, IBooleanConsumer resultCallback) {
8209 enforceModifyPermission();
8210 long token = Binder.clearCallingIdentity();
8211 try {
8212 Phone phone = getPhone(subscriptionId);
8213 if (phone == null) {
8214 try {
8215 if (resultCallback != null) {
8216 resultCallback.accept(false);
8217 }
8218 } catch (RemoteException e) {
8219 // ignore
8220 }
8221 return;
8222 }
8223 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8224 Pair.create(specifiers, (x) -> {
8225 try {
8226 if (resultCallback != null) {
8227 resultCallback.accept(x);
8228 }
8229 } catch (RemoteException e) {
8230 // ignore
8231 }
8232 });
8233 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8234 } finally {
8235 Binder.restoreCallingIdentity(token);
8236 }
8237 }
8238
8239 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008240 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008241 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008242 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8243 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8244 if (iccRecords == null) {
8245 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8246 return false;
8247 }
8248 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8249 }
8250
8251 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008252 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8253 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008254 if (callingPackage == null) {
8255 callingPackage = getCurrentPackageName();
8256 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008257 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8258 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008259 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8260 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008261 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8262 }
8263 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8264 Intent intent = new Intent();
8265 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8266 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8267 // Bring up choose default SMS subscription dialog right now
8268 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8269 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8270 mApp.startActivity(intent);
8271 }
chen xud5ca2d52019-05-28 15:20:57 -07008272
8273 @Override
8274 public String getMmsUAProfUrl(int subId) {
8275 //TODO investigate if this API should require proper permission check in R b/133791609
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008278 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8279 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
8283 }
8284
8285 @Override
8286 public String getMmsUserAgent(int subId) {
8287 //TODO investigate if this API should require proper permission check in R b/133791609
8288 final long identity = Binder.clearCallingIdentity();
8289 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008290 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8291 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
8295 }
Jack Yub07d4972019-05-28 16:12:25 -07008296
8297 @Override
8298 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8299 enforceModifyPermission();
8300
8301 // Now that all security checks passes, perform the operation as ourselves.
8302 final long identity = Binder.clearCallingIdentity();
8303 try {
8304 Phone phone = getPhone(subId);
8305 if (phone == null) return false;
8306
8307 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
8313 @Override
8314 public boolean isDataAllowedInVoiceCall(int subId) {
8315 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8316
8317 // Now that all security checks passes, perform the operation as ourselves.
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 Phone phone = getPhone(subId);
8321 if (phone == null) return false;
8322
8323 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008328
changbettyd5c246e2019-12-24 15:40:37 +08008329 @Override
8330 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8331 enforceModifyPermission();
8332
8333 // Now that all security checks passes, perform the operation as ourselves.
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = getPhone(subId);
8337 if (phone == null) return false;
8338
8339 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008345 /**
8346 * Updates whether conference event pacakge handling is enabled.
8347 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8348 * otherwise.
8349 */
8350 @Override
8351 public void setCepEnabled(boolean isCepEnabled) {
8352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8353
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8357 for (Phone phone : PhoneFactory.getPhones()) {
8358 Phone defaultPhone = phone.getImsPhone();
8359 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8360 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8361 ImsPhoneCallTracker imsPhoneCallTracker =
8362 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8363 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8364 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8365 + imsPhone.getMsisdn());
8366 }
8367 }
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
allenwtsu46dcc572020-01-08 18:24:03 +08008372
8373 /**
8374 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8375 *
8376 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8377 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8378 * before being read.
8379 */
8380 @Override
8381 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8382 isCompressed) {
8383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8384 mApp, subId, "notifyRcsAutoConfigurationReceived");
8385 try {
8386 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8387 if (configBinder == null) {
8388 Rlog.e(LOG_TAG, "null result for getImsConfig");
8389 } else {
8390 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8391 }
8392 } catch (RemoteException e) {
8393 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8394 }
8395 }
zoey chene02881a2019-12-30 16:11:23 +08008396
8397 @Override
8398 public boolean isIccLockEnabled(int subId) {
8399 enforceReadPrivilegedPermission("isIccLockEnabled");
8400
8401 // Now that all security checks passes, perform the operation as ourselves.
8402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 Phone phone = getPhone(subId);
8405 if (phone != null && phone.getIccCard() != null) {
8406 return phone.getIccCard().getIccLockEnabled();
8407 } else {
8408 return false;
8409 }
8410 } finally {
8411 Binder.restoreCallingIdentity(identity);
8412 }
8413 }
8414
8415 /**
8416 * Set the ICC pin lock enabled or disabled.
8417 *
8418 * @return an integer representing the status of IccLock enabled or disabled in the following
8419 * three cases:
8420 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8421 * successfully.
8422 * - Positive number and zero for remaining password attempts.
8423 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8424 *
8425 */
8426 @Override
8427 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8428 enforceModifyPermission();
8429
8430 Phone phone = getPhone(subId);
8431 if (phone == null) {
8432 return 0;
8433 }
8434 // Now that all security checks passes, perform the operation as ourselves.
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8438 new Pair<Boolean, String>(enabled, password), phone, null);
8439 return attemptsRemaining;
8440
8441 } catch (Exception e) {
8442 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 return 0;
8447 }
8448
8449 /**
8450 * Change the ICC password used in ICC pin lock.
8451 *
8452 * @return an integer representing the status of IccLock changed in the following three cases:
8453 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8454 * - Positive number and zero for remaining password attempts.
8455 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8456 *
8457 */
8458 @Override
8459 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8460 enforceModifyPermission();
8461
8462 Phone phone = getPhone(subId);
8463 if (phone == null) {
8464 return 0;
8465 }
8466 // Now that all security checks passes, perform the operation as ourselves.
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8470 new Pair<String, String>(oldPassword, newPassword), phone, null);
8471 return attemptsRemaining;
8472
8473 } catch (Exception e) {
8474 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 return 0;
8479 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008480
8481 /**
8482 * Request for receiving user activity notification
8483 */
8484 @Override
8485 public void requestUserActivityNotification() {
8486 if (!mNotifyUserActivity.get()
8487 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8488 mNotifyUserActivity.set(true);
8489 }
8490 }
8491
8492 /**
8493 * Called when userActivity is signalled in the power manager.
8494 * This is safe to call from any thread, with any window manager locks held or not.
8495 */
8496 @Override
8497 public void userActivity() {
8498 // ***************************************
8499 // * Inherited from PhoneWindowManager *
8500 // ***************************************
8501 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8502 // WITH ITS LOCKS HELD.
8503 //
8504 // This code must be VERY careful about the locks
8505 // it acquires.
8506 // In fact, the current code acquires way too many,
8507 // and probably has lurking deadlocks.
8508
8509 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8510 throw new SecurityException("Only the OS may call notifyUserActivity()");
8511 }
8512
8513 if (mNotifyUserActivity.getAndSet(false)) {
8514 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8515 USER_ACTIVITY_NOTIFICATION_DELAY);
8516 }
8517 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008518
8519 @Override
8520 public boolean canConnectTo5GInDsdsMode() {
8521 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008523}