blob: 5e34fac9baa314319c2a28379be3b926e4a65c36 [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;
changbetty363e8ac2019-12-06 18:16:37 +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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
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 Ebinger774ba362019-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 Ebinger77b832e2019-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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192/**
193 * Implementation of the ITelephony interface.
194 */
Santos Cordon117fee72014-05-16 17:56:12 -0700195public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 private static final String LOG_TAG = "PhoneInterfaceManager";
197 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
198 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800199 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200
201 // Message codes used with mMainThreadHandler
202 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700203 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
204 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205 private static final int CMD_OPEN_CHANNEL = 9;
206 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
207 private static final int CMD_CLOSE_CHANNEL = 11;
208 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800209 private static final int CMD_NV_READ_ITEM = 13;
210 private static final int EVENT_NV_READ_ITEM_DONE = 14;
211 private static final int CMD_NV_WRITE_ITEM = 15;
212 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
213 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
214 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700215 private static final int CMD_RESET_MODEM_CONFIG = 19;
216 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800217 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
218 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
219 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
220 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800221 private static final int CMD_SEND_ENVELOPE = 25;
222 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000223 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
224 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700225 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
226 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
227 private static final int CMD_EXCHANGE_SIM_IO = 31;
228 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800229 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
230 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700231 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700233 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
234 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700235 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
236 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
237 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700239 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
240 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
241 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
242 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700243 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800244 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
245 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246 private static final int CMD_SWITCH_SLOTS = 50;
247 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700248 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
249 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
250 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
251 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
252 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
253 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
254 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
255 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700256 private static final int CMD_GET_ALL_CELL_INFO = 60;
257 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
258 private static final int CMD_GET_CELL_LOCATION = 62;
259 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700260 private static final int CMD_MODEM_REBOOT = 64;
261 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700262 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
263 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800264 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
265 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700266 private static final int CMD_GET_MODEM_STATUS = 70;
267 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700268 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
269 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700270 private static final int CMD_ERASE_MODEM_CONFIG = 74;
271 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800272 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
273 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
274 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
275 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
sqian80370722020-01-29 15:02:51 -0800276 private static final int CMD_GET_CALL_FORWARDING = 83;
277 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
278 private static final int CMD_SET_CALL_FORWARDING = 85;
279 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
280 private static final int CMD_GET_CALL_WAITING = 87;
281 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
282 private static final int CMD_SET_CALL_WAITING = 89;
283 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800285 // Parameters of select command.
286 private static final int SELECT_COMMAND = 0xA4;
287 private static final int SELECT_P1 = 0x04;
288 private static final int SELECT_P2 = 0;
289 private static final int SELECT_P3 = 0x10;
290
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 /** The singleton instance. */
292 private static PhoneInterfaceManager sInstance;
293
Wink Saville3ab207e2014-11-20 13:07:20 -0800294 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800296 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700297 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private AppOpsManager mAppOps;
299 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800300 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700302 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
Derek Tan97ebb422014-09-05 16:55:38 -0700304 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
305 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800306 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800307 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700308
Michelecea4cf22018-12-21 15:00:11 -0800309 // String to store multi SIM allowed
310 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
311
Derek Tan740e1672017-06-27 14:56:27 -0700312 // The AID of ISD-R.
313 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
314
yinxub1bed742017-04-17 11:45:04 -0700315 private NetworkScanRequestTracker mNetworkScanRequestTracker;
316
David Kelly5e06a7f2018-03-12 14:10:59 +0000317 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
318 private static final int MANUFACTURER_CODE_LENGTH = 8;
319
Derek Tan89e89d42014-07-08 17:00:10 -0700320 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700321 * Experiment flag to enable erase modem config on reset network, default value is false
322 */
323 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
324 "reset_network_erase_modem_config_enabled";
325
326 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700327 * A request object to use for transmitting data to an ICC.
328 */
329 private static final class IccAPDUArgument {
330 public int channel, cla, command, p1, p2, p3;
331 public String data;
332
333 public IccAPDUArgument(int channel, int cla, int command,
334 int p1, int p2, int p3, String data) {
335 this.channel = channel;
336 this.cla = cla;
337 this.command = command;
338 this.p1 = p1;
339 this.p2 = p2;
340 this.p3 = p3;
341 this.data = data;
342 }
343 }
344
345 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700346 * A request object to use for transmitting data to an ICC.
347 */
348 private static final class ManualNetworkSelectionArgument {
349 public OperatorInfo operatorInfo;
350 public boolean persistSelection;
351
352 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
353 this.operatorInfo = operatorInfo;
354 this.persistSelection = persistSelection;
355 }
356 }
357
358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
360 * request after sending. The main thread will notify the request when it is complete.
361 */
362 private static final class MainThreadRequest {
363 /** The argument to use for the request */
364 public Object argument;
365 /** The result of the request that is run on the main thread */
366 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800367 // The subscriber id that this request applies to. Defaults to
368 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
369 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Nathan Harold92bed182018-10-12 18:16:49 -0700371 // In cases where subId is unavailable, the caller needs to specify the phone.
372 public Phone phone;
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 public WorkSource workSource;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 public MainThreadRequest(Object argument) {
377 this.argument = argument;
378 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379
Nathan Harold92bed182018-10-12 18:16:49 -0700380 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
381 this.argument = argument;
382 if (phone != null) {
383 this.phone = phone;
384 }
385 this.workSource = workSource;
386 }
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800389 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800390 if (subId != null) {
391 this.subId = subId;
392 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 }
396
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800397 private static final class IncomingThirdPartyCallArgs {
398 public final ComponentName component;
399 public final String callId;
400 public final String callerDisplayName;
401
402 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
403 String callerDisplayName) {
404 this.component = component;
405 this.callId = callId;
406 this.callerDisplayName = callerDisplayName;
407 }
408 }
409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /**
411 * A handler that processes messages on the main thread in the phone process. Since many
412 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
413 * inbound binder threads to the main thread in the phone process. The Binder thread
414 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
415 * on, which will be notified when the operation completes and will contain the result of the
416 * request.
417 *
418 * <p>If a MainThreadRequest object is provided in the msg.obj field,
419 * note that request.result must be set to something non-null for the calling thread to
420 * unblock.
421 */
422 private final class MainThreadHandler extends Handler {
423 @Override
424 public void handleMessage(Message msg) {
425 MainThreadRequest request;
426 Message onCompleted;
427 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800428 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800430 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
432 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 case CMD_HANDLE_USSD_REQUEST: {
434 request = (MainThreadRequest) msg.obj;
435 final Phone phone = getPhoneFromRequest(request);
436 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
437 String ussdRequest = ussdObject.first;
438 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 if (!isUssdApiAllowed(request.subId)) {
441 // Carrier does not support use of this API, return failure.
442 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
443 UssdResponse response = new UssdResponse(ussdRequest, null);
444 Bundle returnData = new Bundle();
445 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
446 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700447
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 request.result = true;
449 notifyRequester(request);
450 return;
451 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 try {
454 request.result = phone != null
455 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
456 } catch (CallStateException cse) {
457 request.result = false;
458 }
459 // Wake up the requesting thread
460 notifyRequester(request);
461 break;
pkanwar32d516d2016-10-14 19:37:38 -0700462 }
463
Yorke Lee716f67e2015-06-17 15:39:16 -0700464 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700466 final Phone phone = getPhoneFromRequest(request);
467 request.result = phone != null ?
468 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
469 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduLogicalChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700483 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
485 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 iccArgument.channel, iccArgument.cla, iccArgument.command,
488 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 break;
492
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 ar = (AsyncResult) msg.obj;
495 request = (MainThreadRequest) ar.userObj;
496 if (ar.exception == null && ar.result != null) {
497 request.result = ar.result;
498 } else {
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 if (ar.result == null) {
501 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800502 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800504 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 } else {
506 loge("iccTransmitApduLogicalChannel: Unknown exception");
507 }
508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 break;
511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccTransmitApduBasicChannel: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 } else {
521 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
522 request);
523 uiccCard.iccTransmitApduBasicChannel(
524 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
525 iccArgument.p3, iccArgument.data, onCompleted);
526 }
527 break;
528
529 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
534 } else {
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("iccTransmitApduBasicChannel: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("iccTransmitApduBasicChannel: CommandException: " +
540 ar.exception);
541 } else {
542 loge("iccTransmitApduBasicChannel: Unknown exception");
543 }
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 break;
547
548 case CMD_EXCHANGE_SIM_IO:
549 request = (MainThreadRequest) msg.obj;
550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (uiccCard == null) {
553 loge("iccExchangeSimIO: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
558 request);
559 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
560 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
561 iccArgument.data, onCompleted);
562 }
563 break;
564
565 case EVENT_EXCHANGE_SIM_IO_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6f, 0, (byte[])null);
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 break;
575
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 case CMD_SEND_ENVELOPE:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("sendEnvelopeWithStatus: No UICC");
581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
585 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 break;
588
589 case EVENT_SEND_ENVELOPE_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
596 if (ar.result == null) {
597 loge("sendEnvelopeWithStatus: Empty response");
598 } else if (ar.exception instanceof CommandException) {
599 loge("sendEnvelopeWithStatus: CommandException: " +
600 ar.exception);
601 } else {
602 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
603 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 break;
607
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 case CMD_OPEN_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800611 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800614 request.result = new IccOpenLogicalChannelResponse(-1,
615 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800619 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
620 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_OPEN_CHANNEL_DONE:
625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 int[] result = (int[]) ar.result;
630 int channelId = result[0];
631 byte[] selectResponse = null;
632 if (result.length > 1) {
633 selectResponse = new byte[result.length - 1];
634 for (int i = 1; i < result.length; ++i) {
635 selectResponse[i - 1] = (byte) result[i];
636 }
637 }
638 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 if (ar.result == null) {
642 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 if (ar.exception != null) {
645 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
646 }
647
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700648 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700649 if (ar.exception instanceof CommandException) {
650 CommandException.Error error =
651 ((CommandException) (ar.exception)).getCommandError();
652 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700654 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 }
657 }
658 openChannelResp = new IccOpenLogicalChannelResponse(
659 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700661 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case CMD_CLOSE_CHANNEL:
666 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800667 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 if (uiccCard == null) {
669 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900670 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
674 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800679 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
680 break;
681
682 case CMD_NV_READ_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
686 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800695 request.result = "";
696 if (ar.result == null) {
697 loge("nvReadItem: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("nvReadItem: CommandException: " +
700 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800702 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 break;
707
Jake Hambye994d462014-02-03 13:10:13 -0800708 case CMD_NV_WRITE_ITEM:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
711 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800712 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700713 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
716 case EVENT_NV_WRITE_ITEM_DONE:
717 handleNullReturnEvent(msg, "nvWriteItem");
718 break;
719
720 case CMD_NV_WRITE_CDMA_PRL:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
726 case EVENT_NV_WRITE_CDMA_PRL_DONE:
727 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
728 break;
729
chen xu6dac5ab2018-10-26 17:39:23 -0700730 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800731 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700732 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case EVENT_RESET_MODEM_CONFIG_DONE:
737 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 case CMD_GET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 if (ar.exception == null && ar.result != null) {
750 request.result = ar.result; // Integer
751 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800752 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 if (ar.result == null) {
754 loge("getPreferredNetworkType: Empty response");
755 } else if (ar.exception instanceof CommandException) {
756 loge("getPreferredNetworkType: CommandException: " +
757 ar.exception);
758 } else {
759 loge("getPreferredNetworkType: Unknown exception");
760 }
761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800763 break;
764
765 case CMD_SET_PREFERRED_NETWORK_TYPE:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
768 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700769 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800770 break;
771
772 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
773 handleNullReturnEvent(msg, "setPreferredNetworkType");
774 break;
775
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000776 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
777 request = (MainThreadRequest)msg.obj;
778 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000780 break;
781
782 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
783 ar = (AsyncResult)msg.obj;
784 request = (MainThreadRequest)ar.userObj;
785 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 break;
788
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800789 case CMD_SET_VOICEMAIL_NUMBER:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
792 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800793 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
794 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800795 break;
796
797 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
798 handleNullReturnEvent(msg, "setVoicemailNumber");
799 break;
800
Stuart Scott54788802015-03-30 13:18:01 -0700801 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
804 request);
805 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
806 break;
807
808 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
809 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
810 break;
811
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 case CMD_PERFORM_NETWORK_SCAN:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
815 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
816 break;
817
sqian80370722020-01-29 15:02:51 -0800818 case CMD_GET_CALL_FORWARDING:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
821 int callForwardingReason = (Integer) request.argument;
822 getPhoneFromRequest(request).getCallForwardingOption(
823 callForwardingReason, onCompleted);
824 break;
825
826 case EVENT_GET_CALL_FORWARDING_DONE:
827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 CallForwardingInfo callForwardingInfo = null;
830 if (ar.exception == null && ar.result != null) {
831 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
832 for (CallForwardInfo callForwardInfo : callForwardInfos) {
833 // Service Class is a bit mask per 3gpp 27.007. Search for
834 // any service for voice call.
835 if ((callForwardInfo.serviceClass
836 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
837 callForwardingInfo = new CallForwardingInfo(
838 callForwardInfo.serviceClass, callForwardInfo.reason,
839 callForwardInfo.number,
840 callForwardInfo.timeSeconds);
841 break;
842 }
843 }
844 // Didn't find a call forward info for voice call.
845 if (callForwardingInfo == null) {
846 callForwardingInfo = new CallForwardingInfo(
847 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
848 0 /* reason */, null /* number */, 0 /* timeout */);
849 }
850 } else {
851 if (ar.result == null) {
852 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
853 }
854 if (ar.exception != null) {
855 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
856 }
857 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
860 ((CommandException) (ar.exception)).getCommandError();
861 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
862 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
863 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
864 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
865 }
866 }
867 callForwardingInfo = new CallForwardingInfo(
868 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
869 }
870 request.result = callForwardingInfo;
871 notifyRequester(request);
872 break;
873
874 case CMD_SET_CALL_FORWARDING:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
877 CallForwardingInfo callForwardingInfoToSet =
878 (CallForwardingInfo) request.argument;
879 getPhoneFromRequest(request).setCallForwardingOption(
880 callForwardingInfoToSet.getStatus(),
881 callForwardingInfoToSet.getReason(),
882 callForwardingInfoToSet.getNumber(),
883 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
884 break;
885
886 case EVENT_SET_CALL_FORWARDING_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null) {
890 request.result = true;
891 } else {
892 request.result = false;
893 loge("setCallForwarding exception: " + ar.exception);
894 }
895 notifyRequester(request);
896 break;
897
898 case CMD_GET_CALL_WAITING:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
901 getPhoneFromRequest(request).getCallWaiting(onCompleted);
902 break;
903
904 case EVENT_GET_CALL_WAITING_DONE:
905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
908 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800909 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800910 // Service Class is a bit mask per 3gpp 27.007.
911 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800912 if (callForwardResults.length > 1
913 && ((callForwardResults[1]
914 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
915 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800916 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
917 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
918 } else {
919 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
920 }
921 } else {
922 if (ar.result == null) {
923 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
924 }
925 if (ar.exception != null) {
926 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
927 }
928 if (ar.exception instanceof CommandException) {
929 CommandException.Error error =
930 ((CommandException) (ar.exception)).getCommandError();
931 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 callForwardingStatus =
933 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
934 }
935 }
936 }
937 request.result = callForwardingStatus;
938 notifyRequester(request);
939 break;
940
941 case CMD_SET_CALL_WAITING:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
944 boolean isEnable = (Boolean) request.argument;
945 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
946 break;
947
948 case EVENT_SET_CALL_WAITING_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null) {
952 request.result = true;
953 } else {
954 request.result = false;
955 loge("setCallWaiting exception: " + ar.exception);
956 }
957 notifyRequester(request);
958 break;
959
Shishir Agrawal302c8692015-06-19 13:49:39 -0700960 case EVENT_PERFORM_NETWORK_SCAN_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 CellNetworkScanResult cellScanResult;
964 if (ar.exception == null && ar.result != null) {
965 cellScanResult = new CellNetworkScanResult(
966 CellNetworkScanResult.STATUS_SUCCESS,
967 (List<OperatorInfo>) ar.result);
968 } else {
969 if (ar.result == null) {
970 loge("getCellNetworkScanResults: Empty response");
971 }
972 if (ar.exception != null) {
973 loge("getCellNetworkScanResults: Exception: " + ar.exception);
974 }
975 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
976 if (ar.exception instanceof CommandException) {
977 CommandException.Error error =
978 ((CommandException) (ar.exception)).getCommandError();
979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
980 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
981 } else if (error == CommandException.Error.GENERIC_FAILURE) {
982 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
983 }
984 }
985 cellScanResult = new CellNetworkScanResult(errorCode, null);
986 }
987 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700988 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700989 break;
990
991 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
992 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700993 ManualNetworkSelectionArgument selArg =
994 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700995 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
996 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700997 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
998 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700999 break;
1000
1001 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception == null) {
1005 request.result = true;
1006 } else {
1007 request.result = false;
1008 loge("setNetworkSelectionModeManual " + ar.exception);
1009 }
1010 notifyRequester(request);
1011 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001012 break;
1013
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001014 case CMD_GET_MODEM_ACTIVITY_INFO:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001017 if (defaultPhone != null) {
1018 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1019 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001020 break;
1021
1022 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 if (ar.exception == null && ar.result != null) {
1026 request.result = ar.result;
1027 } else {
1028 if (ar.result == null) {
1029 loge("queryModemActivityInfo: Empty response");
1030 } else if (ar.exception instanceof CommandException) {
1031 loge("queryModemActivityInfo: CommandException: " +
1032 ar.exception);
1033 } else {
1034 loge("queryModemActivityInfo: Unknown exception");
1035 }
1036 }
Amit Mahajand4766222016-01-28 15:28:28 -08001037 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1038 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001039 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001040 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001041 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001042 break;
1043
Meng Wang1a7c35a2016-05-05 20:56:15 -07001044 case CMD_SET_ALLOWED_CARRIERS:
1045 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001046 CarrierRestrictionRules argument =
1047 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001048 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001049 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001050 break;
1051
1052 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 if (ar.exception == null && ar.result != null) {
1056 request.result = ar.result;
1057 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001058 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1059 if (ar.exception instanceof CommandException) {
1060 loge("setAllowedCarriers: CommandException: " + ar.exception);
1061 CommandException.Error error =
1062 ((CommandException) (ar.exception)).getCommandError();
1063 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1064 request.result =
1065 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1066 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001067 } else {
1068 loge("setAllowedCarriers: Unknown exception");
1069 }
1070 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001071 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001072 break;
1073
1074 case CMD_GET_ALLOWED_CARRIERS:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001077 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001078 break;
1079
1080 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 if (ar.exception == null && ar.result != null) {
1084 request.result = ar.result;
1085 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001086 request.result = new IllegalStateException(
1087 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 if (ar.result == null) {
1089 loge("getAllowedCarriers: Empty response");
1090 } else if (ar.exception instanceof CommandException) {
1091 loge("getAllowedCarriers: CommandException: " +
1092 ar.exception);
1093 } else {
1094 loge("getAllowedCarriers: Unknown exception");
1095 }
1096 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001097 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001098 break;
1099
Nathan Haroldb3014052017-01-25 15:57:32 -08001100 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null && ar.result != null) {
1104 request.result = ar.result;
1105 } else {
1106 request.result = new IllegalArgumentException(
1107 "Failed to retrieve Forbidden Plmns");
1108 if (ar.result == null) {
1109 loge("getForbiddenPlmns: Empty response");
1110 } else {
1111 loge("getForbiddenPlmns: Unknown exception");
1112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001115 break;
1116
1117 case CMD_GET_FORBIDDEN_PLMNS:
1118 request = (MainThreadRequest) msg.obj;
1119 uiccCard = getUiccCardFromRequest(request);
1120 if (uiccCard == null) {
1121 loge("getForbiddenPlmns() UiccCard is null");
1122 request.result = new IllegalArgumentException(
1123 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001124 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001125 break;
1126 }
1127 Integer appType = (Integer) request.argument;
1128 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1129 if (uiccApp == null) {
1130 loge("getForbiddenPlmns() no app with specified type -- "
1131 + appType);
1132 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001134 break;
1135 } else {
1136 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1137 + " specified type -- " + appType);
1138 }
1139 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1140 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1141 onCompleted);
1142 break;
1143
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001144 case CMD_SWITCH_SLOTS:
1145 request = (MainThreadRequest) msg.obj;
1146 int[] physicalSlots = (int[]) request.argument;
1147 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1148 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1149 break;
1150
1151 case EVENT_SWITCH_SLOTS_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
1156 break;
1157 case CMD_GET_NETWORK_SELECTION_MODE:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1160 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1161 break;
1162
1163 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 if (ar.exception != null) {
1167 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1168 } else {
1169 int mode = ((int[]) ar.result)[0];
1170 if (mode == 0) {
1171 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1172 } else {
1173 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1174 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
1177 break;
1178 case CMD_GET_CDMA_ROAMING_MODE:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1181 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1182 break;
1183 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception != null) {
1187 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1188 } else {
1189 request.result = ((int[]) ar.result)[0];
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_CDMA_ROAMING_MODE:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1196 int mode = (int) request.argument;
1197 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1198 break;
1199 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 request.result = ar.exception == null;
1203 notifyRequester(request);
1204 break;
1205 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1208 int subscriptionMode = (int) request.argument;
1209 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1210 break;
1211 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 request.result = ar.exception == null;
1215 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001216 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001217 case CMD_GET_ALL_CELL_INFO:
1218 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001219 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001220 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001221 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001222 case EVENT_GET_ALL_CELL_INFO_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001225 // If a timeout occurs, the response will be null
1226 request.result = (ar.exception == null && ar.result != null)
1227 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001228 synchronized (request) {
1229 request.notifyAll();
1230 }
1231 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001232 case CMD_REQUEST_CELL_INFO_UPDATE:
1233 request = (MainThreadRequest) msg.obj;
1234 request.phone.requestCellInfoUpdate(request.workSource,
1235 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1236 break;
1237 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1241 try {
1242 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001244 cb.onError(
1245 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1246 ar.exception.getClass().getName(),
1247 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001249 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001250 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 } else {
1252 // use the result as returned
1253 cb.onCellInfo((List<CellInfo>) ar.result);
1254 }
1255 } catch (RemoteException re) {
1256 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1257 }
1258 break;
1259 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 request = (MainThreadRequest) msg.obj;
1261 WorkSource ws = (WorkSource) request.argument;
1262 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001263 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001265 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null) {
1269 request.result = ar.result;
1270 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001271 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001273 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 }
1275
1276 synchronized (request) {
1277 request.notifyAll();
1278 }
1279 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001280 case CMD_MODEM_REBOOT:
1281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001283 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001284 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001285 case EVENT_CMD_MODEM_REBOOT_DONE:
1286 handleNullReturnEvent(msg, "rebootModem");
1287 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001288 case CMD_REQUEST_ENABLE_MODEM:
1289 request = (MainThreadRequest) msg.obj;
1290 boolean enable = (boolean) request.argument;
1291 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001292 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001293 PhoneConfigurationManager.getInstance()
1294 .enablePhone(request.phone, enable, onCompleted);
1295 break;
1296 case EVENT_ENABLE_MODEM_DONE:
1297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
1299 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001300 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001301 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001302 if ((boolean) request.result) {
1303 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1304 updateModemStateMetrics();
1305 } else {
1306 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1307 + ar.exception);
1308 }
1309 notifyRequester(request);
1310 break;
1311 case CMD_GET_MODEM_STATUS:
1312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1314 PhoneConfigurationManager.getInstance()
1315 .getPhoneStatusFromModem(request.phone, onCompleted);
1316 break;
1317 case EVENT_GET_MODEM_STATUS_DONE:
1318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
1320 int id = request.phone.getPhoneId();
1321 if (ar.exception == null && ar.result != null) {
1322 request.result = ar.result;
1323 //update the cache as modem status has changed
1324 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1325 (boolean) request.result);
1326 } else {
1327 // Return true if modem status cannot be retrieved. For most cases,
1328 // modem status is on. And for older version modems, GET_MODEM_STATUS
1329 // and disable modem are not supported. Modem is always on.
1330 // TODO: this should be fixed in R to support a third
1331 // status UNKNOWN b/131631629
1332 request.result = true;
1333 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1334 + ar.exception);
1335 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001336 notifyRequester(request);
1337 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001338 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 if (ar.exception == null && ar.result != null) {
1342 request.result = ar.result;
1343 } else {
1344 request.result = -1;
1345 loge("Failed to set Forbidden Plmns");
1346 if (ar.result == null) {
1347 loge("setForbidenPlmns: Empty response");
1348 } else if (ar.exception != null) {
1349 loge("setForbiddenPlmns: Exception: " + ar.exception);
1350 request.result = -1;
1351 } else {
1352 loge("setForbiddenPlmns: Unknown exception");
1353 }
1354 }
1355 notifyRequester(request);
1356 break;
1357 case CMD_SET_FORBIDDEN_PLMNS:
1358 request = (MainThreadRequest) msg.obj;
1359 uiccCard = getUiccCardFromRequest(request);
1360 if (uiccCard == null) {
1361 loge("setForbiddenPlmns: UiccCard is null");
1362 request.result = -1;
1363 notifyRequester(request);
1364 break;
1365 }
1366 Pair<Integer, List<String>> setFplmnsArgs =
1367 (Pair<Integer, List<String>>) request.argument;
1368 appType = setFplmnsArgs.first;
1369 List<String> fplmns = setFplmnsArgs.second;
1370 uiccApp = uiccCard.getApplicationByType(appType);
1371 if (uiccApp == null) {
1372 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1373 request.result = -1;
1374 loge("Failed to get UICC App");
1375 notifyRequester(request);
1376 } else {
1377 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1378 ((SIMRecords) uiccApp.getIccRecords())
1379 .setForbiddenPlmns(onCompleted, fplmns);
1380 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001381 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001382 case CMD_ERASE_MODEM_CONFIG:
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1385 defaultPhone.eraseModemConfig(onCompleted);
1386 break;
1387 case EVENT_ERASE_MODEM_CONFIG_DONE:
1388 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001389 break;
zoey chenf95ca592019-12-30 16:11:23 +08001390
1391 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1394 Pair<String, String> changed = (Pair<String, String>) request.argument;
1395 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1396 changed.first, changed.second, onCompleted);
1397 break;
1398 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null) {
1402 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1403 } else {
1404 request.result = msg.arg1;
1405 }
1406 notifyRequester(request);
1407 break;
1408
1409 case CMD_SET_ICC_LOCK_ENABLED:
1410 request = (MainThreadRequest) msg.obj;
1411 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1412 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1413 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1414 enabled.first, enabled.second, onCompleted);
1415 break;
1416 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 if (ar.exception == null) {
1420 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1421 } else {
1422 request.result = msg.arg1;
1423 }
1424 notifyRequester(request);
1425 break;
1426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 default:
1428 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1429 break;
1430 }
1431 }
Jake Hambye994d462014-02-03 13:10:13 -08001432
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 private void notifyRequester(MainThreadRequest request) {
1434 synchronized (request) {
1435 request.notifyAll();
1436 }
1437 }
1438
Jake Hambye994d462014-02-03 13:10:13 -08001439 private void handleNullReturnEvent(Message msg, String command) {
1440 AsyncResult ar = (AsyncResult) msg.obj;
1441 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1442 if (ar.exception == null) {
1443 request.result = true;
1444 } else {
1445 request.result = false;
1446 if (ar.exception instanceof CommandException) {
1447 loge(command + ": CommandException: " + ar.exception);
1448 } else {
1449 loge(command + ": Unknown exception");
1450 }
1451 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 }
1455
1456 /**
1457 * Posts the specified command to be executed on the main thread,
1458 * waits for the request to complete, and returns the result.
1459 * @see #sendRequestAsync
1460 */
1461 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001462 return sendRequest(
1463 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001464 }
1465
1466 /**
1467 * Posts the specified command to be executed on the main thread,
1468 * waits for the request to complete, and returns the result.
1469 * @see #sendRequestAsync
1470 */
1471 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1472 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001473 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001474 }
1475
1476 /**
1477 * Posts the specified command to be executed on the main thread,
1478 * waits for the request to complete, and returns the result.
1479 * @see #sendRequestAsync
1480 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001481 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001482 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001483 }
1484
1485 /**
1486 * Posts the specified command to be executed on the main thread,
1487 * waits for the request to complete, and returns the result.
1488 * @see #sendRequestAsync
1489 */
Nathan Harold92bed182018-10-12 18:16:49 -07001490 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1491 return sendRequest(command, argument, subId, null, workSource);
1492 }
1493
1494 /**
1495 * Posts the specified command to be executed on the main thread,
1496 * waits for the request to complete, and returns the result.
1497 * @see #sendRequestAsync
1498 */
1499 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1500 return sendRequest(
1501 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1502 }
1503
1504 /**
1505 * Posts the specified command to be executed on the main thread,
1506 * waits for the request to complete, and returns the result.
1507 * @see #sendRequestAsync
1508 */
1509 private Object sendRequest(
1510 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1512 throw new RuntimeException("This method will deadlock if called from the main thread.");
1513 }
1514
Nathan Harold92bed182018-10-12 18:16:49 -07001515 MainThreadRequest request = null;
1516 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1517 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1518 } else if (phone != null) {
1519 request = new MainThreadRequest(argument, phone, workSource);
1520 } else {
1521 request = new MainThreadRequest(argument, subId, workSource);
1522 }
1523
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 Message msg = mMainThreadHandler.obtainMessage(command, request);
1525 msg.sendToTarget();
1526
1527 // Wait for the request to complete
1528 synchronized (request) {
1529 while (request.result == null) {
1530 try {
1531 request.wait();
1532 } catch (InterruptedException e) {
1533 // Do nothing, go back and wait until the request is complete
1534 }
1535 }
1536 }
1537 return request.result;
1538 }
1539
1540 /**
1541 * Asynchronous ("fire and forget") version of sendRequest():
1542 * Posts the specified command to be executed on the main thread, and
1543 * returns immediately.
1544 * @see #sendRequest
1545 */
1546 private void sendRequestAsync(int command) {
1547 mMainThreadHandler.sendEmptyMessage(command);
1548 }
1549
1550 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001551 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001552 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001553 */
1554 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001555 sendRequestAsync(command, argument, null, null);
1556 }
1557
1558 /**
1559 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1560 * @see {@link #sendRequest(int,Object)}
1561 */
1562 private void sendRequestAsync(
1563 int command, Object argument, Phone phone, WorkSource workSource) {
1564 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001565 Message msg = mMainThreadHandler.obtainMessage(command, request);
1566 msg.sendToTarget();
1567 }
1568
1569 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 * Initialize the singleton PhoneInterfaceManager instance.
1571 * This is only done once, at startup, from PhoneApp.onCreate().
1572 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001573 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 synchronized (PhoneInterfaceManager.class) {
1575 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001576 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 } else {
1578 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1579 }
1580 return sInstance;
1581 }
1582 }
1583
1584 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001585 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001588 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001589 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1591 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001592 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001593 mTelephonySharedPreferences =
1594 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001595 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001596 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001597
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 publish();
1599 }
1600
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001601 private Phone getDefaultPhone() {
1602 Phone thePhone = getPhone(getDefaultSubscription());
1603 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1604 }
1605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 private void publish() {
1607 if (DBG) log("publish: " + this);
1608
1609 ServiceManager.addService("phone", this);
1610 }
1611
Stuart Scott584921c2015-01-15 17:10:34 -08001612 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001613 if (request.phone != null) {
1614 return request.phone;
1615 } else {
1616 return getPhoneFromSubId(request.subId);
1617 }
1618 }
1619
1620 private Phone getPhoneFromSubId(int subId) {
1621 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1622 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001623 }
1624
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001625 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1626 Phone phone = getPhoneFromRequest(request);
1627 return phone == null ? null :
1628 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1629 }
1630
Wink Saville36469e72014-06-11 15:17:00 -07001631 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001632 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001633 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001636 private void sendEraseModemConfig(Phone phone) {
1637 if (phone != null) {
1638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1639 mApp, phone.getSubId(), "eraseModemConfig");
1640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1643 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
1646 }
1647 }
1648 }
1649
Peter Wang050bb052020-01-13 23:33:09 -08001650 private boolean isImsAvailableOnDevice() {
1651 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1652 if (pm == null) {
1653 // For some reason package manger is not available.. This will fail internally anyway,
1654 // so do not throw error and allow.
1655 return true;
1656 }
1657 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1658 }
1659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001661 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 if (DBG) log("dial: " + number);
1666 // No permission check needed here: This is just a wrapper around the
1667 // ACTION_DIAL intent, which is available to any app since it puts up
1668 // the UI before it does anything.
1669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001670 final long identity = Binder.clearCallingIdentity();
1671 try {
1672 String url = createTelUrl(number);
1673 if (url == null) {
1674 return;
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 // PENDING: should we just silently fail if phone is offhook or ringing?
1678 PhoneConstants.State state = mCM.getState(subId);
1679 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1680 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1681 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1682 mApp.startActivity(intent);
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687 }
1688
1689 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001690 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001691 }
1692
Wink Savilleb564aae2014-10-23 10:18:09 -07001693 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 if (DBG) log("call: " + number);
1695
1696 // This is just a wrapper around the ACTION_CALL intent, but we still
1697 // need to do a permission check since we're calling startActivity()
1698 // from the context of the phone app.
1699 enforceCallPermission();
1700
Jordan Liu1617b712019-07-10 15:06:26 -07001701 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 != AppOpsManager.MODE_ALLOWED) {
1703 return;
1704 }
1705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 String url = createTelUrl(number);
1709 if (url == null) {
1710 return;
1711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713 boolean isValid = false;
1714 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1715 if (slist != null) {
1716 for (SubscriptionInfo subInfoRecord : slist) {
1717 if (subInfoRecord.getSubscriptionId() == subId) {
1718 isValid = true;
1719 break;
1720 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001721 }
Wink Saville08874612014-08-31 19:19:58 -07001722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 if (!isValid) {
1724 return;
1725 }
Wink Saville08874612014-08-31 19:19:58 -07001726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1728 intent.putExtra(SUBSCRIPTION_KEY, subId);
1729 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1730 mApp.startActivity(intent);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001738 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1739 }
1740
Wink Savilleb564aae2014-10-23 10:18:09 -07001741 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001742 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001743 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1744 }
1745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1752 checkSimPin.start();
1753 return checkSimPin.unlockSim(null, pin);
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
1756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
Wink Savilleb564aae2014-10-23 10:18:09 -07001759 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001761
1762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1765 checkSimPuk.start();
1766 return checkSimPuk.unlockSim(puk, pin);
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
1769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001773 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 * a synchronous one.
1775 */
1776 private static class UnlockSim extends Thread {
1777
1778 private final IccCard mSimCard;
1779
1780 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001781 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1782 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783
1784 // For replies from SimCard interface
1785 private Handler mHandler;
1786
1787 // For async handler to identify request type
1788 private static final int SUPPLY_PIN_COMPLETE = 100;
1789
1790 public UnlockSim(IccCard simCard) {
1791 mSimCard = simCard;
1792 }
1793
1794 @Override
1795 public void run() {
1796 Looper.prepare();
1797 synchronized (UnlockSim.this) {
1798 mHandler = new Handler() {
1799 @Override
1800 public void handleMessage(Message msg) {
1801 AsyncResult ar = (AsyncResult) msg.obj;
1802 switch (msg.what) {
1803 case SUPPLY_PIN_COMPLETE:
1804 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1805 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001806 mRetryCount = msg.arg1;
1807 if (ar.exception != null) {
1808 if (ar.exception instanceof CommandException &&
1809 ((CommandException)(ar.exception)).getCommandError()
1810 == CommandException.Error.PASSWORD_INCORRECT) {
1811 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1812 } else {
1813 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1814 }
1815 } else {
1816 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 mDone = true;
1819 UnlockSim.this.notifyAll();
1820 }
1821 break;
1822 }
1823 }
1824 };
1825 UnlockSim.this.notifyAll();
1826 }
1827 Looper.loop();
1828 }
1829
1830 /*
1831 * Use PIN or PUK to unlock SIM card
1832 *
1833 * If PUK is null, unlock SIM card with PIN
1834 *
1835 * If PUK is not null, unlock SIM card with PUK and set PIN code
1836 */
Wink Saville9de0f752013-10-22 19:04:03 -07001837 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838
1839 while (mHandler == null) {
1840 try {
1841 wait();
1842 } catch (InterruptedException e) {
1843 Thread.currentThread().interrupt();
1844 }
1845 }
1846 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1847
1848 if (puk == null) {
1849 mSimCard.supplyPin(pin, callback);
1850 } else {
1851 mSimCard.supplyPuk(puk, pin, callback);
1852 }
1853
1854 while (!mDone) {
1855 try {
1856 Log.d(LOG_TAG, "wait for done");
1857 wait();
1858 } catch (InterruptedException e) {
1859 // Restore the interrupted status
1860 Thread.currentThread().interrupt();
1861 }
1862 }
1863 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001864 int[] resultArray = new int[2];
1865 resultArray[0] = mResult;
1866 resultArray[1] = mRetryCount;
1867 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869 }
1870
1871 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001872 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001873
1874 }
1875
Wink Savilleb564aae2014-10-23 10:18:09 -07001876 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 // No permission check needed here: this call is harmless, and it's
1878 // needed for the ServiceState.requestStateUpdate() call (which is
1879 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
1884 phone.updateServiceLocation();
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001891 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001892 @Override
1893 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001894 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001895 }
1896
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001898 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1899 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1900 callingFeatureId);
1901 }
1902
1903 @Deprecated
1904 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001905 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001906 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1907 }
1908
1909 @Override
1910 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1911 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001913 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 return false;
1915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 return isRadioOnForSubscriber(subId);
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001923 }
1924
1925 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 final Phone phone = getPhone(subId);
1929 if (phone != null) {
1930 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1931 } else {
1932 return false;
1933 }
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001940 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
Wink Saville36469e72014-06-11 15:17:00 -07001942
Wink Savilleb564aae2014-10-23 10:18:09 -07001943 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1951 }
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 }
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
1957 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001958 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001959 }
1960
Wink Savilleb564aae2014-10-23 10:18:09 -07001961 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001963
1964 final long identity = Binder.clearCallingIdentity();
1965 try {
1966 final Phone phone = getPhone(subId);
1967 if (phone == null) {
1968 return false;
1969 }
1970 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1971 toggleRadioOnOffForSubscriber(subId);
1972 }
1973 return true;
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
Wink Saville36469e72014-06-11 15:17:00 -07001978
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001979 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001980 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001981 /*
1982 * If any of the Radios are available, it will need to be
1983 * shutdown. So return true if any Radio is available.
1984 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1988 Phone phone = PhoneFactory.getPhone(i);
1989 if (phone != null && phone.isRadioAvailable()) return true;
1990 }
1991 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1992 return false;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001995 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001996 }
1997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001999 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 enforceModifyPermission();
2001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2005 logv("Shutting down Phone " + i);
2006 shutdownRadioUsingPhoneId(i);
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002010 }
2011 }
2012
2013 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002014 Phone phone = PhoneFactory.getPhone(phoneId);
2015 if (phone != null && phone.isRadioAvailable()) {
2016 phone.shutdownRadio();
2017 }
2018 }
2019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2026 if (defaultPhone != null) {
2027 defaultPhone.setRadioPower(turnOn);
2028 return true;
2029 } else {
2030 loge("There's no default phone.");
2031 return false;
2032 }
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002035 }
Wink Saville36469e72014-06-11 15:17:00 -07002036 }
2037
Wink Savilleb564aae2014-10-23 10:18:09 -07002038 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 final Phone phone = getPhone(subId);
2044 if (phone != null) {
2045 phone.setRadioPower(turnOn);
2046 return true;
2047 } else {
2048 return false;
2049 }
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
Wink Saville36469e72014-06-11 15:17:00 -07002055 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 public boolean enableDataConnectivity() {
2058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 int subId = mSubscriptionController.getDefaultDataSubId();
2063 final Phone phone = getPhone(subId);
2064 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002065 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002066 return true;
2067 } else {
2068 return false;
2069 }
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
2074
Wink Saville36469e72014-06-11 15:17:00 -07002075 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 public boolean disableDataConnectivity() {
2078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079
2080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 int subId = mSubscriptionController.getDefaultDataSubId();
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002085 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 return true;
2087 } else {
2088 return false;
2089 }
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Sanket Padawe356d7632015-06-22 14:03:32 -07002095 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002096 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002101 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102 } else {
2103 return false;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002111 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
pkanwarae03a6b2016-11-06 20:37:09 -08002114 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115 enforceCallPermission();
2116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2120 return;
2121 }
2122 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2123 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
2126 }
pkanwar32d516d2016-10-14 19:37:38 -07002127 };
2128
Wink Savilleb564aae2014-10-23 10:18:09 -07002129 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2135 return false;
2136 }
2137 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002145 }
2146
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002147 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 Phone phone = PhoneFactory.getPhone(slotIndex);
2151 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2152 PhoneConstantConversions.convertCallState(phone.getState());
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002159 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002160 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2161 }
2162
2163 @Override
2164 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002165 final long identity = Binder.clearCallingIdentity();
2166 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002167 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 if (phone != null) {
2169 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2170 } else {
2171 return PhoneConstantConversions.convertDataState(
2172 PhoneConstants.DataState.DISCONNECTED);
2173 }
2174 } finally {
2175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002180 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002181 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2182 }
2183
2184 @Override
2185 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 final long identity = Binder.clearCallingIdentity();
2187 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002188 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 if (phone != null) {
2190 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2191 } else {
2192 return TelephonyManager.DATA_ACTIVITY_NONE;
2193 }
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
2199 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002200 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002201 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002202 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002203
2204 LocationAccessPolicy.LocationPermissionResult locationResult =
2205 LocationAccessPolicy.checkLocationPermission(mApp,
2206 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2207 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002208 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002209 .setCallingPid(Binder.getCallingPid())
2210 .setCallingUid(Binder.getCallingUid())
2211 .setMethod("getCellLocation")
2212 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2213 .build());
2214 switch (locationResult) {
2215 case DENIED_HARD:
2216 throw new SecurityException("Not allowed to access cell location");
2217 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002218 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2219 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002226 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002227 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
Svetoslav64fad262015-04-14 14:35:21 -07002231 }
2232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2235 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002236 if (!TextUtils.isEmpty(callingPackage)) {
2237 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2239 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002240 return "";
2241 }
2242 }
2243
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002244 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2245 // registered cell info, so return a NULL country instead.
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002248 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2249 // Get default phone in this case.
2250 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2251 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002252 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002253 // Todo: fix this when we can get the actual cellular network info when the device
2254 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002255 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002256 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2257 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002258 return "";
2259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 Phone phone = PhoneFactory.getPhone(phoneId);
2261 if (phone != null) {
2262 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002263 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 if (sst != null) {
2265 LocaleTracker lt = sst.getLocaleTracker();
2266 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002267 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2268 return lt.getCurrentCountry();
2269 } else if (emergencyNumberTracker != null) {
2270 return emergencyNumberTracker.getEmergencyCountryIso();
2271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272 }
2273 }
2274 }
2275 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002279 }
2280
2281 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002283 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002284 }
2285
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002287 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 mApp.enforceCallingOrSelfPermission(
2289 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 final Phone phone = getPhone(subId);
2294 if (phone != null) {
2295 phone.enableLocationUpdates();
2296 }
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 @Override
2303 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002304 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 mApp.enforceCallingOrSelfPermission(
2310 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 final Phone phone = getPhone(subId);
2315 if (phone != null) {
2316 phone.disableLocationUpdates();
2317 }
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
Nathan Harold31d7ff32018-10-15 20:20:30 -07002323 /**
2324 * Returns the target SDK version number for a given package name.
2325 *
Nathan Haroldec184742019-07-10 17:04:16 -07002326 * This call MUST be invoked before clearing the calling UID.
2327 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002328 * @return target SDK if the package is found or INT_MAX.
2329 */
2330 private int getTargetSdk(String packageName) {
2331 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002332 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002333 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002334 if (ai != null) return ai.targetSdkVersion;
2335 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002336 loge("Failed to get package info for pkg="
2337 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002338 }
2339 return Integer.MAX_VALUE;
2340 }
2341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 @Override
2343 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002344 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2345 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002346 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002347 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2348 throw new SecurityException(
2349 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2350 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002351
Jordan Liu1617b712019-07-10 15:06:26 -07002352 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2354 return null;
2355 }
Svetoslav64fad262015-04-14 14:35:21 -07002356
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002357 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002359 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002360 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361
Nathan Haroldf180aac2018-06-01 18:43:55 -07002362 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2363 for (CellInfo ci : info) {
2364 if (ci instanceof CellInfoGsm) {
2365 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2366 } else if (ci instanceof CellInfoWcdma) {
2367 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002370 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002373 private List<CellInfo> getCachedCellInfo() {
2374 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2375 for (Phone phone : PhoneFactory.getPhones()) {
2376 List<CellInfo> info = phone.getAllCellInfo();
2377 if (info != null) cellInfos.addAll(info);
2378 }
2379 return cellInfos;
2380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381
2382 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002383 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002384 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002385 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002386
2387 LocationAccessPolicy.LocationPermissionResult locationResult =
2388 LocationAccessPolicy.checkLocationPermission(mApp,
2389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2390 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002392 .setCallingPid(Binder.getCallingPid())
2393 .setCallingUid(Binder.getCallingUid())
2394 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002395 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2397 .build());
2398 switch (locationResult) {
2399 case DENIED_HARD:
2400 throw new SecurityException("Not allowed to access cell info");
2401 case DENIED_SOFT:
2402 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002405 final int targetSdk = getTargetSdk(callingPackage);
2406 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2407 return getCachedCellInfo();
2408 }
2409
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002410 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2415 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002416 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002417 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424 }
2425
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002426 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002427 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2428 String callingFeatureId) {
2429 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2430 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 }
2432
2433 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002434 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2435 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002436 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002437 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 }
2439
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002440 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2441 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002442 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002444
2445 LocationAccessPolicy.LocationPermissionResult locationResult =
2446 LocationAccessPolicy.checkLocationPermission(mApp,
2447 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2448 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002450 .setCallingPid(Binder.getCallingPid())
2451 .setCallingUid(Binder.getCallingUid())
2452 .setMethod("requestCellInfoUpdate")
2453 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2454 .build());
2455 switch (locationResult) {
2456 case DENIED_HARD:
2457 throw new SecurityException("Not allowed to access cell info");
2458 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002459 try {
2460 cb.onCellInfo(new ArrayList<CellInfo>());
2461 } catch (RemoteException re) {
2462 // Drop without consequences
2463 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002464 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 }
2466
Nathan Harolda939a962019-05-09 10:13:47 -07002467
2468 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002469 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2470
2471 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2472 }
2473
2474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002476 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Shishir Agrawala9f32182016-04-12 12:00:16 -07002487 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002488 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002489 Phone phone = PhoneFactory.getPhone(slotIndex);
2490 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002491 return null;
2492 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002493 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002494 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002495 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002496 return null;
2497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 return phone.getImei();
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002505 }
2506
2507 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002508 public String getTypeAllocationCodeForSlot(int slotIndex) {
2509 Phone phone = PhoneFactory.getPhone(slotIndex);
2510 String tac = null;
2511 if (phone != null) {
2512 String imei = phone.getImei();
2513 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2514 }
2515 return tac;
2516 }
2517
2518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002519 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002520 Phone phone = PhoneFactory.getPhone(slotIndex);
2521 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002522 return null;
2523 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002524
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002526 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 return null;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return phone.getMeid();
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Jack Yu2af8d712017-03-15 17:14:14 -07002537 }
2538
2539 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002540 public String getManufacturerCodeForSlot(int slotIndex) {
2541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 String manufacturerCode = null;
2543 if (phone != null) {
2544 String meid = phone.getMeid();
2545 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2546 }
2547 return manufacturerCode;
2548 }
2549
2550 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002551 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2552 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 Phone phone = PhoneFactory.getPhone(slotIndex);
2554 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 return null;
2556 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
2558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002559 mApp, subId, callingPackage, callingFeatureId,
2560 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 return null;
2562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 return phone.getDeviceSvn();
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 }
2571
fionaxu43304da2017-11-27 22:51:16 -08002572 @Override
2573 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
2580 }
fionaxu43304da2017-11-27 22:51:16 -08002581 }
2582
2583 @Override
2584 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(subId);
2588 return phone == null ? null : phone.getCarrierName();
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
fionaxu43304da2017-11-27 22:51:16 -08002592 }
2593
calvinpanffe225e2018-11-01 19:43:06 +08002594 @Override
chen xu0026ca62019-03-06 15:28:50 -08002595 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 final Phone phone = getPhone(subId);
2599 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002600 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
2604 }
2605
2606 @Override
chen xu0026ca62019-03-06 15:28:50 -08002607 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002611 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
2615 }
2616
chen xu651eec72018-11-11 19:03:44 -08002617 @Override
chen xu864e11c2018-12-06 22:10:03 -08002618 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2619 if (!isSubscriptionMccMnc) {
2620 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2621 }
chen xu651eec72018-11-11 19:03:44 -08002622 final Phone phone = PhoneFactory.getPhone(slotIndex);
2623 if (phone == null) {
2624 return TelephonyManager.UNKNOWN_CARRIER_ID;
2625 }
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
2632 }
2633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 //
2635 // Internal helper methods.
2636 //
2637
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002638 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2640 *
2641 * @throws SecurityException if the caller does not have the required permission
2642 */
2643 private void enforceModifyPermission() {
2644 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2645 }
2646
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002647 /**
2648 * Make sure the caller is system.
2649 *
2650 * @throws SecurityException if the caller is not system.
2651 */
2652 private void enforceSystemCaller() {
2653 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2654 throw new SecurityException("Caller must be system");
2655 }
2656 }
2657
Shuo Qianf2b2df42019-11-13 17:43:31 -08002658 private void enforceActiveEmergencySessionPermission() {
2659 mApp.enforceCallingOrSelfPermission(
2660 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2661 }
2662
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 /**
2664 * Make sure the caller has the CALL_PHONE permission.
2665 *
2666 * @throws SecurityException if the caller does not have the required permission
2667 */
2668 private void enforceCallPermission() {
2669 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2670 }
2671
paulhu423b5f22019-08-23 19:17:33 +08002672 private void enforceSettingsPermission() {
2673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002674 }
2675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 private String createTelUrl(String number) {
2677 if (TextUtils.isEmpty(number)) {
2678 return null;
2679 }
2680
Jake Hambye994d462014-02-03 13:10:13 -08002681 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Ihab Awadf9e92732013-12-05 18:02:52 -08002684 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2686 }
2687
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002688 private static void logv(String msg) {
2689 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2690 }
2691
Ihab Awadf9e92732013-12-05 18:02:52 -08002692 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2694 }
2695
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002696 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002698 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Sanket Padawe356d7632015-06-22 14:03:32 -07002701 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002702 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = PhoneFactory.getPhone(slotIndex);
2706 if (phone == null) {
2707 return PhoneConstants.PHONE_TYPE_NONE;
2708 } else {
2709 return phone.getPhoneType();
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
2717 * Returns the CDMA ERI icon index to display
2718 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002719 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002720 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2721 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2722 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002723 }
2724
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002726 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2727 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002729 mApp, subId, callingPackage, callingFeatureId,
2730 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002731 return -1;
2732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 final Phone phone = getPhone(subId);
2737 if (phone != null) {
2738 return phone.getCdmaEriIconIndex();
2739 } else {
2740 return -1;
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
2747 /**
2748 * Returns the CDMA ERI icon mode,
2749 * 0 - ON
2750 * 1 - FLASHING
2751 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002752 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002753 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2754 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2755 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002759 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2760 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002762 mApp, subId, callingPackage, callingFeatureId,
2763 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002764 return -1;
2765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 return phone.getCdmaEriIconMode();
2772 } else {
2773 return -1;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
2781 * Returns the CDMA ERI text,
2782 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002784 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2785 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2786 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002787 }
2788
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002790 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002793 mApp, subId, callingPackage, callingFeatureId,
2794 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002795 return null;
2796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
2802 return phone.getCdmaEriText();
2803 } else {
2804 return null;
2805 }
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 }
2810
2811 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002812 * Returns the CDMA MDN.
2813 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002815 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2817 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002822 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 return phone.getLine1Number();
2824 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 return null;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002830 }
2831 }
2832
2833 /**
2834 * Returns the CDMA MIN.
2835 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002837 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2845 return phone.getCdmaMin();
2846 } else {
2847 return null;
2848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002851 }
2852 }
2853
Hall Liud892bec2018-11-30 14:51:45 -08002854 @Override
2855 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2856 INumberVerificationCallback callback, String callingPackage) {
2857 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2858 != PERMISSION_GRANTED) {
2859 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2860 }
2861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2862
2863 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2864 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2865 throw new SecurityException("Calling package must be configured in the device config");
2866 }
2867
2868 if (range == null) {
2869 throw new NullPointerException("Range must be non-null");
2870 }
2871
2872 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002873 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002874
2875 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2876 }
2877
Junda Liuca05d5d2014-08-14 22:36:34 -07002878 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 * Returns true if CDMA provisioning needs to run.
2880 */
2881 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
2889
2890 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002891 * Sets the voice mail number of a given subId.
2892 */
2893 @Override
2894 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2896 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2901 new Pair<String, String>(alphaTag, number), new Integer(subId));
2902 return success;
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002906 }
2907
Ta-wei Yen87c49842016-05-13 21:19:52 -07002908 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002909 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002911 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2912 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002913 if (!TextUtils.equals(callingPackage, systemDialer)) {
2914 throw new SecurityException("caller must be system dialer");
2915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2920 if (phoneAccountHandle == null) {
2921 return null;
2922 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002926 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002927 }
2928
2929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002930 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2931 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002934 mApp, subId, callingPackage, callingFeatureId,
2935 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002936 return null;
2937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002945 }
2946
2947 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002948 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2949 VisualVoicemailSmsFilterSettings settings) {
2950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002959 }
2960
2961 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002962 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002972 }
2973
2974 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002975 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2976 String callingPackage, int subId) {
2977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002986 }
2987
2988 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002989 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002999 }
3000
3001 @Override
3002 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3003 String number, int port, String text, PendingIntent sentIntent) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003005 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003006 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003007 SmsController smsController = PhoneFactory.getSmsController();
3008 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3009 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003010 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003011
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003012 /**
fionaxu0152e512016-11-14 13:36:14 -08003013 * Sets the voice activation state of a given subId.
3014 */
3015 @Override
3016 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3018 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 final Phone phone = getPhone(subId);
3023 if (phone != null) {
3024 phone.setVoiceActivationState(activationState);
3025 } else {
3026 loge("setVoiceActivationState fails with invalid subId: " + subId);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003030 }
3031 }
3032
3033 /**
3034 * Sets the data activation state of a given subId.
3035 */
3036 @Override
3037 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3039 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
3045 phone.setDataActivationState(activationState);
3046 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003047 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003051 }
3052 }
3053
3054 /**
3055 * Returns the voice activation state of a given subId.
3056 */
3057 @Override
3058 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
fionaxu0152e512016-11-14 13:36:14 -08003061 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 if (phone != null) {
3065 return phone.getVoiceActivationState();
3066 } else {
3067 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Returns the data activation state of a given subId.
3076 */
3077 @Override
3078 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003079 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
fionaxu0152e512016-11-14 13:36:14 -08003081 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 if (phone != null) {
3085 return phone.getDataActivationState();
3086 } else {
3087 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003091 }
3092 }
3093
3094 /**
Wink Saville36469e72014-06-11 15:17:00 -07003095 * Returns the unread count of voicemails for a subId
3096 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003097 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003098 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3099 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003101 mApp, subId, callingPackage, callingFeatureId,
3102 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003103 return 0;
3104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 if (phone != null) {
3109 return phone.getVoiceMessageCount();
3110 } else {
3111 return 0;
3112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
3118 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003119 * returns true, if the device is in a state where both voice and data
3120 * are supported simultaneously. This can change based on location or network condition.
3121 */
3122 @Override
3123 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003131 }
3132
3133 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003134 * Send the dialer code if called from the current default dialer or the caller has
3135 * carrier privilege.
3136 * @param inputCode The dialer code to send
3137 */
3138 @Override
3139 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003140 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003142 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3143 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003144 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003145 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003146 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
fionaxu235cc5e2017-03-06 22:25:57 -08003155 }
3156
Pengquan Menga1bb6272018-09-06 09:59:22 -07003157 @Override
3158 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003159 TelephonyPermissions
3160 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3161 mApp, subId, "getNetworkSelectionMode");
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 if (!isActiveSubscription(subId)) {
3165 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3166 }
3167 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003171 }
3172
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08003174 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3175 String callingFeatureId) {
3176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3177 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3178 return null;
3179 }
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 return mPhoneConfigurationManager.getStaticPhoneCapability();
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 }
3187
3188 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003189 public boolean isInEmergencySmsMode() {
3190 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 for (Phone phone : PhoneFactory.getPhones()) {
3194 if (phone.isInEmergencySmsMode()) {
3195 return true;
3196 }
3197 }
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 return false;
3202 }
3203
shilu366312e2019-12-17 09:28:10 -08003204 /**
3205 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3206 * @param subId The subscription to use to check the configuration.
3207 * @param c The callback that will be used to send the result.
3208 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003209 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003210 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3211 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003212 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3213 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003214
Brad Ebinger77b832e2019-10-17 17:03:22 -07003215 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3216 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3217 "IMS not available on device.");
3218 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 final long token = Binder.clearCallingIdentity();
3220 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003222 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003224 } catch (ImsException e) {
3225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 } finally {
3227 Binder.restoreCallingIdentity(token);
3228 }
3229 }
3230
shilu366312e2019-12-17 09:28:10 -08003231 /**
3232 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3233 * @param subId The subscription to use to check the configuration.
3234 * @param c The callback that will be used to send the result.
3235 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003237 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003238 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3239 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3241 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3242 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003243 final long token = Binder.clearCallingIdentity();
3244 try {
3245 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3246 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3247 .removeRegistrationCallbackForSubscription(c, subId);
3248 } catch (ImsException e) {
3249 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3250 + "is inactive, ignoring unregister.");
3251 // If the subscription is no longer active, just return, since the callback
3252 // will already have been removed internally.
3253 } finally {
3254 Binder.restoreCallingIdentity(token);
3255 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 }
3257
Brad Ebinger774ba362019-10-22 17:36:18 -07003258 /**
3259 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3260 */
3261 @Override
3262 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3263 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3264 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3265 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3266 "IMS not available on device.");
3267 }
3268 final long token = Binder.clearCallingIdentity();
3269 try {
3270 Phone phone = getPhone(subId);
3271 if (phone == null) {
3272 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3273 + subId + "'");
3274 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3275 }
3276 phone.getImsRegistrationState(regState -> {
3277 try {
3278 consumer.accept((regState == null)
3279 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3280 } catch (RemoteException e) {
3281 // Ignore if the remote process is no longer available to call back.
3282 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3283 }
3284 });
3285 } finally {
3286 Binder.restoreCallingIdentity(token);
3287 }
3288 }
3289
3290 /**
3291 * Get the transport type for the IMS service registration state.
3292 */
3293 @Override
3294 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003295 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3296 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003297 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3299 "IMS not available on device.");
3300 }
3301 final long token = Binder.clearCallingIdentity();
3302 try {
3303 Phone phone = getPhone(subId);
3304 if (phone == null) {
3305 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3306 + subId + "'");
3307 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3308 }
3309 phone.getImsRegistrationTech(regTech -> {
3310 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3311 int regTechConverted = (regTech == null)
3312 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3313 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3314 regTechConverted);
3315 try {
3316 consumer.accept(regTechConverted);
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
shilu366312e2019-12-17 09:28:10 -08003327 /**
3328 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3329 * @param subId The subscription to use to check the configuration.
3330 * @param c The callback that will be used to send the result.
3331 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003333 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3334 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003335 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3336 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003337 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3338 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3339 "IMS not available on device.");
3340 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3342 final long token = Binder.clearCallingIdentity();
3343 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003346 } catch (ImsException e) {
3347 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 } finally {
3349 Binder.restoreCallingIdentity(token);
3350 }
3351 }
3352
shilu366312e2019-12-17 09:28:10 -08003353 /**
3354 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3355 * @param subId The subscription to use to check the configuration.
3356 * @param c The callback that will be used to send the result.
3357 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003359 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003360 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3361 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003362 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3363 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3364 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003365
3366 final long token = Binder.clearCallingIdentity();
3367 try {
3368 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3369 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003370 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003371 } catch (ImsException e) {
3372 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3373 + "is inactive, ignoring unregister.");
3374 // If the subscription is no longer active, just return, since the callback
3375 // will already have been removed internally.
3376 } finally {
3377 Binder.restoreCallingIdentity(token);
3378 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 }
3380
3381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003382 public boolean isCapable(int subId, int capability, int regTech) {
3383 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3385 final long token = Binder.clearCallingIdentity();
3386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3391 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003392 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003393 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3394 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 } finally {
3396 Binder.restoreCallingIdentity(token);
3397 }
3398 }
3399
3400 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003401 public boolean isAvailable(int subId, int capability, int regTech) {
3402 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 final long token = Binder.clearCallingIdentity();
3404 try {
3405 Phone phone = getPhone(subId);
3406 if (phone == null) return false;
3407 return phone.isImsCapabilityAvailable(capability, regTech);
3408 } finally {
3409 Binder.restoreCallingIdentity(token);
3410 }
3411 }
3412
Brad Ebinger77b832e2019-10-17 17:03:22 -07003413 /**
3414 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3415 * subscription.
3416 * @param subId The subscription to use to check the configuration.
3417 * @param callback The callback that will be used to send the result.
3418 * @param capability The MmTelFeature capability that will be used to send the result.
3419 * @param transportType The transport type of the MmTelFeature capability.
3420 */
3421 @Override
3422 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3423 int transportType) {
3424 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3425 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3426 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3427 "IMS not available on device.");
3428 }
3429 final long token = Binder.clearCallingIdentity();
3430 try {
3431 int slotId = getSlotIndex(subId);
3432 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3433 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3434 + subId + "'");
3435 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3436 }
3437 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3438 transportType, aBoolean -> {
3439 try {
3440 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3441 } catch (RemoteException e) {
3442 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3443 + "running. Ignore");
3444 }
3445 });
3446 } finally {
3447 Binder.restoreCallingIdentity(token);
3448 }
3449 }
3450
shilu366312e2019-12-17 09:28:10 -08003451 /**
3452 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3453 * @param subId The subscription to use to check the configuration.
3454 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 @Override
3456 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003457 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3458 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003459
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3461 final long token = Binder.clearCallingIdentity();
3462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003465 } catch (ImsException e) {
3466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 } finally {
3468 Binder.restoreCallingIdentity(token);
3469 }
3470 }
3471
3472 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003473 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003475 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003479 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003481 } catch (ImsException e) {
3482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
3486 }
3487
shilu366312e2019-12-17 09:28:10 -08003488 /**
3489 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3490 * @param subId The subscription to use to check the configuration.
3491 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003493 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003494 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3495 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003499 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3500 } catch (ImsException e) {
3501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
3505 }
3506
3507 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003508 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003510 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003514 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003515 } catch (ImsException e) {
3516 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
3520 }
3521
shilu366312e2019-12-17 09:28:10 -08003522 /**
3523 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3524 * @param subId The subscription to use to check the configuration.
3525 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 @Override
3527 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003528 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3529 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003533 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 } catch (ImsException e) {
3536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
3540 }
3541
3542 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003543 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003545 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003549 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003550 } catch (ImsException e) {
3551 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 }
3556
shilu366312e2019-12-17 09:28:10 -08003557 /**
3558 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3559 * @param subId The subscription to use to check the configuration.
3560 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 @Override
3562 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003563 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3564 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003570 } catch (ImsException e) {
3571 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
3577 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003578 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003580 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003584 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003586 } catch (ImsException e) {
3587 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
3591 }
3592
3593 @Override
3594 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3596 "setVoWiFiNonPersistent");
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003600 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003601 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003602 } catch (ImsException e) {
3603 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 } finally {
3605 Binder.restoreCallingIdentity(identity);
3606 }
3607 }
3608
shilu366312e2019-12-17 09:28:10 -08003609 /**
3610 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3611 * @param subId The subscription to use to check the configuration.
3612 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 @Override
3614 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003615 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3616 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003620 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003622 } catch (ImsException e) {
3623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
3629 @Override
3630 public void setVoWiFiModeSetting(int subId, int mode) {
3631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3632 "setVoWiFiModeSetting");
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003638 } catch (ImsException e) {
3639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
3645 @Override
3646 public int getVoWiFiRoamingModeSetting(int subId) {
3647 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003653 } catch (ImsException e) {
3654 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
3658 }
3659
3660 @Override
3661 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3663 "setVoWiFiRoamingModeSetting");
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003669 } catch (ImsException e) {
3670 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
3674 }
3675
3676 @Override
3677 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3679 "setRttCapabilityEnabled");
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003683 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3684 } catch (ImsException e) {
3685 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
3689 }
3690
shilu366312e2019-12-17 09:28:10 -08003691 /**
3692 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3693 * @param subId The subscription to use to check the configuration.
3694 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 @Override
3696 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003697 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3698 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (ImsException e) {
3705 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003711 @Override
3712 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3713 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003716 if (!isImsAvailableOnDevice()) {
3717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3718 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003719 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 }
3729
3730 @Override
3731 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3732 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3733 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3736 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003740 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003742 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3743 + "is inactive, ignoring unregister.");
3744 // If the subscription is no longer active, just return, since the callback will already
3745 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
allenwtsu99c623b2020-01-03 18:24:23 +08003751
3752 private void checkModifyPhoneStatePermission(int subId, String message) {
3753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3754 message);
3755 }
3756
3757 private boolean isImsProvisioningRequired(int subId, int capability,
3758 boolean isMmtelCapability) {
3759 Phone phone = getPhone(subId);
3760 if (phone == null) {
3761 loge("phone instance null for subid " + subId);
3762 return false;
3763 }
3764 if (isMmtelCapability) {
3765 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3766 return false;
3767 }
3768 } else {
3769 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3770 return false;
3771 }
3772 }
3773 return true;
3774 }
3775
3776 @Override
3777 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3778 boolean isProvisioned) {
3779 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3784 if (!isImsProvisioningRequired(subId, capability, false)) {
3785 return;
3786 }
3787
3788 // this capability requires provisioning, route to the correct API.
3789 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3790 switch (capability) {
3791 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3792 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3793 ims.setEabProvisioned(isProvisioned);
3794 break;
3795 default: {
3796 throw new IllegalArgumentException("Tried to set provisioning for "
3797 + "rcs capability '" + capability + "', which does not require "
3798 + "provisioning.");
3799 }
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
3804
3805 }
3806
3807
3808 @Override
3809 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3810 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3814 if (!isImsProvisioningRequired(subId, capability, false)) {
3815 return true;
3816 }
3817
3818 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3819 switch (capability) {
3820 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3821 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3822 return ims.isEabProvisionedOnDevice();
3823
3824 default: {
3825 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3826 + "capability '" + capability + "', which does not require "
3827 + "provisioning.");
3828 }
3829 }
3830
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
3834 }
3835
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003836 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003837 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3838 boolean isProvisioned) {
3839 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3840 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3841 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3842 }
allenwtsu99c623b2020-01-03 18:24:23 +08003843 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003847 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003848 return;
3849 }
3850
3851 // this capability requires provisioning, route to the correct API.
3852 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3853 switch (capability) {
3854 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3855 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3856 ims.setVolteProvisioned(isProvisioned);
3857 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3858 ims.setWfcProvisioned(isProvisioned);
3859 }
3860 break;
3861 }
3862 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3863 // There is currently no difference in VT provisioning type.
3864 ims.setVtProvisioned(isProvisioned);
3865 break;
3866 }
3867 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3868 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3869 // change the capability of the feature instead if needed.
3870 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3871 == isProvisioned) {
3872 // No change in provisioning.
3873 return;
3874 }
3875 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3876 try {
3877 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003878 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003879 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3880 + ", Exception" + e.getMessage());
3881 }
3882 break;
3883 }
3884 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003885 throw new IllegalArgumentException("Tried to set provisioning for "
3886 + "MmTel capability '" + capability + "', which does not require "
3887 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003888 }
3889 }
3890
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
3893 }
3894 }
3895
3896 @Override
3897 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3898 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3899 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3900 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3901 }
3902 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003906 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 return true;
3908 }
3909
3910 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3913 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3914 return ims.isVolteProvisionedOnDevice();
3915 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3916 return ims.isWfcProvisionedOnDevice();
3917 }
3918 // This should never happen, since we are checking tech above to make sure it
3919 // is either LTE or IWLAN.
3920 throw new IllegalArgumentException("Invalid radio technology for voice "
3921 + "capability.");
3922 }
3923 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3924 // There is currently no difference in VT provisioning type.
3925 return ims.isVtProvisionedOnDevice();
3926 }
3927 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3928 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3929 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3930 }
3931 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003932 throw new IllegalArgumentException(
3933 "Tried to get provisioning for MmTel capability '" + capability
3934 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003935 }
3936 }
3937
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
3941 }
3942
3943 @Override
3944 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3945 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3946 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3947 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3948 }
3949 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3950 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3951 return (provisionedBits & capability) > 0;
3952 }
3953
3954 @Override
3955 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3956 boolean isProvisioned) {
3957 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3958 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3959 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3960 }
3961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3962 "setProvisioningStatusForCapability");
3963 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3964 // If the current provisioning status for capability already matches isProvisioned,
3965 // do nothing.
3966 if (((provisionedBits & capability) > 0) == isProvisioned) {
3967 return;
3968 }
3969 if (isProvisioned) {
3970 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3971 } else {
3972 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3973 }
3974 }
3975
3976 /**
3977 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3978 * technology. The bitfield should mirror the bitfield defined by
3979 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3980 */
3981 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3982 String key = getMmTelProvisioningKey(subId, tech);
3983 // Default is no capabilities are provisioned.
3984 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3985 }
3986
3987 /**
3988 * Sets the MmTel capability provisioning bitfield (defined by
3989 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3990 * technology specified.
3991 *
3992 * Note: This is a synchronous command and should not be called on UI thread.
3993 */
3994 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3995 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3996 String key = getMmTelProvisioningKey(subId, tech);
3997 editor.putInt(key, newField);
3998 editor.commit();
3999 }
4000
4001 private static String getMmTelProvisioningKey(int subId, int tech) {
4002 // resulting key is provision_ims_mmtel_{subId}_{tech}
4003 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4004 }
4005
4006 /**
4007 * Query CarrierConfig to see if the specified capability requires provisioning for the
4008 * carrier associated with the subscription id.
4009 */
4010 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4011 int capability) {
4012 CarrierConfigManager configManager = new CarrierConfigManager(context);
4013 PersistableBundle c = configManager.getConfigForSubId(subId);
4014 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004015 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004016 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4017 false);
4018 boolean requireVoiceVtProvisioning = c.getBoolean(
4019 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4020
4021 // First check to make sure that the capability requires provisioning.
4022 switch (capability) {
4023 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4024 // intentional fallthrough
4025 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4026 if (requireVoiceVtProvisioning) {
4027 // Voice and Video requires provisioning
4028 return true;
4029 }
4030 break;
4031 }
4032 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4033 if (requireUtProvisioning) {
4034 // UT requires provisioning
4035 return true;
4036 }
4037 break;
4038 }
4039 }
4040 return false;
4041 }
4042
allenwtsu99c623b2020-01-03 18:24:23 +08004043 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4044 int capability) {
4045 CarrierConfigManager configManager = new CarrierConfigManager(context);
4046 PersistableBundle c = configManager.getConfigForSubId(subId);
4047
4048 boolean requireRcsProvisioning = c.getBoolean(
4049 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4050
4051 // First check to make sure that the capability requires provisioning.
4052 switch (capability) {
4053 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4054 // intentional fallthrough
4055 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4056 if (requireRcsProvisioning) {
4057 // OPTION or PRESENCE requires provisioning
4058 return true;
4059 }
4060 break;
4061 }
4062 }
4063 return false;
4064 }
4065
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004066 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004067 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4069 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4070 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004071 enforceReadPrivilegedPermission("getImsProvisioningInt");
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004075 int slotId = getSlotIndex(subId);
4076 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4077 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4078 + subId + "' for key:" + key);
4079 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4080 }
4081 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004082 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004083 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4084 + subId + "' for key:" + key);
4085 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
4089 }
4090
4091 @Override
4092 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004093 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4094 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4095 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 enforceReadPrivilegedPermission("getImsProvisioningString");
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004100 int slotId = getSlotIndex(subId);
4101 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4102 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4103 + subId + "' for key:" + key);
4104 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4105 }
4106 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004108 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4109 + subId + "' for key:" + key);
4110 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
4114 }
4115
4116 @Override
4117 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004118 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4119 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4120 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4122 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 int slotId = getSlotIndex(subId);
4127 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4128 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4129 + subId + "' for key:" + key);
4130 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4131 }
4132 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4135 + "' for key:" + key);
4136 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4145 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4146 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4148 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 int slotId = getSlotIndex(subId);
4153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4154 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4155 + subId + "' for key:" + key);
4156 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4157 }
4158 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004160 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4161 + "' for key:" + key);
4162 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 }
4167
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004168 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 int slotId = SubscriptionManager.getSlotIndex(subId);
4170 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004171 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4172 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 }
4174 return slotId;
4175 }
4176
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 private int getSlotIndex(int subId) {
4178 int slotId = SubscriptionManager.getSlotIndex(subId);
4179 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4180 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4181 }
4182 return slotId;
4183 }
4184
Wink Saville36469e72014-06-11 15:17:00 -07004185 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004186 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004187 */
4188 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004189 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4190 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004191 final int targetSdk = getTargetSdk(callingPackage);
4192 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004193 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004194 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004195 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004196 mApp, subId, callingPackage, callingFeatureId,
4197 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004198 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4199 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 final Phone phone = getPhone(subId);
4204 if (phone != null) {
4205 return phone.getServiceState().getDataNetworkType();
4206 } else {
4207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4208 }
4209 } finally {
4210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004212 }
4213
4214 /**
4215 * Returns the data network type
4216 */
4217 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004218 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4219 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4220 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004221 }
4222
4223 /**
4224 * Returns the data network type for a subId
4225 */
4226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004227 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4228 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004230 mApp, subId, callingPackage, callingFeatureId,
4231 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004232 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4233 }
4234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 final Phone phone = getPhone(subId);
4238 if (phone != null) {
4239 return phone.getServiceState().getDataNetworkType();
4240 } else {
4241 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4242 }
4243 } finally {
4244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004246 }
4247
4248 /**
Wink Saville36469e72014-06-11 15:17:00 -07004249 * Returns the Voice network type for a subId
4250 */
4251 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004252 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4253 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004255 mApp, subId, callingPackage, callingFeatureId,
4256 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4258 }
4259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 final Phone phone = getPhone(subId);
4263 if (phone != null) {
4264 return phone.getServiceState().getVoiceNetworkType();
4265 } else {
4266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4267 }
4268 } finally {
4269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004271 }
4272
4273 /**
4274 * @return true if a ICC card is present
4275 */
4276 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004277 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004278 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4279 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004280 }
4281
4282 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004283 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004284 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004285 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004286 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 final Phone phone = PhoneFactory.getPhone(slotIndex);
4290 if (phone != null) {
4291 return phone.getIccCard().hasIccCard();
4292 } else {
4293 return false;
4294 }
4295 } finally {
4296 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004298 }
4299
4300 /**
4301 * Return if the current radio is LTE on CDMA. This
4302 * is a tri-state return value as for a period of time
4303 * the mode may be unknown.
4304 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004305 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004306 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004307 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004308 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004309 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004310 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4311 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4312 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004313 }
4314
Sanket Padawe356d7632015-06-22 14:03:32 -07004315 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004316 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4317 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004318 try {
4319 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4320 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004321 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4322 }
4323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 final Phone phone = getPhone(subId);
4327 if (phone == null) {
4328 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4329 } else {
4330 return phone.getLteOnCdmaMode();
4331 }
4332 } finally {
4333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004334 }
Wink Saville36469e72014-06-11 15:17:00 -07004335 }
4336
Wink Saville36469e72014-06-11 15:17:00 -07004337 /**
4338 * {@hide}
4339 * Returns Default subId, 0 in the case of single standby.
4340 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004341 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004342 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004343 }
4344
Shishir Agrawala9f32182016-04-12 12:00:16 -07004345 private int getSlotForDefaultSubscription() {
4346 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4347 }
4348
Wink Savilleb564aae2014-10-23 10:18:09 -07004349 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004350 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004351 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004352
Pengquan Menge92a50d2018-09-21 15:54:48 -07004353 private boolean isActiveSubscription(int subId) {
4354 return mSubscriptionController.isActiveSubId(subId);
4355 }
4356
Ihab Awadf2177b72013-11-25 13:33:23 -08004357 /**
4358 * @see android.telephony.TelephonyManager.WifiCallingChoices
4359 */
4360 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004363 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4365 getWhenToMakeWifiCallsDefaultPreference());
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004369 }
4370
4371 /**
4372 * @see android.telephony.TelephonyManager.WifiCallingChoices
4373 */
4374 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004378 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004383 }
4384
Sailesh Nepald1e68152013-12-12 19:08:02 -08004385 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004386 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004387 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004388 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004389
Jordan Liu4c733742019-02-28 12:03:40 -08004390 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4391 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4392 if (phoneId == -1) {
4393 throw new IllegalArgumentException("Given slot index: " + slotIndex
4394 + " does not correspond to an active phone");
4395 }
4396 return PhoneFactory.getPhone(phoneId);
4397 }
4398
Shishir Agrawal566b7612013-10-28 14:41:00 -07004399 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004400 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4401 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4403 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004405 if (DBG) {
4406 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4407 }
4408 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4409 p2);
4410 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004411
Jordan Liu4c733742019-02-28 12:03:40 -08004412
4413 @Override
4414 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4415 int slotIndex, String callingPackage, String aid, int p2) {
4416 enforceModifyPermission();
4417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4418 if (DBG) {
4419 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4420 }
4421 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4422 callingPackage, aid, p2);
4423 }
4424
4425 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4426 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 if (TextUtils.equals(ISDR_AID, aid)) {
4430 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004431 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4432 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 if (bestComponent == null
4434 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4435 loge("The calling package is not allowed to access ISD-R.");
4436 throw new SecurityException(
4437 "The calling package is not allowed to access ISD-R.");
4438 }
Derek Tan740e1672017-06-27 14:56:27 -07004439 }
Derek Tan740e1672017-06-27 14:56:27 -07004440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004442 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4443 null /* workSource */);
4444 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 return response;
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004449 }
4450
4451 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004452 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4454 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004455 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4456 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004458
Jordan Liu4c733742019-02-28 12:03:40 -08004459 @Override
4460 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4461 enforceModifyPermission();
4462 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4463 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4464 channel);
4465 }
4466
4467 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 if (channel < 0) {
4471 return false;
4472 }
Jordan Liu4c733742019-02-28 12:03:40 -08004473 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4474 null /* workSource */);
4475 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 return success;
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004479 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004480 }
4481
4482 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004483 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004484 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4486 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004487 if (DBG) {
4488 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4489 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4490 + p3 + " data=" + data);
4491 }
4492 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4493 command, p1, p2, p3, data);
4494 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004495
Jordan Liu4c733742019-02-28 12:03:40 -08004496 @Override
4497 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4498 int command, int p1, int p2, int p3, String data) {
4499 enforceModifyPermission();
4500 if (DBG) {
4501 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4502 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4503 + p3 + " data=" + data);
4504 }
4505 return iccTransmitApduLogicalChannelWithPermission(
4506 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4507 data);
4508 }
4509
4510 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4511 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 final long identity = Binder.clearCallingIdentity();
4513 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004514 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 return "";
4516 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004519 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4520 null /* workSource */);
4521 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 // Append the returned status code to the end of the response payload.
4524 String s = Integer.toHexString(
4525 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4526 if (response.payload != null) {
4527 s = IccUtils.bytesToHexString(response.payload) + s;
4528 }
4529 return s;
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533 }
Jake Hambye994d462014-02-03 13:10:13 -08004534
Evan Charltonc66da362014-05-16 14:06:40 -07004535 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004536 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4537 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4539 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004541 if (DBG) {
4542 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4543 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4544 }
4545 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4546 cla, command, p1, p2, p3, data);
4547 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004548
Jordan Liu4c733742019-02-28 12:03:40 -08004549 @Override
4550 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4551 int command, int p1, int p2, int p3, String data) {
4552 enforceModifyPermission();
4553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4554 if (DBG) {
4555 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4556 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4557 + " data=" + data);
4558 }
4559
4560 return iccTransmitApduBasicChannelWithPermission(
4561 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4562 p2, p3, data);
4563 }
4564
4565 // open APDU basic channel assuming the caller has sufficient permissions
4566 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4567 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4571 && TextUtils.equals(ISDR_AID, data)) {
4572 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004573 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4574 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 if (bestComponent == null
4576 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4577 loge("The calling package is not allowed to select ISD-R.");
4578 throw new SecurityException(
4579 "The calling package is not allowed to select ISD-R.");
4580 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004581 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004584 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4585 null /* workSource */);
4586 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 // Append the returned status code to the end of the response payload.
4589 String s = Integer.toHexString(
4590 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4591 if (response.payload != null) {
4592 s = IccUtils.bytesToHexString(response.payload) + s;
4593 }
4594 return s;
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004597 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004598 }
4599
4600 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004601 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004602 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4604 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 if (DBG) {
4609 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4610 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4611 }
4612
4613 IccIoResult response =
4614 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4615 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4616 subId);
4617
4618 if (DBG) {
4619 log("Exchange SIM_IO [R]" + response);
4620 }
4621
4622 byte[] result = null;
4623 int length = 2;
4624 if (response.payload != null) {
4625 length = 2 + response.payload.length;
4626 result = new byte[length];
4627 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4628 } else {
4629 result = new byte[length];
4630 }
4631
4632 result[length - 1] = (byte) response.sw2;
4633 result[length - 2] = (byte) response.sw1;
4634 return result;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004637 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004638 }
4639
Nathan Haroldb3014052017-01-25 15:57:32 -08004640 /**
4641 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4642 * on a particular subscription
4643 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004644 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4645 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004647 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004648 return null;
4649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650
4651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 if (appType != TelephonyManager.APPTYPE_USIM
4654 && appType != TelephonyManager.APPTYPE_SIM) {
4655 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4656 return null;
4657 }
4658 Object response = sendRequest(
4659 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4660 if (response instanceof String[]) {
4661 return (String[]) response;
4662 }
yincheng zhaod698b842019-09-06 17:06:54 -07004663 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004665 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004668 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004669 }
4670
yincheng zhaod698b842019-09-06 17:06:54 -07004671 /**
4672 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4673 * subscription.
4674 *
4675 * @param subId the id of the subscription.
4676 * @param appType the uicc app type, must be USIM or SIM.
4677 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4678 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004679 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004680 * @return number of fplmns that is successfully written to the SIM.
4681 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004682 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4683 String callingFeatureId) {
4684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4685 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004686 if (DBG) logv("no permissions for setForbiddenplmns");
4687 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4688 }
4689 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4690 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4691 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4692 }
4693 if (fplmns == null) {
4694 throw new IllegalArgumentException("Fplmn List provided is null");
4695 }
4696 for (String fplmn : fplmns) {
4697 if (!CellIdentity.isValidPlmn(fplmn)) {
4698 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4699 }
4700 }
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 Object response = sendRequest(
4704 CMD_SET_FORBIDDEN_PLMNS,
4705 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4706 subId);
4707 return (int) response;
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
4711 }
4712
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004713 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004714 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4716 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4721 if (response.payload == null) {
4722 return "";
4723 }
Evan Charltonc66da362014-05-16 14:06:40 -07004724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 // Append the returned status code to the end of the response payload.
4726 String s = Integer.toHexString(
4727 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4728 s = IccUtils.bytesToHexString(response.payload) + s;
4729 return s;
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
Evan Charltonc66da362014-05-16 14:06:40 -07004733 }
4734
Jake Hambye994d462014-02-03 13:10:13 -08004735 /**
4736 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4737 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4738 *
4739 * @param itemID the ID of the item to read
4740 * @return the NV item as a String, or null on error.
4741 */
4742 @Override
4743 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4746 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747
4748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004751 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4753 return value;
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
Jake Hambye994d462014-02-03 13:10:13 -08004757 }
4758
4759 /**
4760 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4761 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4762 *
4763 * @param itemID the ID of the item to read
4764 * @param itemValue the value to write, as a String
4765 * @return true on success; false on any failure
4766 */
4767 @Override
4768 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004769 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4771 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772
4773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4776 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004777 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4779 return success;
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Jake Hambye994d462014-02-03 13:10:13 -08004783 }
4784
4785 /**
4786 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4787 * Used for device configuration by some CDMA operators.
4788 *
4789 * @param preferredRoamingList byte array containing the new PRL
4790 * @return true on success; false on any failure
4791 */
4792 @Override
4793 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4795 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796
4797 final long identity = Binder.clearCallingIdentity();
4798 try {
4799 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4800 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4801 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4802 return success;
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Jake Hambye994d462014-02-03 13:10:13 -08004806 }
4807
4808 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004809 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004810 * Used for device configuration by some CDMA operators.
4811 *
chen xu6dac5ab2018-10-26 17:39:23 -07004812 * @param slotIndex - device slot.
4813 *
Jake Hambye994d462014-02-03 13:10:13 -08004814 * @return true on success; false on any failure
4815 */
4816 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004817 public boolean resetModemConfig(int slotIndex) {
4818 Phone phone = PhoneFactory.getPhone(slotIndex);
4819 if (phone != null) {
4820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
chen xu6dac5ab2018-10-26 17:39:23 -07004823 final long identity = Binder.clearCallingIdentity();
4824 try {
4825 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4826 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4827 return success;
4828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 }
chen xu6dac5ab2018-10-26 17:39:23 -07004832 return false;
4833 }
4834
4835 /**
4836 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4837 *
4838 * @param slotIndex - device slot.
4839 *
4840 * @return true on success; false on any failure
4841 */
4842 @Override
4843 public boolean rebootModem(int slotIndex) {
4844 Phone phone = PhoneFactory.getPhone(slotIndex);
4845 if (phone != null) {
4846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, phone.getSubId(), "rebootModem");
4848
4849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4852 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4853 return success;
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
4857 }
4858 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004859 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004860
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004861 public String[] getPcscfAddress(String apnType, String callingPackage,
4862 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004863 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4865 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004866 return new String[0];
4867 }
4868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004871 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
Wink Saville36469e72014-06-11 15:17:00 -07004875 }
4876
Brad Ebinger51f743a2017-01-23 13:50:20 -08004877 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004878 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4879 * {@link #disableIms(int)}.
4880 * @param slotIndex device slot.
4881 */
4882 public void resetIms(int slotIndex) {
4883 enforceModifyPermission();
4884
4885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 if (mImsResolver == null) {
4888 // may happen if the does not support IMS.
4889 return;
4890 }
4891 mImsResolver.disableIms(slotIndex);
4892 mImsResolver.enableIms(slotIndex);
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
4898 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004899 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4900 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004901 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004902 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904
4905 final long identity = Binder.clearCallingIdentity();
4906 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004907 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004908 // may happen if the device does not support IMS.
4909 return;
4910 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004911 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004915 }
4916
4917 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004918 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4919 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004920 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004921 public void disableIms(int slotId) {
4922 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004926 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004927 // may happen if the device does not support IMS.
4928 return;
4929 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004930 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004934 }
4935
4936 /**
4937 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4938 * feature or {@link null} if the service is not available. If the feature is available, the
4939 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4940 */
4941 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004942 IImsServiceFeatureCallback callback) {
4943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
Brad Ebinger05f52c22019-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 null;
4950 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004951 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004955 }
4956
4957 /**
4958 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4959 * feature during emergency calling or {@link null} if the service is not available. If the
4960 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4961 * listener for feature updates.
4962 */
4963 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004968 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004969 // may happen if the device does not support IMS.
4970 return null;
4971 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004972 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004976 }
4977
Brad Ebinger5f64b052017-12-14 14:26:15 -08004978 /**
4979 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004980 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004981 */
4982 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger05f52c22019-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 Ebinger05f52c22019-12-05 13:03:21 -08004991 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004995 }
4996
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004997 /**
4998 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004999 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005000 */
5001 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
5004 final long identity = Binder.clearCallingIdentity();
5005 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005006 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005007 // may happen if the device does not support IMS.
5008 return null;
5009 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005010 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005014 }
5015
Brad Ebinger884c07b2018-02-15 16:17:40 -08005016 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005017 * Sets the ImsService Package Name that Telephony will bind to.
5018 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005019 * @param slotIndex the slot ID that the ImsService should bind for.
5020 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005021 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005022 * @param featureTypes An integer array of feature types associated with a packageName.
5023 * @param packageName The name of the package that the current configuration will be replaced
5024 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005025 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005026 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005027 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5028 int[] featureTypes, String packageName) {
5029 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5032 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005033 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005037 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005038 // may happen if the device does not support IMS.
5039 return false;
5040 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005041 Map<Integer, String> featureConfig = new HashMap<>();
5042 for (int featureType : featureTypes) {
5043 featureConfig.put(featureType, packageName);
5044 }
5045 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5046 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005050 }
5051
5052 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005053 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005054 *
5055 * @param slotId The slot that the ImsService is associated with.
5056 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5057 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005059 * @return the package name of the ImsService configuration.
5060 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005061 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5062 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005063 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005064 TelephonyPermissions
5065 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5066 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5067 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005071 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005072 // may happen if the device does not support IMS.
5073 return "";
5074 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005075 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005076 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5077 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 }
5082
Brad Ebinger77b832e2019-10-17 17:03:22 -07005083 /**
5084 * Get the MmTelFeature state associated with the requested subscription id.
5085 * @param subId The subscription that the MmTelFeature is associated with.
5086 * @param callback A callback with an integer containing the
5087 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5088 */
5089 @Override
5090 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5091 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5092 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5094 "IMS not available on device.");
5095 }
5096 final long token = Binder.clearCallingIdentity();
5097 try {
5098 int slotId = getSlotIndex(subId);
5099 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5100 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5101 + subId + "'");
5102 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5103 }
5104 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5105 try {
5106 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5107 } catch (RemoteException e) {
5108 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5109 + "Ignore");
5110 }
5111 });
5112 } finally {
5113 Binder.restoreCallingIdentity(token);
5114 }
5115 }
5116
Wink Saville36469e72014-06-11 15:17:00 -07005117 public void setImsRegistrationState(boolean registered) {
5118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119
5120 final long identity = Binder.clearCallingIdentity();
5121 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005122 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
Wink Saville36469e72014-06-11 15:17:00 -07005126 }
5127
5128 /**
Stuart Scott54788802015-03-30 13:18:01 -07005129 * Set the network selection mode to automatic.
5130 *
5131 */
5132 @Override
5133 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5135 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
shilufc958392020-01-20 11:36:01 -08005139 if (!isActiveSubscription(subId)) {
5140 return;
5141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5143 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Stuart Scott54788802015-03-30 13:18:01 -07005147 }
5148
Pengquan Mengea84e042018-09-20 14:57:26 -07005149 /**
5150 * Ask the radio to connect to the input network and change selection mode to manual.
5151 *
5152 * @param subId the id of the subscription.
5153 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5154 * the operator to attach to.
5155 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5156 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5157 * normal network selection next time.
5158 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005159 */
5160 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005161 public boolean setNetworkSelectionModeManual(
5162 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5164 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005165
5166 if (!isActiveSubscription(subId)) {
5167 return false;
5168 }
5169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005172 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005174 if (DBG) {
5175 log("setNetworkSelectionModeManual: subId: " + subId
5176 + " operator: " + operatorInfo);
5177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005182 }
5183
5184 /**
5185 * Scans for available networks.
5186 */
5187 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005188 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5189 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005192 LocationAccessPolicy.LocationPermissionResult locationResult =
5193 LocationAccessPolicy.checkLocationPermission(mApp,
5194 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5195 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005196 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005197 .setCallingPid(Binder.getCallingPid())
5198 .setCallingUid(Binder.getCallingUid())
5199 .setMethod("getCellNetworkScanResults")
5200 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5201 .build());
5202 switch (locationResult) {
5203 case DENIED_HARD:
5204 throw new SecurityException("Not allowed to access scan results -- location");
5205 case DENIED_SOFT:
5206 return null;
5207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208
Pengquan Menga1bb6272018-09-06 09:59:22 -07005209 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 try {
5211 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005212 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005217 }
5218
5219 /**
sqian80370722020-01-29 15:02:51 -08005220 * Get the call forwarding info, given the call forwarding reason.
5221 */
5222 @Override
5223 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5224 enforceReadPrivilegedPermission("getCallForwarding");
5225 long identity = Binder.clearCallingIdentity();
5226 try {
5227 if (DBG) {
5228 log("getCallForwarding: subId " + subId
5229 + " callForwardingReason" + callForwardingReason);
5230 }
5231 return (CallForwardingInfo) sendRequest(
5232 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
5236 }
5237
5238 /**
5239 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5240 * reason, the number to forward, and the timeout before the forwarding is attempted.
5241 */
5242 @Override
5243 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5244 enforceModifyPermission();
5245 long identity = Binder.clearCallingIdentity();
5246 try {
5247 if (DBG) {
5248 log("setCallForwarding: subId " + subId
5249 + " callForwardingInfo" + callForwardingInfo);
5250 }
5251 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
5255 }
5256
5257 /**
5258 * Get the call forwarding info, given the call forwarding reason.
5259 */
5260 @Override
5261 public int getCallWaitingStatus(int subId) {
5262 enforceReadPrivilegedPermission("getCallForwarding");
5263 long identity = Binder.clearCallingIdentity();
5264 try {
5265 if (DBG) log("getCallWaitingStatus: subId " + subId);
5266 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
5270 }
5271
5272 /**
5273 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5274 * reason, the number to forward, and the timeout before the forwarding is attempted.
5275 */
5276 @Override
5277 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5278 enforceModifyPermission();
5279 long identity = Binder.clearCallingIdentity();
5280 try {
5281 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5282 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
5288 /**
yinxub1bed742017-04-17 11:45:04 -07005289 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005290 *
yinxub1bed742017-04-17 11:45:04 -07005291 * @param subId id of the subscription
5292 * @param request contains the radio access networks with bands/channels to scan
5293 * @param messenger callback messenger for scan results or errors
5294 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005295 * @return the id of the requested scan which can be used to stop the scan.
5296 */
5297 @Override
5298 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005299 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005302 LocationAccessPolicy.LocationPermissionResult locationResult =
5303 LocationAccessPolicy.checkLocationPermission(mApp,
5304 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5305 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005306 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005307 .setCallingPid(Binder.getCallingPid())
5308 .setCallingUid(Binder.getCallingUid())
5309 .setMethod("requestNetworkScan")
5310 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5311 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005312 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005313 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005314 if (e != null) {
5315 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5316 throw e;
5317 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005318 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005319 return TelephonyScanManager.INVALID_SCAN_ID;
5320 }
5321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 }
Hall Liu912dfd32019-04-25 14:02:26 -07005323 int callingUid = Binder.getCallingUid();
5324 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005325 final long identity = Binder.clearCallingIdentity();
5326 try {
5327 return mNetworkScanRequestTracker.startNetworkScan(
5328 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005329 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
yinxu504e1392017-04-12 16:03:22 -07005333 }
5334
Hall Liub2ac8ef2019-02-28 15:56:23 -08005335 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005336 NetworkScanRequest request, int subId) {
5337 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5338 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5339 boolean hasNetworkScanPermission =
5340 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5341 == PERMISSION_GRANTED;
5342
5343 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5344 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5345 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005346 }
5347
5348 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5349 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005350 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5351 return new SecurityException("Specific channels must not be"
5352 + " scanned without location access.");
5353 }
5354 }
5355 }
5356
Hall Liub2ac8ef2019-02-28 15:56:23 -08005357 return null;
5358 }
5359
yinxu504e1392017-04-12 16:03:22 -07005360 /**
5361 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005362 *
5363 * @param subId id of the subscription
5364 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005365 */
5366 @Override
5367 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5369 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370
Hall Liu912dfd32019-04-25 14:02:26 -07005371 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005374 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
yinxu504e1392017-04-12 16:03:22 -07005378 }
5379
5380 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005381 * Get the calculated preferred network type.
5382 * Used for debugging incorrect network type.
5383 *
5384 * @return the preferred network type, defined in RILConstants.java.
5385 */
5386 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005387 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 final Phone defaultPhone = getDefaultPhone();
5389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005390 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005391 return RILConstants.PREFERRED_NETWORK_MODE;
5392 }
5393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
Junda Liu84d15a22014-07-02 11:21:04 -07005401 }
5402
5403 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005404 * Get the preferred network type.
5405 * Used for device configuration by some CDMA operators.
5406 *
5407 * @return the preferred network type, defined in RILConstants.java.
5408 */
5409 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005410 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005411 TelephonyPermissions
5412 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5413 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 if (DBG) log("getPreferredNetworkType");
5418 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5419 int networkType = (result != null ? result[0] : -1);
5420 if (DBG) log("getPreferredNetworkType: " + networkType);
5421 return networkType;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005425 }
5426
5427 /**
5428 * Set the preferred network type.
5429 * Used for device configuration by some CDMA operators.
5430 *
5431 * @param networkType the preferred network type, defined in RILConstants.java.
5432 * @return true on success; false on any failure.
5433 */
5434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005435 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438
5439 final long identity = Binder.clearCallingIdentity();
5440 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005441 Settings.Global.putInt(mApp.getContentResolver(),
5442 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5443 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 } finally {
5445 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005447 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005448
5449 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005450 * Get the allowed network types that store in the telephony provider.
5451 *
5452 * @param subId the id of the subscription.
5453 * @return allowedNetworkTypes the allowed network types.
5454 */
5455 @Override
5456 public long getAllowedNetworkTypes(int subId) {
5457 TelephonyPermissions
5458 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5459 mApp, subId, "getAllowedNetworkTypes");
5460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 return SubscriptionManager.getLongSubscriptionProperty(
5464 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
5468 }
5469
5470 /**
5471 * Set the allowed network types.
5472 *
5473 * @param subId the id of the subscription.
5474 * @param allowedNetworkTypes the allowed network types.
5475 * @return true on success; false on any failure.
5476 */
5477 @Override
5478 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5480 mApp, subId, "setAllowedNetworkTypes");
5481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 SubscriptionManager.setSubscriptionProperty(subId,
5484 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5485 String.valueOf(allowedNetworkTypes));
5486 return setPreferredNetworkTypesInternal(subId);
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
5490 }
5491
5492 private boolean setPreferredNetworkTypesInternal(int subId) {
5493 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5494 Settings.Global.getInt(mApp.getContentResolver(),
5495 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5496 RILConstants.PREFERRED_NETWORK_MODE));
5497 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5498 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5499 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5500 (int) (networkTypeBitMask & allowedNetworkTypes));
5501
5502 if (DBG) {
5503 log("setPreferredNetworkTypesInternal: subId " + subId
5504 + " networkTypes " + networkTypeBitMask
5505 + " allowedNetworkTypes " + allowedNetworkTypes
5506 + " networkMode " + networkMode);
5507 }
5508
5509 Boolean success = (Boolean) sendRequest(
5510 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5511 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5512 return success;
5513 }
5514
5515 /**
Miaoa84611c2019-03-15 09:21:10 +08005516 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005517 *
Miaoa84611c2019-03-15 09:21:10 +08005518 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005519 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005520 * @hide
5521 */
5522 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005523 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005526 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 try {
Miaoa84611c2019-03-15 09:21:10 +08005528 if (phone != null) {
5529 return phone.hasMatchedTetherApnSetting();
5530 } else {
5531 return false;
5532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005535 }
Junda Liu475951f2014-11-07 16:45:03 -08005536 }
5537
5538 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005539 * Set mobile data enabled
5540 * Used by the user through settings etc to turn on/off mobile data
5541 *
5542 * @param enable {@code true} turn turn data on, else {@code false}
5543 */
5544 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005545 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5547 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 int phoneId = mSubscriptionController.getPhoneId(subId);
5552 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5553 Phone phone = PhoneFactory.getPhone(phoneId);
5554 if (phone != null) {
5555 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005556 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005558 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 }
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005562 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005563 }
5564
5565 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005566 * Enable or disable always reporting signal strength changes from radio.
5567 *
5568 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5569 */
5570 @Override
5571 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5572 enforceModifyPermission();
5573 enforceSystemCaller();
5574
5575 final long identity = Binder.clearCallingIdentity();
5576 final Phone phone = getPhone(subId);
5577 try {
5578 if (phone != null) {
5579 if (DBG) {
5580 log("setAlwaysReportSignalStrength: subId=" + subId
5581 + " isEnable=" + isEnable);
5582 }
5583 phone.setAlwaysReportSignalStrength(isEnable);
5584 } else {
5585 loge("setAlwaysReportSignalStrength: no phone found for subId="
5586 + subId);
5587 }
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
5591 }
5592
5593 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005594 * Get the user enabled state of Mobile Data.
5595 *
5596 * TODO: remove and use isUserDataEnabled.
5597 * This can't be removed now because some vendor codes
5598 * calls through ITelephony directly while they should
5599 * use TelephonyManager.
5600 *
5601 * @return true on enabled
5602 */
5603 @Override
5604 public boolean getDataEnabled(int subId) {
5605 return isUserDataEnabled(subId);
5606 }
5607
5608 /**
5609 * Get whether mobile data is enabled per user setting.
5610 *
5611 * There are other factors deciding whether mobile data is actually enabled, but they are
5612 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005613 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005614 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005615 *
5616 * @return {@code true} if data is enabled else {@code false}
5617 */
5618 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005619 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005620 try {
5621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5622 null);
5623 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5625 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 int phoneId = mSubscriptionController.getPhoneId(subId);
5631 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5632 Phone phone = PhoneFactory.getPhone(phoneId);
5633 if (phone != null) {
5634 boolean retVal = phone.isUserDataEnabled();
5635 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5636 return retVal;
5637 } else {
5638 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5639 return false;
5640 }
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005643 }
5644 }
5645
5646 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005647 * Checks if the device is capable of mobile data by considering whether whether the
5648 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5649 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005650 *
Shuo Qian985d1232020-01-08 14:30:06 -08005651 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005652 */
5653 @Override
5654 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005655 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 int phoneId = mSubscriptionController.getPhoneId(subId);
5660 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5661 Phone phone = PhoneFactory.getPhone(phoneId);
5662 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005663 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5665 return retVal;
5666 } else {
5667 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5668 return false;
5669 }
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005672 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005673 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005674
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005675 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5676 Phone phone) {
5677 //load access rules from carrier configs, and check those as well: b/139133814
5678 SubscriptionController subController = SubscriptionController.getInstance();
5679 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5680 || subController == null) return privilegeFromSim;
5681
5682 int uid = Binder.getCallingUid();
5683 PackageManager pkgMgr = phone.getContext().getPackageManager();
5684 String[] packages = pkgMgr.getPackagesForUid(uid);
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5689 SubscriptionManager subManager = (SubscriptionManager)
5690 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5691 for (String pkg : packages) {
5692 if (subManager.canManageSubscription(subInfo, pkg)) {
5693 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5694 }
5695 }
5696 return privilegeFromSim;
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701
5702 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5703 String pkgName) {
5704 //load access rules from carrier configs, and check those as well: b/139133814
5705 SubscriptionController subController = SubscriptionController.getInstance();
5706 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5707 || subController == null) return privilegeFromSim;
5708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5712 SubscriptionManager subManager = (SubscriptionManager)
5713 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5714 return subManager.canManageSubscription(subInfo, pkgName)
5715 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
5719 }
5720
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005722 public int getCarrierPrivilegeStatus(int subId) {
5723 final Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 loge("getCarrierPrivilegeStatus: Invalid subId");
5726 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5727 }
5728 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005729 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005730 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5732 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005733
5734 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5735 card.getCarrierPrivilegeStatusForCurrentTransaction(
5736 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005737 }
Junda Liu29340342014-07-10 15:23:27 -07005738
5739 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005740 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005741 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005742 final Phone phone = getPhone(subId);
5743 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005744 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5746 }
5747 UiccProfile profile =
5748 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5749 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005750 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5752 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005753 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005754 profile.getCarrierPrivilegeStatusForUid(
5755 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005756 }
5757
5758 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005759 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5760 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005762 }
5763
5764 int phoneId = SubscriptionManager.getPhoneId(subId);
5765 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005766 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005767 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5769 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005770 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5771 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5772 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005773 }
5774
5775 @Override
5776 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005777 if (TextUtils.isEmpty(pkgName))
5778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005779 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5780 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5781 UiccCard card = UiccController.getInstance().getUiccCard(i);
5782 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005783 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005784 continue;
5785 }
5786
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005787 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5788 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5789 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005790 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5791 break;
5792 }
5793 }
5794
5795 return result;
Junda Liu29340342014-07-10 15:23:27 -07005796 }
Derek Tan89e89d42014-07-08 17:00:10 -07005797
5798 @Override
Junda Liue64de782015-04-16 17:19:16 -07005799 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5800 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5801 loge("phoneId " + phoneId + " is not valid.");
5802 return null;
5803 }
5804 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005805 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005806 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005807 return null ;
5808 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005809 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005810 }
5811
Amith Yamasani6e118872016-02-19 12:53:51 -08005812 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005813 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005814 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005815 List<String> privilegedPackages = new ArrayList<>();
5816 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005817 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5818 // has UICC in that slot.
5819 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005820 if (card.hasCarrierPrivilegeRules()) {
5821 if (packages == null) {
5822 // Only check packages in user 0 for now
5823 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005824 PackageManager.MATCH_DISABLED_COMPONENTS
5825 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005826 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005827 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005828 }
5829 for (int p = packages.size() - 1; p >= 0; p--) {
5830 PackageInfo pkgInfo = packages.get(p);
5831 if (pkgInfo != null && pkgInfo.packageName != null
5832 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005833 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005834 privilegedPackages.add(pkgInfo.packageName);
5835 }
5836 }
5837 }
5838 }
5839 return privilegedPackages;
5840 }
5841
chen xuf7e9fe82019-05-09 19:31:02 -07005842 @Override
5843 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005844 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5845
5846 final long identity = Binder.clearCallingIdentity();
5847
chen xuf7e9fe82019-05-09 19:31:02 -07005848 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005849 try {
5850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5851 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5852 }
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005855 }
5856 return privilegedPackages;
5857 }
5858
Wink Savilleb564aae2014-10-23 10:18:09 -07005859 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005860 final Phone phone = getPhone(subId);
5861 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005862 if (card == null) {
5863 loge("getIccId: No UICC");
5864 return null;
5865 }
5866 String iccId = card.getIccId();
5867 if (TextUtils.isEmpty(iccId)) {
5868 loge("getIccId: ICC ID is null or empty.");
5869 return null;
5870 }
5871 return iccId;
5872 }
5873
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005874 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005875 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5876 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005878 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 final String iccId = getIccId(subId);
5883 final Phone phone = getPhone(subId);
5884 if (phone == null) {
5885 return false;
5886 }
5887 final String subscriberId = phone.getSubscriberId();
5888
5889 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005890 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 + subscriberId + " to " + number);
5892 }
5893
5894 if (TextUtils.isEmpty(iccId)) {
5895 return false;
5896 }
5897
5898 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5899
5900 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5901 if (alphaTag == null) {
5902 editor.remove(alphaTagPrefKey);
5903 } else {
5904 editor.putString(alphaTagPrefKey, alphaTag);
5905 }
5906
5907 // Record both the line number and IMSI for this ICCID, since we need to
5908 // track all merged IMSIs based on line number
5909 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5910 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5911 if (number == null) {
5912 editor.remove(numberPrefKey);
5913 editor.remove(subscriberPrefKey);
5914 } else {
5915 editor.putString(numberPrefKey, number);
5916 editor.putString(subscriberPrefKey, subscriberId);
5917 }
5918
5919 editor.commit();
5920 return true;
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005923 }
Derek Tan7226c842014-07-02 17:42:23 -07005924 }
5925
5926 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005927 public String getLine1NumberForDisplay(int subId, String callingPackage,
5928 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005929 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005931 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005932 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005933 return null;
5934 }
Derek Tan97ebb422014-09-05 16:55:38 -07005935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 final long identity = Binder.clearCallingIdentity();
5937 try {
5938 String iccId = getIccId(subId);
5939 if (iccId != null) {
5940 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5941 if (DBG_MERGE) {
5942 log("getLine1NumberForDisplay returning "
5943 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5944 }
5945 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5948 return null;
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005951 }
Derek Tan7226c842014-07-02 17:42:23 -07005952 }
5953
5954 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005955 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5956 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005958 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005959 return null;
5960 }
Derek Tan97ebb422014-09-05 16:55:38 -07005961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 String iccId = getIccId(subId);
5965 if (iccId != null) {
5966 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5967 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5968 }
5969 return null;
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005972 }
Derek Tan7226c842014-07-02 17:42:23 -07005973 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005974
5975 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005976 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5977 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005978 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5979 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005981 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005982 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005983 return null;
5984 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005985
Jordan Liub49b04b2019-05-06 14:45:15 -07005986 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5987 // the process, where TelephonyManager was instantiated.
5988 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005989 final long identity = Binder.clearCallingIdentity();
5990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005991 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final TelephonyManager tele = TelephonyManager.from(context);
5993 final SubscriptionManager sub = SubscriptionManager.from(context);
5994
5995 // Figure out what subscribers are currently active
5996 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997
Jordan Liub49b04b2019-05-06 14:45:15 -07005998 // Only consider subs which match the current subId
5999 // This logic can be simplified. See b/131189269 for progress.
6000 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006001 activeSubscriberIds.add(tele.getSubscriberId(subId));
6002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 // First pass, find a number override for an active subscriber
6005 String mergeNumber = null;
6006 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6007 for (String key : prefs.keySet()) {
6008 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6009 final String subscriberId = (String) prefs.get(key);
6010 if (activeSubscriberIds.contains(subscriberId)) {
6011 final String iccId = key.substring(
6012 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6013 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6014 mergeNumber = (String) prefs.get(numberKey);
6015 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006016 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 + " for active subscriber " + subscriberId);
6018 }
6019 if (!TextUtils.isEmpty(mergeNumber)) {
6020 break;
6021 }
6022 }
6023 }
6024 }
6025
6026 // Shortcut when no active merged subscribers
6027 if (TextUtils.isEmpty(mergeNumber)) {
6028 return null;
6029 }
6030
6031 // Second pass, find all subscribers under that line override
6032 final ArraySet<String> result = new ArraySet<>();
6033 for (String key : prefs.keySet()) {
6034 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6035 final String number = (String) prefs.get(key);
6036 if (mergeNumber.equals(number)) {
6037 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6038 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6039 final String subscriberId = (String) prefs.get(subscriberKey);
6040 if (!TextUtils.isEmpty(subscriberId)) {
6041 result.add(subscriberId);
6042 }
6043 }
6044 }
6045 }
6046
6047 final String[] resultArray = result.toArray(new String[result.size()]);
6048 Arrays.sort(resultArray);
6049 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006050 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6052 }
6053 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006056 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006057 }
6058
6059 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006060 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6061 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6062
6063 final long identity = Binder.clearCallingIdentity();
6064 try {
6065 final TelephonyManager telephonyManager = mApp.getSystemService(
6066 TelephonyManager.class);
6067 String subscriberId = telephonyManager.getSubscriberId(subId);
6068 if (subscriberId == null) {
6069 if (DBG) {
6070 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6071 + subId);
6072 }
6073 return null;
6074 }
6075
6076 final SubscriptionInfo info = SubscriptionController.getInstance()
6077 .getSubscriptionInfo(subId);
6078 final ParcelUuid groupUuid = info.getGroupUuid();
6079 // If it doesn't belong to any group, return just subscriberId of itself.
6080 if (groupUuid == null) {
6081 return new String[]{subscriberId};
6082 }
6083
6084 // Get all subscriberIds from the group.
6085 final List<String> mergedSubscriberIds = new ArrayList<>();
6086 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006087 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6088 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006089 for (SubscriptionInfo subInfo : groupInfos) {
6090 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6091 if (subscriberId != null) {
6092 mergedSubscriberIds.add(subscriberId);
6093 }
6094 }
6095
6096 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099
6100 }
6101 }
6102
6103 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006104 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006106 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 final Phone phone = getPhone(subId);
6111 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006115 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006116
6117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006118 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006119 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6120 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6122 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123
6124 final long identity = Binder.clearCallingIdentity();
6125 try {
6126 final Phone phone = getPhone(subId);
6127 if (phone == null) {
6128 return false;
6129 }
6130 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6131 cdmaNonRoamingList);
6132 } finally {
6133 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006134 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006135 }
6136
6137 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006138 @Deprecated
6139 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6140 enforceModifyPermission();
6141
6142 int returnValue = 0;
6143 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006144 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006145 if(result.exception == null) {
6146 if (result.result != null) {
6147 byte[] responseData = (byte[])(result.result);
6148 if(responseData.length > oemResp.length) {
6149 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6150 responseData.length + "bytes. Buffer Size is " +
6151 oemResp.length + "bytes.");
6152 }
6153 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6154 returnValue = responseData.length;
6155 }
6156 } else {
6157 CommandException ex = (CommandException) result.exception;
6158 returnValue = ex.getCommandError().ordinal();
6159 if(returnValue > 0) returnValue *= -1;
6160 }
6161 } catch (RuntimeException e) {
6162 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6163 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6164 if(returnValue > 0) returnValue *= -1;
6165 }
6166
6167 return returnValue;
6168 }
6169
6170 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006171 public void setRadioCapability(RadioAccessFamily[] rafs) {
6172 try {
6173 ProxyController.getInstance().setRadioCapability(rafs);
6174 } catch (RuntimeException e) {
6175 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6176 }
6177 }
6178
6179 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006180 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006181 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006182 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006183 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006184 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
chen xub97461a2018-10-26 14:17:57 -07006188 TelephonyPermissions
6189 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6190 mApp, phone.getSubId(), "getRadioAccessFamily");
6191 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
chen xub97461a2018-10-26 14:17:57 -07006195 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006196 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006197
6198 @Override
6199 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006205 ImsManager.getInstance(defaultPhone.getContext(),
6206 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006210 }
6211
6212 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006213 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006214 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6216 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006217 return false;
6218 }
Svet Ganovb320e182015-04-16 12:30:10 -07006219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 // Check the user preference and the system-level IMS setting. Even if the user has
6223 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6224 // In the long run, we may instead need to check if there exists a connection service
6225 // which can support video calling.
6226 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006227 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 return imsManager.isVtEnabledByPlatform()
6229 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6230 && imsManager.isVtEnabledByUser();
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006234 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006235
Andrew Leea1239f22015-03-02 17:44:07 -08006236 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006237 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6238 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006240 mApp, subId, callingPackage, callingFeatureId,
6241 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 return false;
6243 }
6244
6245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 CarrierConfigManager configManager =
6248 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006249 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
6253 }
Andrew Leea1239f22015-03-02 17:44:07 -08006254 }
6255
6256 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006257 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006259 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 return false;
6261 }
6262
6263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 CarrierConfigManager configManager =
6266 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006267 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
Andrew Leea1239f22015-03-02 17:44:07 -08006272 }
6273
Andrew Lee9431b832015-03-09 18:46:45 -07006274 @Override
6275 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006276 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006277 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006278 }
6279
6280 @Override
6281 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
Andrew Lee9431b832015-03-09 18:46:45 -07006288 }
6289
Hall Liuf6668912018-10-31 17:05:23 -07006290 /**
6291 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6292 * support for the feature and device firmware support.
6293 *
6294 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6295 */
6296 @Override
6297 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006299 final Phone phone = getPhone(subscriptionId);
6300 if (phone == null) {
6301 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6302 return false;
6303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6307 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006308 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 return isCarrierSupported && isDeviceSupported;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
Hall Liu98187582018-01-22 19:15:32 -08006313 }
6314
Hall Liuf6668912018-10-31 17:05:23 -07006315 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006316 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6317 * RTT setting, will return true if the device and carrier both support RTT.
6318 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006319 */
6320 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006323 boolean isRttSupported = isRttSupported(subscriptionId);
6324 boolean isUserRttSettingOn = Settings.Secure.getInt(
6325 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6326 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6327 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6328 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006332 }
6333
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006334 @Deprecated
6335 @Override
6336 public String getDeviceId(String callingPackage) {
6337 return getDeviceIdWithFeature(callingPackage, null);
6338 }
6339
Sanket Padawe7310cc72015-01-14 09:53:20 -08006340 /**
6341 * Returns the unique device ID of phone, for example, the IMEI for
6342 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6343 *
6344 * <p>Requires Permission:
6345 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6346 */
6347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006348 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006349 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006350 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006351 return null;
6352 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006353 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006354 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006355 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006356 return null;
6357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 return phone.getDeviceId();
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006365 }
6366
Ping Sunc67b7c22016-03-02 19:16:45 +08006367 /**
6368 * {@hide}
6369 * Returns the IMS Registration Status on a particular subid
6370 *
6371 * @param subId
6372 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006373 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006374 Phone phone = getPhone(subId);
6375 if (phone != null) {
6376 return phone.isImsRegistered();
6377 } else {
6378 return false;
6379 }
6380 }
6381
Santos Cordon7a1885b2015-02-03 11:15:19 -08006382 @Override
6383 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006390 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006391
Tyler Gunnf70ed162019-04-03 15:28:53 -07006392 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006393 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006394 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006396 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006397 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6398 }
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
6401 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
6405 }
6406
6407 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006408 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 Phone phone = getPhone(subscriptionId);
6412 if (phone == null) {
6413 return null;
6414 }
6415 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
6419 }
6420
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006421 /**
6422 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006423 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006424 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 Phone phone = getPhone(subId);
6428 if (phone != null) {
6429 return phone.isWifiCallingEnabled();
6430 } else {
6431 return false;
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006435 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006436 }
6437
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006438 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006440 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006441 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Phone phone = getPhone(subId);
6445 if (phone != null) {
6446 return phone.isVideoEnabled();
6447 } else {
6448 return false;
6449 }
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006452 }
6453 }
6454
6455 /**
6456 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6457 * defined in {@link ImsRegistrationImplBase}.
6458 */
6459 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 Phone phone = getPhone(subId);
6463 if (phone != null) {
6464 return phone.getImsRegistrationTech();
6465 } else {
6466 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6467 }
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006470 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006471 }
6472
Stuart Scott8eef64f2015-04-08 15:13:54 -07006473 @Override
6474 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006475 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006476 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6477 return;
6478 }
6479
Svet Ganovcc087f82015-05-12 20:35:54 -07006480 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006481
Svet Ganovcc087f82015-05-12 20:35:54 -07006482 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006483 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6484 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006485 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006486 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006487 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006488 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6489 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006490 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006491 // There has been issues when Sms raw table somehow stores orphan
6492 // fragments. They lead to garbled message when new fragments come
6493 // in and combined with those stale ones. In case this happens again,
6494 // user can reset all network settings which will clean up this table.
6495 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006496 // Clean up IMS settings as well here.
6497 int slotId = getSlotIndex(subId);
6498 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6499 ImsManager.getInstance(mApp, slotId).factoryReset();
6500 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006501
6502 // Erase modem config if erase modem on network setting is enabled.
6503 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6504 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6505 if (configValue != null && Boolean.parseBoolean(configValue)) {
6506 sendEraseModemConfig(getDefaultPhone());
6507 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006510 }
6511 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006512
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006513 private void cleanUpSmsRawTable(Context context) {
6514 ContentResolver resolver = context.getContentResolver();
6515 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6516 resolver.delete(uri, null, null);
6517 }
6518
Narayan Kamath1c496c22015-04-16 14:40:19 +01006519 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006520 public String getSimLocaleForSubscriber(int subId) {
6521 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6522 final Phone phone = getPhone(subId);
6523 if (phone == null) {
6524 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006525 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 final long identity = Binder.clearCallingIdentity();
6528 try {
chen xu5d3637b2019-01-21 23:31:38 -08006529 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006530 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006531 if (info == null) {
6532 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6533 return null;
6534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 // Try and fetch the locale from the carrier properties or from the SIM language
6536 // preferences (EF-PL and EF-LI)...
6537 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006539 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6540 if (localeFromDefaultSim != null) {
6541 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6542 if (DBG) log("Using locale from subId: " + subId + " locale: "
6543 + localeFromDefaultSim);
6544 return localeFromDefaultSim.toLanguageTag();
6545 } else {
6546 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 }
6548 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 // The SIM language preferences only store a language (e.g. fr = French), not an
6551 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6552 // the SIM and carrier preferences does not include a country we add the country
6553 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006554 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006556 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 return mccLocale.toLanguageTag();
6558 }
6559
6560 if (DBG) log("No locale found - returning null");
6561 return null;
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006565 }
6566
6567 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006568 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6569 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006570 }
6571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 /**
6573 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6574 */
6575 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006576 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6577 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006578 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006579
Chenjie Yu1ba97252018-01-11 18:16:20 -08006580 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006581 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006582
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006583 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006584 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6585 * representing the state of the modem.
6586 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006587 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6588 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006589 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006590 */
6591 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006592 public void requestModemActivityInfo(ResultReceiver result) {
6593 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 ModemActivityInfo ret = null;
6599 synchronized (mLastModemActivityInfo) {
6600 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6601 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006602 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006603 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006605 int[] txTimeMs = info.getTransmitTimeMillis();
6606 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006608 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 }
6610 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006611 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6612 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 mLastModemActivityInfo.setIdleTimeMillis(
6614 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006615 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6616 mLastModemActivityInfo.setReceiveTimeMillis(
6617 info.getReceiveTimeMillis() + mLastModemActivityInfo
6618 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006619 }
Chen Xu13851032019-09-10 18:49:52 -07006620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6622 mLastModemActivityInfo.getSleepTimeMillis(),
6623 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006624 mLastModemActivityInfo.getTransmitTimeMillis(),
6625 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 Bundle bundle = new Bundle();
6628 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6629 result.send(0, bundle);
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006632 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006633 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006634
Siddharth Rayb8114062018-06-17 15:02:38 -07006635 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6636 // less than total activity duration.
6637 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6638 if (info == null) {
6639 return false;
6640 }
6641 int activityDurationMs =
6642 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6643 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006644 int[] txTimeMs = info.getTransmitTimeMillis();
6645 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6646 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006647 }
6648 return (info.isValid()
6649 && (info.getSleepTimeMillis() <= activityDurationMs)
6650 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006651 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006652 && (totalTxTimeMs <= activityDurationMs));
6653 }
6654
Jack Yu85bd38a2015-11-09 11:34:32 -08006655 /**
6656 * {@hide}
6657 * Returns the service state information on specified subscription.
6658 */
6659 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006660 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6661 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006663 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006664 return null;
6665 }
6666
Hall Liuf19c44f2018-11-27 14:38:17 -08006667 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6668 LocationAccessPolicy.checkLocationPermission(mApp,
6669 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6670 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006671 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006672 .setCallingPid(Binder.getCallingPid())
6673 .setCallingUid(Binder.getCallingUid())
6674 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006675 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006676 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6677 .build());
6678
6679 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6680 LocationAccessPolicy.checkLocationPermission(mApp,
6681 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6682 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006683 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006684 .setCallingPid(Binder.getCallingPid())
6685 .setCallingUid(Binder.getCallingUid())
6686 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006687 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006688 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6689 .build());
6690 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6691 boolean hasFinePermission =
6692 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6693 boolean hasCoarsePermission =
6694 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 final long identity = Binder.clearCallingIdentity();
6697 try {
6698 final Phone phone = getPhone(subId);
6699 if (phone == null) {
6700 return null;
6701 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006702
Hall Liuf19c44f2018-11-27 14:38:17 -08006703 ServiceState ss = phone.getServiceState();
6704
6705 // Scrub out the location info in ServiceState depending on what level of access
6706 // the caller has.
6707 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006708 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6709 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006713 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006714
6715 /**
6716 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6717 *
6718 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6719 * voicemail ringtone.
6720 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6721 * PhoneAccount.
6722 */
6723 @Override
6724 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6728 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006729 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006736 }
6737
6738 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006739 * Sets the per-account voicemail ringtone.
6740 *
6741 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6742 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6743 *
6744 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6745 * voicemail ringtone.
6746 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6747 * PhoneAccount.
6748 */
6749 @Override
6750 public void setVoicemailRingtoneUri(String callingPackage,
6751 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006752 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006754 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6755 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6757 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6758 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6764 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006765 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 }
6767 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006770 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006771 }
6772
6773 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006774 * Returns whether vibration is set for voicemail notification in Phone settings.
6775 *
6776 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6777 * voicemail vibration setting.
6778 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6779 */
6780 @Override
6781 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6785 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006786 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006793 }
6794
Youhan Wange64578a2016-05-02 15:32:42 -07006795 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006796 * Sets the per-account voicemail vibration.
6797 *
6798 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6799 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6800 *
6801 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6802 * voicemail vibration setting.
6803 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6804 * specific PhoneAccount.
6805 */
6806 @Override
6807 public void setVoicemailVibrationEnabled(String callingPackage,
6808 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006809 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006811 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6812 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6814 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6815 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006816 }
6817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 final long identity = Binder.clearCallingIdentity();
6819 try {
6820 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6821 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006822 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 }
6824 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006827 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006828 }
6829
6830 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006831 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6832 *
6833 * @throws SecurityException if the caller does not have the required permission
6834 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006835 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006836 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006837 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006838 }
6839
6840 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006841 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6842 * permission.
6843 *
6844 * @throws SecurityException if the caller does not have the required permission
6845 */
6846 private void enforceSendSmsPermission() {
6847 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6848 }
6849
6850 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006851 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006852 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006853 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006854 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006855 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006859 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 if (componentName == null) {
6861 throw new SecurityException(
6862 "Caller not current active visual voicemail package[null]");
6863 }
6864 String vvmPackage = componentName.getPackageName();
6865 if (!callingPackage.equals(vvmPackage)) {
6866 throw new SecurityException("Caller not current active visual voicemail package["
6867 + vvmPackage + "]");
6868 }
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006871 }
6872 }
6873
6874 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006875 * Return the application ID for the app type.
6876 *
6877 * @param subId the subscription ID that this request applies to.
6878 * @param appType the uicc app type.
6879 * @return Application ID for specificied app type, or null if no uicc.
6880 */
6881 @Override
6882 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006883 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006884 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885
6886 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006887 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 if (phone == null) {
6889 return null;
6890 }
6891 String aid = null;
6892 try {
6893 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6894 .getApplicationByType(appType).getAid();
6895 } catch (Exception e) {
6896 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6897 }
6898 return aid;
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006901 }
Youhan Wange64578a2016-05-02 15:32:42 -07006902 }
6903
Youhan Wang4001d252016-05-11 10:29:41 -07006904 /**
6905 * Return the Electronic Serial Number.
6906 *
6907 * @param subId the subscription ID that this request applies to.
6908 * @return ESN or null if error.
6909 */
6910 @Override
6911 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006912 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006913 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914
6915 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006916 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 if (phone == null) {
6918 return null;
6919 }
6920 String esn = null;
6921 try {
6922 esn = phone.getEsn();
6923 } catch (Exception e) {
6924 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6925 }
6926 return esn;
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006929 }
Youhan Wang4001d252016-05-11 10:29:41 -07006930 }
6931
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006932 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006933 * Return the Preferred Roaming List Version.
6934 *
6935 * @param subId the subscription ID that this request applies to.
6936 * @return PRLVersion or null if error.
6937 */
6938 @Override
6939 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006940 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006941 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942
6943 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006944 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 if (phone == null) {
6946 return null;
6947 }
6948 String cdmaPrlVersion = null;
6949 try {
6950 cdmaPrlVersion = phone.getCdmaPrlVersion();
6951 } catch (Exception e) {
6952 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6953 }
6954 return cdmaPrlVersion;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006957 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006958 }
6959
6960 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006961 * Get snapshot of Telephony histograms
6962 * @return List of Telephony histograms
6963 * @hide
6964 */
6965 @Override
6966 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6968 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 return RIL.getTelephonyRILTimingHistograms();
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006976 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006977
6978 /**
6979 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006980 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6981 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006982 * Require system privileges. In the future we may add this to carrier APIs.
6983 *
Michele Berionne482f8202018-11-27 18:57:59 -08006984 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006985 */
6986 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006987 @TelephonyManager.SetCarrierRestrictionResult
6988 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006989 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006990 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006991
Michele Berionne482f8202018-11-27 18:57:59 -08006992 if (carrierRestrictionRules == null) {
6993 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006994 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 final long identity = Binder.clearCallingIdentity();
6997 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006998 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006999 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007003 }
7004
7005 /**
7006 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007007 * Get the allowed carrier list and the excluded carrier list, including the priority between
7008 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007009 * Require system privileges. In the future we may add this to carrier APIs.
7010 *
Michele Berionne482f8202018-11-27 18:57:59 -08007011 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007012 */
7013 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007014 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007015 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017
7018 final long identity = Binder.clearCallingIdentity();
7019 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007020 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7021 if (response instanceof CarrierRestrictionRules) {
7022 return (CarrierRestrictionRules) response;
7023 }
7024 // Response is an Exception of some kind,
7025 // which is signalled to the user as a NULL retval
7026 return null;
7027 } catch (Exception e) {
7028 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7029 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007033 }
7034
fionaxu59545b42016-05-25 15:53:37 -07007035 /**
7036 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7037 * @param subId the subscription ID that this action applies to.
7038 * @param enabled control enable or disable metered apns.
7039 * {@hide}
7040 */
7041 @Override
7042 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7043 enforceModifyPermission();
7044 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045
7046 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007047 if (phone == null) {
7048 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7049 return;
7050 }
7051 try {
7052 phone.carrierActionSetMeteredApnsEnabled(enabled);
7053 } catch (Exception e) {
7054 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 } finally {
7056 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007057 }
7058 }
7059
7060 /**
7061 * Action set from carrier signalling broadcast receivers to enable/disable radio
7062 * @param subId the subscription ID that this action applies to.
7063 * @param enabled control enable or disable radio.
7064 * {@hide}
7065 */
7066 @Override
7067 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7068 enforceModifyPermission();
7069 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070
7071 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007072 if (phone == null) {
7073 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7074 return;
7075 }
7076 try {
7077 phone.carrierActionSetRadioEnabled(enabled);
7078 } catch (Exception e) {
7079 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007082 }
7083 }
7084
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007085 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007086 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7087 * network status based on which carrier apps could apply actions accordingly,
7088 * enable/disable default url handler for example.
7089 *
7090 * @param subId the subscription ID that this action applies to.
7091 * @param report control start/stop reporting the default network status.
7092 * {@hide}
7093 */
7094 @Override
7095 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7096 enforceModifyPermission();
7097 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098
7099 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007100 if (phone == null) {
7101 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7102 return;
7103 }
7104 try {
7105 phone.carrierActionReportDefaultNetworkStatus(report);
7106 } catch (Exception e) {
7107 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 } finally {
7109 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007110 }
7111 }
7112
7113 /**
fionaxud9622282017-07-17 17:51:30 -07007114 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7115 * @param subId the subscription ID that this action applies to.
7116 * {@hide}
7117 */
7118 @Override
7119 public void carrierActionResetAll(int subId) {
7120 enforceModifyPermission();
7121 final Phone phone = getPhone(subId);
7122 if (phone == null) {
7123 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7124 return;
7125 }
7126 try {
7127 phone.carrierActionResetAll();
7128 } catch (Exception e) {
7129 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7130 }
7131 }
7132
7133 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007134 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7135 * bug report is being generated.
7136 */
7137 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007138 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7140 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007141 writer.println("Permission Denial: can't dump Phone from pid="
7142 + Binder.getCallingPid()
7143 + ", uid=" + Binder.getCallingUid()
7144 + "without permission "
7145 + android.Manifest.permission.DUMP);
7146 return;
7147 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007148 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007149 }
Jack Yueb89b242016-06-22 13:27:47 -07007150
Brad Ebingerdac2f002018-04-03 15:17:52 -07007151 @Override
7152 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7153 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7154 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007155 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7156 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007157 }
7158
Jack Yueb89b242016-06-22 13:27:47 -07007159 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007160 * Policy control of data connection. Usually used when data limit is passed.
7161 * @param enabled True if enabling the data, otherwise disabling.
7162 * @param subId Subscription index
7163 * {@hide}
7164 */
7165 @Override
7166 public void setPolicyDataEnabled(boolean enabled, int subId) {
7167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 Phone phone = getPhone(subId);
7172 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007173 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 }
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007177 }
7178 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007179
7180 /**
7181 * Get Client request stats
7182 * @return List of Client Request Stats
7183 * @hide
7184 */
7185 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007186 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7187 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007189 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007190 return null;
7191 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007192 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 if (phone != null) {
7197 return phone.getClientRequestStats();
7198 }
7199
7200 return null;
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007204 }
7205
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007206 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007207 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007208 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007209 }
Jack Yueb4124c2017-02-16 15:32:43 -08007210
7211 /**
Grace Chen70990072017-03-24 17:21:30 -07007212 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007213 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007214 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007215 * @param state State of SIM (power down, power up, pass through)
7216 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7217 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7218 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007219 *
7220 **/
7221 @Override
Grace Chen70990072017-03-24 17:21:30 -07007222 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007223 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007224 Phone phone = PhoneFactory.getPhone(slotIndex);
7225
vagdeviaf9a5b92018-08-15 16:01:53 -07007226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007231 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 }
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007235 }
7236 }
Shuo Qiandd210312017-04-12 22:11:33 +00007237
Tyler Gunn65d45c22017-06-05 11:22:26 -07007238 private boolean isUssdApiAllowed(int subId) {
7239 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007240 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007241 if (configManager == null) {
7242 return false;
7243 }
7244 PersistableBundle pb = configManager.getConfigForSubId(subId);
7245 if (pb == null) {
7246 return false;
7247 }
7248 return pb.getBoolean(
7249 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7250 }
7251
Shuo Qiandd210312017-04-12 22:11:33 +00007252 /**
7253 * Check if phone is in emergency callback mode
7254 * @return true if phone is in emergency callback mode
7255 * @param subId sub id
7256 */
goneil9c5f4872017-12-05 14:07:56 -08007257 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007258 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007259 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007260 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261
7262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 if (phone != null) {
7265 return phone.isInEcm();
7266 } else {
7267 return false;
7268 }
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007271 }
7272 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007273
7274 /**
7275 * Get the current signal strength information for the given subscription.
7276 * Because this information is not updated when the device is in a low power state
7277 * it should not be relied-upon to be current.
7278 * @param subId Subscription index
7279 * @return the most recent cached signal strength info from the modem
7280 */
7281 @Override
7282 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 Phone p = getPhone(subId);
7286 if (p == null) {
7287 return null;
7288 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 return p.getSignalStrength();
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007294 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007295
Pengquan Meng77b7f132018-08-22 14:49:57 -07007296 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007297 * Get the current modem radio state for the given slot.
7298 * @param slotIndex slot index.
7299 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007300 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007301 * @return the current radio power state from the modem
7302 */
7303 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007304 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007305 Phone phone = PhoneFactory.getPhone(slotIndex);
7306 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7308 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007309 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7310 }
7311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 return phone.getRadioPowerState();
7315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
7318 }
7319 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7320 }
7321
7322 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007323 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7324 *
7325 * <p>Requires one of the following permissions:
7326 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7327 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7328 * privileges.
7329 *
7330 * @param subId subscription id
7331 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7332 * {@code false}.
7333 */
7334 @Override
7335 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7337 null /* message */);
7338
Pengquan Menga1bb6272018-09-06 09:59:22 -07007339 boolean isEnabled = false;
7340 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007341 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007342 Phone phone = getPhone(subId);
7343 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007344 } catch (Exception e) {
7345 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7346 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007347 } finally {
7348 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007349 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007350 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007351 }
7352
7353
7354 /**
7355 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7356 *
7357 * <p> Requires permission:
7358 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7359 * privileges.
7360 *
7361 * @param subId subscription id
7362 * @param isEnabled {@code true} means enable, {@code false} means disable.
7363 */
7364 @Override
7365 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7367 mApp, subId, "setDataRoamingEnabled");
7368
Pengquan Menga1bb6272018-09-06 09:59:22 -07007369 final long identity = Binder.clearCallingIdentity();
7370 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007371 Phone phone = getPhone(subId);
7372 if (phone != null) {
7373 phone.setDataRoamingEnabled(isEnabled);
7374 }
7375 } finally {
7376 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007377 }
7378 }
7379
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007380 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007381 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007382 TelephonyPermissions
7383 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007384 mApp, subId, "isManualNetworkSelectionAllowed");
7385
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007386 boolean isAllowed = true;
7387 final long identity = Binder.clearCallingIdentity();
7388 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007389 Phone phone = getPhone(subId);
7390 if (phone != null) {
7391 isAllowed = phone.isCspPlmnEnabled();
7392 }
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
7396 return isAllowed;
7397 }
7398
7399 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007400 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007401 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007402 try {
7403 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007404 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007405 } catch (SecurityException e) {
7406 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7407 // has carrier privileges on an active UICC
7408 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7409 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007410 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007411 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007412 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007413
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007416 UiccController uiccController = UiccController.getInstance();
7417 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007418 if (hasReadPermission) {
7419 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007420 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007421
7422 // Remove private info if the caller doesn't have access
7423 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7424 for (UiccCardInfo cardInfo : cardInfos) {
7425 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7426 // is available
7427 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7428 if (card == null || card.getUiccProfile() == null) {
7429 // assume no access if the card or profile is unavailable
7430 filteredInfos.add(cardInfo.getUnprivileged());
7431 continue;
7432 }
7433 UiccProfile profile = card.getUiccProfile();
7434 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7435 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7436 filteredInfos.add(cardInfo);
7437 } else {
7438 filteredInfos.add(cardInfo.getUnprivileged());
7439 }
7440 }
7441 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
7445 }
7446
7447 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007448 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007449 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
7453 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7454 if (slots == null) {
7455 Rlog.i(LOG_TAG, "slots is null.");
7456 return null;
7457 }
7458
7459 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7460 for (int i = 0; i < slots.length; i++) {
7461 UiccSlot slot = slots[i];
7462 if (slot == null) {
7463 continue;
7464 }
7465
Jordan Liu7be7e652019-05-06 18:55:02 +00007466 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 UiccCard card = slot.getUiccCard();
7468 if (card != null) {
7469 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007470 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007471 cardId = slot.getEid();
7472 if (TextUtils.isEmpty(cardId)) {
7473 cardId = slot.getIccId();
7474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 }
7476
Jordan Liu857451f2019-05-09 16:35:35 -07007477 if (cardId != null) {
7478 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7479 // if cardId is an EID, it's all digits so this is fine
7480 cardId = IccUtils.stripTrailingFs(cardId);
7481 }
7482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 int cardState = 0;
7484 switch (slot.getCardState()) {
7485 case CARDSTATE_ABSENT:
7486 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7487 break;
7488 case CARDSTATE_PRESENT:
7489 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7490 break;
7491 case CARDSTATE_ERROR:
7492 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7493 break;
7494 case CARDSTATE_RESTRICTED:
7495 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7496 break;
7497 default:
7498 break;
7499
7500 }
7501
7502 infos[i] = new UiccSlotInfo(
7503 slot.isActive(),
7504 slot.isEuicc(),
7505 cardId,
7506 cardState,
7507 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007508 slot.isExtendedApduSupported(),
7509 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 }
7511 return infos;
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007514 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007515 }
7516
7517 @Override
7518 public boolean switchSlots(int[] physicalSlots) {
7519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007527 }
Jack Yu4c988042018-02-27 15:30:01 -08007528
7529 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007530 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 return UiccController.getInstance().getCardIdForDefaultEuicc();
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
7538
7539 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007540 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7541 enforceModifyPermission();
7542 final Phone phone = getPhone(subId);
7543 if (phone == null) {
7544 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7545 return;
7546 }
7547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 final long identity = Binder.clearCallingIdentity();
7549 try {
7550 phone.setRadioIndicationUpdateMode(filters, mode);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Jack Yu4c988042018-02-27 15:30:01 -08007554 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007555
7556 /**
goneil47ffb6e2018-04-06 15:40:58 -07007557 * A test API to reload the UICC profile.
7558 *
7559 * <p>Requires that the calling app has permission
7560 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7561 * @hide
7562 */
7563 @Override
7564 public void refreshUiccProfile(int subId) {
7565 enforceModifyPermission();
7566
7567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = getPhone(subId);
7570 if (phone == null) {
7571 return;
7572 }
7573 UiccCard uiccCard = phone.getUiccCard();
7574 if (uiccCard == null) {
7575 return;
7576 }
7577 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7578 if (uiccProfile == null) {
7579 return;
7580 }
7581 uiccProfile.refresh();
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
7587 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007588 * Returns false if the mobile data is disabled by default, otherwise return true.
7589 */
7590 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007591 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007592 }
7593
7594 /**
7595 * Returns true if the data roaming is enabled by default, i.e the system property
7596 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7597 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7598 */
7599 private boolean getDefaultDataRoamingEnabled(int subId) {
7600 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007602 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007603 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7604 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7605 return isDataRoamingEnabled;
7606 }
7607
7608 /**
7609 * Returns the default network type for the given {@code subId}, if the default network type is
7610 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7611 */
7612 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007613 List<Integer> list = TelephonyProperties.default_network();
7614 int phoneId = mSubscriptionController.getPhoneId(subId);
7615 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7616 return list.get(phoneId);
7617 }
7618 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007619 }
fionaxua13278b2018-03-21 00:08:13 -07007620
7621 @Override
7622 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007623 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 final Phone phone = getPhone(subId);
7629 if (phone == null) {
7630 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7631 return;
7632 }
chen xueaba88a2019-03-15 13:15:10 -07007633 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7634 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 } finally {
7636 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007637 }
fionaxua13278b2018-03-21 00:08:13 -07007638 }
7639
7640 @Override
7641 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007642 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 final Phone phone = getPhone(subId);
7647 if (phone == null) {
7648 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7649 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7650 }
7651 return phone.getCarrierIdListVersion();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007654 }
fionaxua13278b2018-03-21 00:08:13 -07007655 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007656
7657 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007658 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7659 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007661 mApp, subId, callingPackage, callingFeatureId,
7662 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007663 return -1;
7664 }
7665
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
7671 }
7672 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007673
7674 @Override
7675 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007676 TelephonyPermissions
7677 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007678 mApp, subId, "getCdmaRoamingMode");
7679
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
7688 @Override
7689 public boolean setCdmaRoamingMode(int subId, int mode) {
7690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7691 mApp, subId, "setCdmaRoamingMode");
7692
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
7700
7701 @Override
7702 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7704 mApp, subId, "setCdmaSubscriptionMode");
7705
7706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
7712 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007713
sqianc5eccab2018-10-19 18:46:41 -07007714 @Override
sqian8c685422019-02-22 15:55:18 -08007715 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007716 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007718 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7719 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007720 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7721 }
7722 final long identity = Binder.clearCallingIdentity();
7723 try {
sqian854d44b2018-12-12 16:48:18 -08007724 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7725 for (Phone phone: PhoneFactory.getPhones()) {
7726 if (phone.getEmergencyNumberTracker() != null
7727 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7728 emergencyNumberListInternal.put(
7729 phone.getSubId(),
7730 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7731 }
sqian11b7a0e2018-12-05 18:48:28 -08007732 }
sqian854d44b2018-12-12 16:48:18 -08007733 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
sqianc5eccab2018-10-19 18:46:41 -07007737 }
7738
7739 @Override
sqian8c685422019-02-22 15:55:18 -08007740 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007742 if (!exactMatch) {
7743 TelephonyPermissions
7744 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007745 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007746 }
7747 final long identity = Binder.clearCallingIdentity();
7748 try {
sqian854d44b2018-12-12 16:48:18 -08007749 for (Phone phone: PhoneFactory.getPhones()) {
7750 if (phone.getEmergencyNumberTracker() != null
7751 && phone.getEmergencyNumberTracker() != null) {
7752 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7753 number, exactMatch)) {
7754 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007755 }
7756 }
sqian11b7a0e2018-12-05 18:48:28 -08007757 }
7758 return false;
7759 } finally {
7760 Binder.restoreCallingIdentity(identity);
7761 }
7762 }
7763
sqianf4ca7ed2019-01-15 18:32:07 -08007764 /**
7765 * Update emergency number list for test mode.
7766 */
7767 @Override
7768 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7770 "updateEmergencyNumberListTestMode");
7771
7772 final long identity = Binder.clearCallingIdentity();
7773 try {
7774 for (Phone phone: PhoneFactory.getPhones()) {
7775 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7776 if (tracker != null) {
7777 tracker.executeEmergencyNumberTestModeCommand(action, num);
7778 }
7779 }
7780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
7783 }
7784
7785 /**
7786 * Get the full emergency number list for test mode.
7787 */
7788 @Override
7789 public List<String> getEmergencyNumberListTestMode() {
7790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7791 "getEmergencyNumberListTestMode");
7792
7793 final long identity = Binder.clearCallingIdentity();
7794 try {
7795 Set<String> emergencyNumbers = new HashSet<>();
7796 for (Phone phone: PhoneFactory.getPhones()) {
7797 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7798 if (tracker != null) {
7799 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7800 emergencyNumbers.add(num.getNumber());
7801 }
7802 }
7803 }
7804 return new ArrayList<>(emergencyNumbers);
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
7808 }
7809
chen xud6b45bd2018-10-30 22:27:10 -07007810 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007811 public int getEmergencyNumberDbVersion(int subId) {
7812 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7813
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 final Phone phone = getPhone(subId);
7817 if (phone == null) {
7818 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7819 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7820 }
7821 return phone.getEmergencyNumberDbVersion();
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
7825 }
7826
7827 @Override
7828 public void notifyOtaEmergencyNumberDbInstalled() {
7829 enforceModifyPermission();
7830
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 for (Phone phone: PhoneFactory.getPhones()) {
7834 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7835 if (tracker != null) {
7836 tracker.updateOtaEmergencyNumberDatabase();
7837 }
7838 }
7839 } finally {
7840 Binder.restoreCallingIdentity(identity);
7841 }
7842 }
7843
7844 @Override
7845 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7846 enforceActiveEmergencySessionPermission();
7847
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 for (Phone phone: PhoneFactory.getPhones()) {
7851 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7852 if (tracker != null) {
7853 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7854 }
7855 }
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
7858 }
7859 }
7860
7861 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007862 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7863 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7864 Phone phone = getPhone(subId);
7865 if (phone == null) {
7866 return null;
7867 }
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 UiccProfile profile = UiccController.getInstance()
7871 .getUiccProfileForPhone(phone.getPhoneId());
7872 if (profile != null) {
7873 return profile.getCertsFromCarrierPrivilegeAccessRules();
7874 }
7875 } finally {
7876 Binder.restoreCallingIdentity(identity);
7877 }
7878 return null;
7879 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007880
7881 /**
7882 * Enable or disable a modem stack.
7883 */
7884 @Override
7885 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7886 enforceModifyPermission();
7887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 Phone phone = PhoneFactory.getPhone(slotIndex);
7891 if (phone == null) {
7892 return false;
7893 } else {
7894 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7895 }
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
7899 }
Michelecea4cf22018-12-21 15:00:11 -08007900
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007901 /**
7902 * Whether a modem stack is enabled or not.
7903 */
7904 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007905 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7906 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007907 Phone phone = PhoneFactory.getPhone(slotIndex);
7908 if (phone == null) return false;
7909
7910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007911 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7912 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007913 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7914 }
7915
7916 final long identity = Binder.clearCallingIdentity();
7917 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007918 try {
7919 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7920 } catch (NoSuchElementException ex) {
7921 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7922 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 }
7927
Michelecea4cf22018-12-21 15:00:11 -08007928 @Override
Michele0ea7d782019-03-19 14:58:42 -07007929 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007930 enforceModifyPermission();
7931
7932 final long identity = Binder.clearCallingIdentity();
7933 try {
7934 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007935 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007936 .commit();
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
7940 }
7941
7942 @Override
Michele0ea7d782019-03-19 14:58:42 -07007943 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007944 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007946 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7947 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007948 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007949 }
Michelecea4cf22018-12-21 15:00:11 -08007950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
Michele0ea7d782019-03-19 14:58:42 -07007953 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
7957 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007958
Michele0ea7d782019-03-19 14:58:42 -07007959 @TelephonyManager.IsMultiSimSupportedResult
7960 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007961 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7962 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7963 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007964 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7965 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007966 }
7967 // Check if the hardware supports multisim functionality. If usage of multisim is not
7968 // supported by the modem, indicate that it is restricted.
7969 PhoneCapability staticCapability =
7970 mPhoneConfigurationManager.getStaticPhoneCapability();
7971 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007972 loge("isMultiSimSupportedInternal: no static configuration available");
7973 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007974 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08007975 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007976 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7977 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007978 }
7979 // Check if support of multiple SIMs is restricted by carrier
7980 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007981 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007982 }
7983
Michele0ea7d782019-03-19 14:58:42 -07007984 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007985 }
7986
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007987 /**
7988 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007989 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7990 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7991 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007992 * @param numOfSims number of active sims we want to switch to
7993 */
7994 @Override
7995 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007996 if (numOfSims == 1) {
7997 enforceModifyPermission();
7998 } else {
7999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8000 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8001 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008002 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008003
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008004 try {
Michele30b57b22019-03-01 12:01:14 -08008005 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008006 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008007 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8008 return;
8009 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008010 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
8014 }
8015
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008016 @Override
8017 public boolean isApplicationOnUicc(int subId, int appType) {
8018 enforceReadPrivilegedPermission("isApplicationOnUicc");
8019 Phone phone = getPhone(subId);
8020 if (phone == null) {
8021 return false;
8022 }
8023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 UiccCard uiccCard = phone.getUiccCard();
8026 if (uiccCard == null) {
8027 return false;
8028 }
8029 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8030 if (uiccProfile == null) {
8031 return false;
8032 }
8033 if (TelephonyManager.APPTYPE_SIM <= appType
8034 && appType <= TelephonyManager.APPTYPE_ISIM) {
8035 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8036 }
8037 return false;
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
8041 }
8042
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008043 /**
chen xub4baa772019-04-03 10:23:41 -07008044 * Get whether making changes to modem configurations will trigger reboot.
8045 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008046 */
8047 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008048 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8049 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008051 mApp, subId, callingPackage, callingFeatureId,
8052 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008053 return false;
8054 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
8061 }
8062
Nathan Harold29f5f052019-02-15 13:41:57 -08008063 private void updateModemStateMetrics() {
8064 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8065 // TODO: check the state for each modem if the api is ready.
8066 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8067 }
8068
Pengquan Meng3889a572019-01-23 11:16:29 -08008069 @Override
8070 public int[] getSlotsMapping() {
8071 enforceReadPrivilegedPermission("getSlotsMapping");
8072
8073 final long identity = Binder.clearCallingIdentity();
8074 try {
8075 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8076 // All logical slots should have a mapping to a physical slot.
8077 int[] logicalSlotsMapping = new int[phoneCount];
8078 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8079 for (int i = 0; i < slotInfos.length; i++) {
8080 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8081 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8082 }
8083 }
8084 return logicalSlotsMapping;
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008089
8090 /**
8091 * Get the IRadio HAL Version
8092 */
8093 @Override
8094 public int getRadioHalVersion() {
8095 Phone phone = getDefaultPhone();
8096 if (phone == null) return -1;
8097 HalVersion hv = phone.getHalVersion();
8098 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8099 return hv.major * 100 + hv.minor;
8100 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008101
8102 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008103 * Get the current calling package name.
8104 * @return the current calling package name
8105 */
8106 @Override
8107 public String getCurrentPackageName() {
8108 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8109 }
8110
8111 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008112 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8113 * corresponding network requests on a subId.
8114 *
8115 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008116 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008117 * 2) APN is un-metered for this subscription, or
8118 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008119 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008120 *
8121 * @return whether data is allowed for a apn type.
8122 *
8123 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008124 */
8125 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008126 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008127 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8128 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008129
8130 // Now that all security checks passes, perform the operation as ourselves.
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 Phone phone = getPhone(subId);
8134 if (phone == null) return false;
8135
Jack Yu41407ee2019-05-13 16:54:09 -07008136 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008137 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8138 } finally {
8139 Binder.restoreCallingIdentity(identity);
8140 }
8141 }
8142
8143 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008144 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008145 enforceReadPrivilegedPermission("isApnMetered");
8146
8147 // Now that all security checks passes, perform the operation as ourselves.
8148 final long identity = Binder.clearCallingIdentity();
8149 try {
8150 Phone phone = getPhone(subId);
8151 if (phone == null) return true; // By default return true.
8152
Jack Yu41407ee2019-05-13 16:54:09 -07008153 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008154 } finally {
8155 Binder.restoreCallingIdentity(identity);
8156 }
8157 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008158
8159 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008160 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8161 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8162 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8163 if (iccRecords == null) {
8164 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8165 return false;
8166 }
8167 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8168 }
8169
8170 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008171 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008172 if (callingPackage == null) {
8173 callingPackage = getCurrentPackageName();
8174 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008175 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8176 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8177 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8178 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8179 }
8180 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8181 Intent intent = new Intent();
8182 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8183 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8184 // Bring up choose default SMS subscription dialog right now
8185 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8186 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8187 mApp.startActivity(intent);
8188 }
chen xud5ca2d52019-05-28 15:20:57 -07008189
8190 @Override
8191 public String getMmsUAProfUrl(int subId) {
8192 //TODO investigate if this API should require proper permission check in R b/133791609
8193 final long identity = Binder.clearCallingIdentity();
8194 try {
8195 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8196 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
8201
8202 @Override
8203 public String getMmsUserAgent(int subId) {
8204 //TODO investigate if this API should require proper permission check in R b/133791609
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8208 .getString(com.android.internal.R.string.config_mms_user_agent);
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 }
Jack Yub07d4972019-05-28 16:12:25 -07008213
8214 @Override
8215 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8216 enforceModifyPermission();
8217
8218 // Now that all security checks passes, perform the operation as ourselves.
8219 final long identity = Binder.clearCallingIdentity();
8220 try {
8221 Phone phone = getPhone(subId);
8222 if (phone == null) return false;
8223
8224 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
8228 }
8229
8230 @Override
8231 public boolean isDataAllowedInVoiceCall(int subId) {
8232 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8233
8234 // Now that all security checks passes, perform the operation as ourselves.
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 Phone phone = getPhone(subId);
8238 if (phone == null) return false;
8239
8240 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
8244 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008245
changbetty97defcf2019-12-24 15:40:37 +08008246 @Override
8247 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8248 enforceModifyPermission();
8249
8250 // Now that all security checks passes, perform the operation as ourselves.
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 Phone phone = getPhone(subId);
8254 if (phone == null) return false;
8255
8256 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
8260 }
8261
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008262 /**
8263 * Updates whether conference event pacakge handling is enabled.
8264 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8265 * otherwise.
8266 */
8267 @Override
8268 public void setCepEnabled(boolean isCepEnabled) {
8269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8274 for (Phone phone : PhoneFactory.getPhones()) {
8275 Phone defaultPhone = phone.getImsPhone();
8276 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8277 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8278 ImsPhoneCallTracker imsPhoneCallTracker =
8279 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8280 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8281 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8282 + imsPhone.getMsisdn());
8283 }
8284 }
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
allenwtsu46dcc572020-01-08 18:24:03 +08008289
8290 /**
8291 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8292 *
8293 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8294 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8295 * before being read.
8296 */
8297 @Override
8298 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8299 isCompressed) {
8300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8301 mApp, subId, "notifyRcsAutoConfigurationReceived");
8302 try {
8303 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8304 if (configBinder == null) {
8305 Rlog.e(LOG_TAG, "null result for getImsConfig");
8306 } else {
8307 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8308 }
8309 } catch (RemoteException e) {
8310 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8311 }
8312 }
zoey chenf95ca592019-12-30 16:11:23 +08008313
8314 @Override
8315 public boolean isIccLockEnabled(int subId) {
8316 enforceReadPrivilegedPermission("isIccLockEnabled");
8317
8318 // Now that all security checks passes, perform the operation as ourselves.
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 Phone phone = getPhone(subId);
8322 if (phone != null && phone.getIccCard() != null) {
8323 return phone.getIccCard().getIccLockEnabled();
8324 } else {
8325 return false;
8326 }
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 /**
8333 * Set the ICC pin lock enabled or disabled..
8334 *
8335 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8336 * 0 or a positive integer as the attempts remaining value.
8337 *
8338 */
8339 @Override
8340 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8341 enforceModifyPermission();
8342
8343 Phone phone = getPhone(subId);
8344 if (phone == null) {
8345 return 0;
8346 }
8347 // Now that all security checks passes, perform the operation as ourselves.
8348 final long identity = Binder.clearCallingIdentity();
8349 try {
8350 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8351 new Pair<Boolean, String>(enabled, password), phone, null);
8352 return attemptsRemaining;
8353
8354 } catch (Exception e) {
8355 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 return 0;
8360 }
8361
8362 /**
8363 * Change the ICC password used in ICC pin lock.
8364 *
8365 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8366 * 0 or a positive integer as the attempts remaining value.
8367 *
8368 */
8369 @Override
8370 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8371 enforceModifyPermission();
8372
8373 Phone phone = getPhone(subId);
8374 if (phone == null) {
8375 return 0;
8376 }
8377 // Now that all security checks passes, perform the operation as ourselves.
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
8380 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8381 new Pair<String, String>(oldPassword, newPassword), phone, null);
8382 return attemptsRemaining;
8383
8384 } catch (Exception e) {
8385 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
8388 }
8389 return 0;
8390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008391}