blob: 5f7b62730648797661e9b33c612fb851b47f96ee [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;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
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;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
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;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800167import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800280 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700305 * Experiment flag to enable erase modem config on reset network, default value is false
306 */
307 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
308 "reset_network_erase_modem_config_enabled";
309
310 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700311 * A request object to use for transmitting data to an ICC.
312 */
313 private static final class IccAPDUArgument {
314 public int channel, cla, command, p1, p2, p3;
315 public String data;
316
317 public IccAPDUArgument(int channel, int cla, int command,
318 int p1, int p2, int p3, String data) {
319 this.channel = channel;
320 this.cla = cla;
321 this.command = command;
322 this.p1 = p1;
323 this.p2 = p2;
324 this.p3 = p3;
325 this.data = data;
326 }
327 }
328
329 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class ManualNetworkSelectionArgument {
333 public OperatorInfo operatorInfo;
334 public boolean persistSelection;
335
336 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
337 this.operatorInfo = operatorInfo;
338 this.persistSelection = persistSelection;
339 }
340 }
341
342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
344 * request after sending. The main thread will notify the request when it is complete.
345 */
346 private static final class MainThreadRequest {
347 /** The argument to use for the request */
348 public Object argument;
349 /** The result of the request that is run on the main thread */
350 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 // The subscriber id that this request applies to. Defaults to
352 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
353 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 // In cases where subId is unavailable, the caller needs to specify the phone.
356 public Phone phone;
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 public WorkSource workSource;
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 public MainThreadRequest(Object argument) {
361 this.argument = argument;
362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363
Nathan Harold92bed182018-10-12 18:16:49 -0700364 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
365 this.argument = argument;
366 if (phone != null) {
367 this.phone = phone;
368 }
369 this.workSource = workSource;
370 }
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 if (subId != null) {
375 this.subId = subId;
376 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800381 private static final class IncomingThirdPartyCallArgs {
382 public final ComponentName component;
383 public final String callId;
384 public final String callerDisplayName;
385
386 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
387 String callerDisplayName) {
388 this.component = component;
389 this.callId = callId;
390 this.callerDisplayName = callerDisplayName;
391 }
392 }
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 /**
395 * A handler that processes messages on the main thread in the phone process. Since many
396 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
397 * inbound binder threads to the main thread in the phone process. The Binder thread
398 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
399 * on, which will be notified when the operation completes and will contain the result of the
400 * request.
401 *
402 * <p>If a MainThreadRequest object is provided in the msg.obj field,
403 * note that request.result must be set to something non-null for the calling thread to
404 * unblock.
405 */
406 private final class MainThreadHandler extends Handler {
407 @Override
408 public void handleMessage(Message msg) {
409 MainThreadRequest request;
410 Message onCompleted;
411 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800414 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 case CMD_HANDLE_USSD_REQUEST: {
418 request = (MainThreadRequest) msg.obj;
419 final Phone phone = getPhoneFromRequest(request);
420 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
421 String ussdRequest = ussdObject.first;
422 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 if (!isUssdApiAllowed(request.subId)) {
425 // Carrier does not support use of this API, return failure.
426 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
427 UssdResponse response = new UssdResponse(ussdRequest, null);
428 Bundle returnData = new Bundle();
429 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
430 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 request.result = true;
433 notifyRequester(request);
434 return;
435 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 try {
438 request.result = phone != null
439 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
440 } catch (CallStateException cse) {
441 request.result = false;
442 }
443 // Wake up the requesting thread
444 notifyRequester(request);
445 break;
pkanwar32d516d2016-10-14 19:37:38 -0700446 }
447
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 final Phone phone = getPhoneFromRequest(request);
451 request.result = phone != null ?
452 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
453 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduLogicalChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
469 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 iccArgument.channel, iccArgument.cla, iccArgument.command,
472 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 break;
476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800486 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800488 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 } else {
490 loge("iccTransmitApduLogicalChannel: Unknown exception");
491 }
492 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduBasicChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 } else {
505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
506 request);
507 uiccCard.iccTransmitApduBasicChannel(
508 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
509 iccArgument.p3, iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduBasicChannel: Empty response");
522 } else if (ar.exception instanceof CommandException) {
523 loge("iccTransmitApduBasicChannel: CommandException: " +
524 ar.exception);
525 } else {
526 loge("iccTransmitApduBasicChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
532 case CMD_EXCHANGE_SIM_IO:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccExchangeSimIO: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
542 request);
543 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
544 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
545 iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_EXCHANGE_SIM_IO_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6f, 0, (byte[])null);
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 case CMD_SEND_ENVELOPE:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("sendEnvelopeWithStatus: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
569 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 break;
572
573 case EVENT_SEND_ENVELOPE_DONE:
574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("sendEnvelopeWithStatus: Empty response");
582 } else if (ar.exception instanceof CommandException) {
583 loge("sendEnvelopeWithStatus: CommandException: " +
584 ar.exception);
585 } else {
586 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
587 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 case CMD_OPEN_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800598 request.result = new IccOpenLogicalChannelResponse(-1,
599 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800603 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
604 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_OPEN_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 int[] result = (int[]) ar.result;
614 int channelId = result[0];
615 byte[] selectResponse = null;
616 if (result.length > 1) {
617 selectResponse = new byte[result.length - 1];
618 for (int i = 1; i < result.length; ++i) {
619 selectResponse[i - 1] = (byte) result[i];
620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 if (ar.result == null) {
626 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 if (ar.exception != null) {
629 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
630 }
631
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700633 if (ar.exception instanceof CommandException) {
634 CommandException.Error error =
635 ((CommandException) (ar.exception)).getCommandError();
636 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700638 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(
643 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700645 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case CMD_CLOSE_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900654 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
658 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800663 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
664 break;
665
666 case CMD_NV_READ_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 request.result = "";
680 if (ar.result == null) {
681 loge("nvReadItem: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("nvReadItem: CommandException: " +
684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800686 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Jake Hambye994d462014-02-03 13:10:13 -0800692 case CMD_NV_WRITE_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
695 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_ITEM_DONE:
701 handleNullReturnEvent(msg, "nvWriteItem");
702 break;
703
704 case CMD_NV_WRITE_CDMA_PRL:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_WRITE_CDMA_PRL_DONE:
711 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800715 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case EVENT_RESET_MODEM_CONFIG_DONE:
721 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 case CMD_GET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // Integer
735 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800736 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 if (ar.result == null) {
738 loge("getPreferredNetworkType: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("getPreferredNetworkType: CommandException: " +
741 ar.exception);
742 } else {
743 loge("getPreferredNetworkType: Unknown exception");
744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case CMD_SET_PREFERRED_NETWORK_TYPE:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
752 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
757 handleNullReturnEvent(msg, "setPreferredNetworkType");
758 break;
759
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
761 request = (MainThreadRequest)msg.obj;
762 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
766 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
767 ar = (AsyncResult)msg.obj;
768 request = (MainThreadRequest)ar.userObj;
769 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 break;
772
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 case CMD_SET_VOICEMAIL_NUMBER:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
776 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800777 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
778 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 break;
780
781 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
782 handleNullReturnEvent(msg, "setVoicemailNumber");
783 break;
784
Stuart Scott54788802015-03-30 13:18:01 -0700785 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
788 request);
789 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
793 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
794 break;
795
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 case CMD_PERFORM_NETWORK_SCAN:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
799 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
800 break;
801
802 case EVENT_PERFORM_NETWORK_SCAN_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 CellNetworkScanResult cellScanResult;
806 if (ar.exception == null && ar.result != null) {
807 cellScanResult = new CellNetworkScanResult(
808 CellNetworkScanResult.STATUS_SUCCESS,
809 (List<OperatorInfo>) ar.result);
810 } else {
811 if (ar.result == null) {
812 loge("getCellNetworkScanResults: Empty response");
813 }
814 if (ar.exception != null) {
815 loge("getCellNetworkScanResults: Exception: " + ar.exception);
816 }
817 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
821 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
823 } else if (error == CommandException.Error.GENERIC_FAILURE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
825 }
826 }
827 cellScanResult = new CellNetworkScanResult(errorCode, null);
828 }
829 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700830 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result = true;
848 } else {
849 request.result = false;
850 loge("setNetworkSelectionModeManual " + ar.exception);
851 }
852 notifyRequester(request);
853 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700854 break;
855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 case CMD_GET_MODEM_ACTIVITY_INFO:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700859 if (defaultPhone != null) {
860 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 break;
863
864 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("queryModemActivityInfo: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("queryModemActivityInfo: CommandException: " +
874 ar.exception);
875 } else {
876 loge("queryModemActivityInfo: Unknown exception");
877 }
878 }
Amit Mahajand4766222016-01-28 15:28:28 -0800879 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
880 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700881 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700884 break;
885
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 case CMD_SET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800888 CarrierRestrictionRules argument =
889 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800891 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_SET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800900 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
901 if (ar.exception instanceof CommandException) {
902 loge("setAllowedCarriers: CommandException: " + ar.exception);
903 CommandException.Error error =
904 ((CommandException) (ar.exception)).getCommandError();
905 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
906 request.result =
907 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 } else {
910 loge("setAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case CMD_GET_ALLOWED_CARRIERS:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case EVENT_GET_ALLOWED_CARRIERS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800928 request.result = new IllegalStateException(
929 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 if (ar.result == null) {
931 loge("getAllowedCarriers: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("getAllowedCarriers: CommandException: " +
934 ar.exception);
935 } else {
936 loge("getAllowedCarriers: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958
959 case CMD_GET_FORBIDDEN_PLMNS:
960 request = (MainThreadRequest) msg.obj;
961 uiccCard = getUiccCardFromRequest(request);
962 if (uiccCard == null) {
963 loge("getForbiddenPlmns() UiccCard is null");
964 request.result = new IllegalArgumentException(
965 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 }
969 Integer appType = (Integer) request.argument;
970 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
971 if (uiccApp == null) {
972 loge("getForbiddenPlmns() no app with specified type -- "
973 + appType);
974 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977 } else {
978 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
979 + " specified type -- " + appType);
980 }
981 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
982 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
983 onCompleted);
984 break;
985
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 case CMD_SWITCH_SLOTS:
987 request = (MainThreadRequest) msg.obj;
988 int[] physicalSlots = (int[]) request.argument;
989 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
990 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
991 break;
992
993 case EVENT_SWITCH_SLOTS_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_NETWORK_SELECTION_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1002 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1003 break;
1004
1005 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1010 } else {
1011 int mode = ((int[]) ar.result)[0];
1012 if (mode == 0) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1014 } else {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
1019 break;
1020 case CMD_GET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1023 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1024 break;
1025 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception != null) {
1029 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1030 } else {
1031 request.result = ((int[]) ar.result)[0];
1032 }
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_ROAMING_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1038 int mode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
1046 break;
1047 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1050 int subscriptionMode = (int) request.argument;
1051 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1052 break;
1053 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 request.result = ar.exception == null;
1057 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case CMD_GET_ALL_CELL_INFO:
1060 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001062 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case EVENT_GET_ALL_CELL_INFO_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001067 // If a timeout occurs, the response will be null
1068 request.result = (ar.exception == null && ar.result != null)
1069 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case CMD_REQUEST_CELL_INFO_UPDATE:
1075 request = (MainThreadRequest) msg.obj;
1076 request.phone.requestCellInfoUpdate(request.workSource,
1077 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1078 break;
1079 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1083 try {
1084 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001086 cb.onError(
1087 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1088 ar.exception.getClass().getName(),
1089 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001092 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else {
1094 // use the result as returned
1095 cb.onCellInfo((List<CellInfo>) ar.result);
1096 }
1097 } catch (RemoteException re) {
1098 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1099 }
1100 break;
1101 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request = (MainThreadRequest) msg.obj;
1103 WorkSource ws = (WorkSource) request.argument;
1104 Phone phone = getPhoneFromRequest(request);
1105 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1106 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = ar.result;
1112 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1115 ? new CdmaCellLocation() : new GsmCellLocation();
1116 }
1117
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001122 case CMD_MODEM_REBOOT:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case EVENT_CMD_MODEM_REBOOT_DONE:
1128 handleNullReturnEvent(msg, "rebootModem");
1129 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001130 case CMD_REQUEST_ENABLE_MODEM:
1131 request = (MainThreadRequest) msg.obj;
1132 boolean enable = (boolean) request.argument;
1133 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 PhoneConfigurationManager.getInstance()
1136 .enablePhone(request.phone, enable, onCompleted);
1137 break;
1138 case EVENT_ENABLE_MODEM_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001142 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001143 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 if ((boolean) request.result) {
1145 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1146 updateModemStateMetrics();
1147 } else {
1148 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1149 + ar.exception);
1150 }
1151 notifyRequester(request);
1152 break;
1153 case CMD_GET_MODEM_STATUS:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1156 PhoneConfigurationManager.getInstance()
1157 .getPhoneStatusFromModem(request.phone, onCompleted);
1158 break;
1159 case EVENT_GET_MODEM_STATUS_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 int id = request.phone.getPhoneId();
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result;
1165 //update the cache as modem status has changed
1166 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1167 (boolean) request.result);
1168 } else {
1169 // Return true if modem status cannot be retrieved. For most cases,
1170 // modem status is on. And for older version modems, GET_MODEM_STATUS
1171 // and disable modem are not supported. Modem is always on.
1172 // TODO: this should be fixed in R to support a third
1173 // status UNKNOWN b/131631629
1174 request.result = true;
1175 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1176 + ar.exception);
1177 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001178 notifyRequester(request);
1179 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001180 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null && ar.result != null) {
1184 request.result = ar.result;
1185 } else {
1186 request.result = -1;
1187 loge("Failed to set Forbidden Plmns");
1188 if (ar.result == null) {
1189 loge("setForbidenPlmns: Empty response");
1190 } else if (ar.exception != null) {
1191 loge("setForbiddenPlmns: Exception: " + ar.exception);
1192 request.result = -1;
1193 } else {
1194 loge("setForbiddenPlmns: Unknown exception");
1195 }
1196 }
1197 notifyRequester(request);
1198 break;
1199 case CMD_SET_FORBIDDEN_PLMNS:
1200 request = (MainThreadRequest) msg.obj;
1201 uiccCard = getUiccCardFromRequest(request);
1202 if (uiccCard == null) {
1203 loge("setForbiddenPlmns: UiccCard is null");
1204 request.result = -1;
1205 notifyRequester(request);
1206 break;
1207 }
1208 Pair<Integer, List<String>> setFplmnsArgs =
1209 (Pair<Integer, List<String>>) request.argument;
1210 appType = setFplmnsArgs.first;
1211 List<String> fplmns = setFplmnsArgs.second;
1212 uiccApp = uiccCard.getApplicationByType(appType);
1213 if (uiccApp == null) {
1214 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1215 request.result = -1;
1216 loge("Failed to get UICC App");
1217 notifyRequester(request);
1218 } else {
1219 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1220 ((SIMRecords) uiccApp.getIccRecords())
1221 .setForbiddenPlmns(onCompleted, fplmns);
1222 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001223 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001393 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001398 mTelephonySharedPreferences =
1399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 publish();
1404 }
1405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001406 private Phone getDefaultPhone() {
1407 Phone thePhone = getPhone(getDefaultSubscription());
1408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1409 }
1410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 private void publish() {
1412 if (DBG) log("publish: " + this);
1413
1414 ServiceManager.addService("phone", this);
1415 }
1416
Stuart Scott584921c2015-01-15 17:10:34 -08001417 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001418 if (request.phone != null) {
1419 return request.phone;
1420 } else {
1421 return getPhoneFromSubId(request.subId);
1422 }
1423 }
1424
1425 private Phone getPhoneFromSubId(int subId) {
1426 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1427 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001428 }
1429
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001430 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1431 Phone phone = getPhoneFromRequest(request);
1432 return phone == null ? null :
1433 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1434 }
1435
Wink Saville36469e72014-06-11 15:17:00 -07001436 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001437 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001438 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001441 private void sendEraseModemConfig(Phone phone) {
1442 if (phone != null) {
1443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1444 mApp, phone.getSubId(), "eraseModemConfig");
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
1452 }
1453 }
1454
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("dial: " + number);
1461 // No permission check needed here: This is just a wrapper around the
1462 // ACTION_DIAL intent, which is available to any app since it puts up
1463 // the UI before it does anything.
1464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001465 final long identity = Binder.clearCallingIdentity();
1466 try {
1467 String url = createTelUrl(number);
1468 if (url == null) {
1469 return;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 // PENDING: should we just silently fail if phone is offhook or ringing?
1473 PhoneConstants.State state = mCM.getState(subId);
1474 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1475 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1477 mApp.startActivity(intent);
1478 }
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 if (DBG) log("call: " + number);
1490
1491 // This is just a wrapper around the ACTION_CALL intent, but we still
1492 // need to do a permission check since we're calling startActivity()
1493 // from the context of the phone app.
1494 enforceCallPermission();
1495
Jordan Liu1617b712019-07-10 15:06:26 -07001496 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 != AppOpsManager.MODE_ALLOWED) {
1498 return;
1499 }
1500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 String url = createTelUrl(number);
1504 if (url == null) {
1505 return;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001508 boolean isValid = false;
1509 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1510 if (slist != null) {
1511 for (SubscriptionInfo subInfoRecord : slist) {
1512 if (subInfoRecord.getSubscriptionId() == subId) {
1513 isValid = true;
1514 break;
1515 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001516 }
Wink Saville08874612014-08-31 19:19:58 -07001517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 if (!isValid) {
1519 return;
1520 }
Wink Saville08874612014-08-31 19:19:58 -07001521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1523 intent.putExtra(SUBSCRIPTION_KEY, subId);
1524 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1525 mApp.startActivity(intent);
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
1528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
1540 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
1549 /** {@hide} */
1550 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556
1557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1560 checkSimPin.start();
1561 return checkSimPin.unlockSim(null, pin);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Saville9de0f752013-10-22 19:04:03 -07001567 /** {@hide} */
1568 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1578 checkSimPuk.start();
1579 return checkSimPuk.unlockSim(puk, pin);
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 * a synchronous one.
1588 */
1589 private static class UnlockSim extends Thread {
1590
1591 private final IccCard mSimCard;
1592
1593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596
1597 // For replies from SimCard interface
1598 private Handler mHandler;
1599
1600 // For async handler to identify request type
1601 private static final int SUPPLY_PIN_COMPLETE = 100;
1602
1603 public UnlockSim(IccCard simCard) {
1604 mSimCard = simCard;
1605 }
1606
1607 @Override
1608 public void run() {
1609 Looper.prepare();
1610 synchronized (UnlockSim.this) {
1611 mHandler = new Handler() {
1612 @Override
1613 public void handleMessage(Message msg) {
1614 AsyncResult ar = (AsyncResult) msg.obj;
1615 switch (msg.what) {
1616 case SUPPLY_PIN_COMPLETE:
1617 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1618 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001619 mRetryCount = msg.arg1;
1620 if (ar.exception != null) {
1621 if (ar.exception instanceof CommandException &&
1622 ((CommandException)(ar.exception)).getCommandError()
1623 == CommandException.Error.PASSWORD_INCORRECT) {
1624 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1625 } else {
1626 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1627 }
1628 } else {
1629 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 mDone = true;
1632 UnlockSim.this.notifyAll();
1633 }
1634 break;
1635 }
1636 }
1637 };
1638 UnlockSim.this.notifyAll();
1639 }
1640 Looper.loop();
1641 }
1642
1643 /*
1644 * Use PIN or PUK to unlock SIM card
1645 *
1646 * If PUK is null, unlock SIM card with PIN
1647 *
1648 * If PUK is not null, unlock SIM card with PUK and set PIN code
1649 */
Wink Saville9de0f752013-10-22 19:04:03 -07001650 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651
1652 while (mHandler == null) {
1653 try {
1654 wait();
1655 } catch (InterruptedException e) {
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1660
1661 if (puk == null) {
1662 mSimCard.supplyPin(pin, callback);
1663 } else {
1664 mSimCard.supplyPuk(puk, pin, callback);
1665 }
1666
1667 while (!mDone) {
1668 try {
1669 Log.d(LOG_TAG, "wait for done");
1670 wait();
1671 } catch (InterruptedException e) {
1672 // Restore the interrupted status
1673 Thread.currentThread().interrupt();
1674 }
1675 }
1676 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001677 int[] resultArray = new int[2];
1678 resultArray[0] = mResult;
1679 resultArray[1] = mRetryCount;
1680 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682 }
1683
1684 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686
1687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 // No permission check needed here: this call is harmless, and it's
1691 // needed for the ServiceState.requestStateUpdate() call (which is
1692 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.updateServiceLocation();
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
1705 public boolean isRadioOn(String callingPackage) {
1706 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001709 @Override
1710 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001712 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001713 return false;
1714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 return isRadioOnForSubscriber(subId);
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
1721 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001722 }
1723
1724 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
1729 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
1738 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
Wink Saville36469e72014-06-11 15:17:00 -07001741
Wink Savilleb564aae2014-10-23 10:18:09 -07001742 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 final Phone phone = getPhone(subId);
1748 if (phone != null) {
1749 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
1755
1756 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001757 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001758 }
1759
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762
1763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 final Phone phone = getPhone(subId);
1766 if (phone == null) {
1767 return false;
1768 }
1769 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1770 toggleRadioOnOffForSubscriber(subId);
1771 }
1772 return true;
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
Wink Saville36469e72014-06-11 15:17:00 -07001777
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001779 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 /*
1781 * If any of the Radios are available, it will need to be
1782 * shutdown. So return true if any Radio is available.
1783 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1787 Phone phone = PhoneFactory.getPhone(i);
1788 if (phone != null && phone.isRadioAvailable()) return true;
1789 }
1790 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1791 return false;
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
1796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001798 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 enforceModifyPermission();
1800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1804 logv("Shutting down Phone " + i);
1805 shutdownRadioUsingPhoneId(i);
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810 }
1811
1812 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 Phone phone = PhoneFactory.getPhone(phoneId);
1814 if (phone != null && phone.isRadioAvailable()) {
1815 phone.shutdownRadio();
1816 }
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1825 if (defaultPhone != null) {
1826 defaultPhone.setRadioPower(turnOn);
1827 return true;
1828 } else {
1829 loge("There's no default phone.");
1830 return false;
1831 }
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001834 }
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.setRadioPower(turnOn);
1845 return true;
1846 } else {
1847 return false;
1848 }
1849 } finally {
1850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
1853
Wink Saville36469e72014-06-11 15:17:00 -07001854 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 public boolean enableDataConnectivity() {
1857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001858
1859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 int subId = mSubscriptionController.getDefaultDataSubId();
1862 final Phone phone = getPhone(subId);
1863 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001864 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 return true;
1866 } else {
1867 return false;
1868 }
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Wink Saville36469e72014-06-11 15:17:00 -07001874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public boolean disableDataConnectivity() {
1877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 int subId = mSubscriptionController.getDefaultDataSubId();
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001884 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 return true;
1886 } else {
1887 return false;
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001895 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001900 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
1909 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001910 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
pkanwarae03a6b2016-11-06 20:37:09 -08001913 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 enforceCallPermission();
1915
1916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1919 return;
1920 }
1921 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1922 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
pkanwar32d516d2016-10-14 19:37:38 -07001926 };
1927
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return false;
1935 }
1936 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001943 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001946 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1951 PhoneConstantConversions.convertCallState(phone.getState());
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001958 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001959 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1960 }
1961
1962 @Override
1963 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 final long identity = Binder.clearCallingIdentity();
1965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 if (phone != null) {
1968 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1969 } else {
1970 return PhoneConstantConversions.convertDataState(
1971 PhoneConstants.DataState.DISCONNECTED);
1972 }
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001979 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1981 }
1982
1983 @Override
1984 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 if (phone != null) {
1989 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1990 } else {
1991 return TelephonyManager.DATA_ACTIVITY_NONE;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001999 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002000 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002001 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002002
2003 LocationAccessPolicy.LocationPermissionResult locationResult =
2004 LocationAccessPolicy.checkLocationPermission(mApp,
2005 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2006 .setCallingPackage(callingPackage)
2007 .setCallingPid(Binder.getCallingPid())
2008 .setCallingUid(Binder.getCallingUid())
2009 .setMethod("getCellLocation")
2010 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2011 .build());
2012 switch (locationResult) {
2013 case DENIED_HARD:
2014 throw new SecurityException("Not allowed to access cell location");
2015 case DENIED_SOFT:
2016 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
2023 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002024 int subId = mSubscriptionController.getDefaultDataSubId();
2025 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2026 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 return data;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Svetoslav64fad262015-04-14 14:35:21 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002034 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2035 if (!TextUtils.isEmpty(callingPackage)) {
2036 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2039 return "";
2040 }
2041 }
2042
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2044 // registered cell info, so return a NULL country instead.
2045 final long identity = Binder.clearCallingIdentity();
2046 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002047 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2048 // Get default phone in this case.
2049 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2050 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002052 // Todo: fix this when we can get the actual cellular network info when the device
2053 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002054 if (TelephonyManager.NETWORK_TYPE_IWLAN
2055 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2056 return "";
2057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 Phone phone = PhoneFactory.getPhone(phoneId);
2059 if (phone != null) {
2060 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002061 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 if (sst != null) {
2063 LocaleTracker lt = sst.getLocaleTracker();
2064 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002065 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2066 return lt.getCurrentCountry();
2067 } else if (emergencyNumberTracker != null) {
2068 return emergencyNumberTracker.getEmergencyCountryIso();
2069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 }
2071 }
2072 }
2073 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002077 }
2078
2079 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002081 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002082 }
2083
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002085 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 mApp.enforceCallingOrSelfPermission(
2087 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002088
2089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 final Phone phone = getPhone(subId);
2092 if (phone != null) {
2093 phone.enableLocationUpdates();
2094 }
2095 } finally {
2096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 }
2099
2100 @Override
2101 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002102 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002103 }
2104
Sanket Padawe356d7632015-06-22 14:03:32 -07002105 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002106 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 mApp.enforceCallingOrSelfPermission(
2108 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002109
2110 final long identity = Binder.clearCallingIdentity();
2111 try {
2112 final Phone phone = getPhone(subId);
2113 if (phone != null) {
2114 phone.disableLocationUpdates();
2115 }
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Nathan Harold31d7ff32018-10-15 20:20:30 -07002121 /**
2122 * Returns the target SDK version number for a given package name.
2123 *
Nathan Haroldec184742019-07-10 17:04:16 -07002124 * This call MUST be invoked before clearing the calling UID.
2125 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002126 * @return target SDK if the package is found or INT_MAX.
2127 */
2128 private int getTargetSdk(String packageName) {
2129 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002130 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002131 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002132 if (ai != null) return ai.targetSdkVersion;
2133 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002134 loge("Failed to get package info for pkg="
2135 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 }
2137 return Integer.MAX_VALUE;
2138 }
2139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 @Override
2141 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Nathan Haroldf180aac2018-06-01 18:43:55 -07002156 List<CellInfo> info = getAllCellInfo(callingPackage);
2157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002180 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
2188 .setCallingPid(Binder.getCallingPid())
2189 .setCallingUid(Binder.getCallingUid())
2190 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002191 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002192 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2193 .build());
2194 switch (locationResult) {
2195 case DENIED_HARD:
2196 throw new SecurityException("Not allowed to access cell info");
2197 case DENIED_SOFT:
2198 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002201 final int targetSdk = getTargetSdk(callingPackage);
2202 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2203 return getCachedCellInfo();
2204 }
2205
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002206 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2211 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002212 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002213 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 if (info != null) cellInfos.addAll(info);
2215 }
2216 return cellInfos;
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220 }
2221
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2224 requestCellInfoUpdateInternal(
2225 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2226 }
2227
2228 @Override
2229 public void requestCellInfoUpdateWithWorkSource(
2230 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2231 enforceModifyPermission();
2232 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2233 }
2234
2235 private void requestCellInfoUpdateInternal(
2236 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002238 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002239
2240 LocationAccessPolicy.LocationPermissionResult locationResult =
2241 LocationAccessPolicy.checkLocationPermission(mApp,
2242 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2243 .setCallingPackage(callingPackage)
2244 .setCallingPid(Binder.getCallingPid())
2245 .setCallingUid(Binder.getCallingUid())
2246 .setMethod("requestCellInfoUpdate")
2247 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2248 .build());
2249 switch (locationResult) {
2250 case DENIED_HARD:
2251 throw new SecurityException("Not allowed to access cell info");
2252 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002253 try {
2254 cb.onCellInfo(new ArrayList<CellInfo>());
2255 } catch (RemoteException re) {
2256 // Drop without consequences
2257 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002258 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002259 }
2260
Nathan Harolda939a962019-05-09 10:13:47 -07002261
2262 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002263 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2264
2265 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2266 }
2267
2268 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002270 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
Shishir Agrawala9f32182016-04-12 12:00:16 -07002281 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002282 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 Phone phone = PhoneFactory.getPhone(slotIndex);
2284 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 return null;
2286 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2289 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 return null;
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 return phone.getImei();
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 }
2300
2301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002302 public String getTypeAllocationCodeForSlot(int slotIndex) {
2303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 String tac = null;
2305 if (phone != null) {
2306 String imei = phone.getImei();
2307 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2308 }
2309 return tac;
2310 }
2311
2312 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002313 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002316 return null;
2317 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002318
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002320 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2321 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 return null;
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 return phone.getMeid();
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Jack Yu2af8d712017-03-15 17:14:14 -07002331 }
2332
2333 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002334 public String getManufacturerCodeForSlot(int slotIndex) {
2335 Phone phone = PhoneFactory.getPhone(slotIndex);
2336 String manufacturerCode = null;
2337 if (phone != null) {
2338 String meid = phone.getMeid();
2339 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2340 }
2341 return manufacturerCode;
2342 }
2343
2344 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002345 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002346 Phone phone = PhoneFactory.getPhone(slotIndex);
2347 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002348 return null;
2349 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 int subId = phone.getSubId();
2351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2352 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2353 return null;
2354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 return phone.getDeviceSvn();
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002362 }
2363
fionaxu43304da2017-11-27 22:51:16 -08002364 @Override
2365 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
fionaxu43304da2017-11-27 22:51:16 -08002373 }
2374
2375 @Override
2376 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 return phone == null ? null : phone.getCarrierName();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
fionaxu43304da2017-11-27 22:51:16 -08002384 }
2385
calvinpanffe225e2018-11-01 19:43:06 +08002386 @Override
chen xu0026ca62019-03-06 15:28:50 -08002387 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002392 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
2396 }
2397
2398 @Override
chen xu0026ca62019-03-06 15:28:50 -08002399 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002403 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
2407 }
2408
chen xu651eec72018-11-11 19:03:44 -08002409 @Override
chen xu864e11c2018-12-06 22:10:03 -08002410 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2411 if (!isSubscriptionMccMnc) {
2412 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2413 }
chen xu651eec72018-11-11 19:03:44 -08002414 final Phone phone = PhoneFactory.getPhone(slotIndex);
2415 if (phone == null) {
2416 return TelephonyManager.UNKNOWN_CARRIER_ID;
2417 }
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
2424 }
2425
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 //
2427 // Internal helper methods.
2428 //
2429
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2432 *
2433 * @throws SecurityException if the caller does not have the required permission
2434 */
2435 private void enforceModifyPermission() {
2436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2437 }
2438
Shuo Qianf2b2df42019-11-13 17:43:31 -08002439 private void enforceActiveEmergencySessionPermission() {
2440 mApp.enforceCallingOrSelfPermission(
2441 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2442 }
2443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 /**
2445 * Make sure the caller has the CALL_PHONE permission.
2446 *
2447 * @throws SecurityException if the caller does not have the required permission
2448 */
2449 private void enforceCallPermission() {
2450 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2451 }
2452
paulhu423b5f22019-08-23 19:17:33 +08002453 private void enforceSettingsPermission() {
2454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002455 }
2456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 private String createTelUrl(String number) {
2458 if (TextUtils.isEmpty(number)) {
2459 return null;
2460 }
2461
Jake Hambye994d462014-02-03 13:10:13 -08002462 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Ihab Awadf9e92732013-12-05 18:02:52 -08002465 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2467 }
2468
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002469 private static void logv(String msg) {
2470 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2471 }
2472
Ihab Awadf9e92732013-12-05 18:02:52 -08002473 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2475 }
2476
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002477 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002479 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002480 }
2481
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002483 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 final Phone phone = PhoneFactory.getPhone(slotIndex);
2487 if (phone == null) {
2488 return PhoneConstants.PHONE_TYPE_NONE;
2489 } else {
2490 return phone.getPhoneType();
2491 }
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496
2497 /**
2498 * Returns the CDMA ERI icon index to display
2499 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 @Override
2501 public int getCdmaEriIconIndex(String callingPackage) {
2502 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002506 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002508 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002509 return -1;
2510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone != null) {
2516 return phone.getCdmaEriIconIndex();
2517 } else {
2518 return -1;
2519 }
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
2525 /**
2526 * Returns the CDMA ERI icon mode,
2527 * 0 - ON
2528 * 1 - FLASHING
2529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 @Override
2531 public int getCdmaEriIconMode(String callingPackage) {
2532 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002533 }
2534
Sanket Padawe356d7632015-06-22 14:03:32 -07002535 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return -1;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getCdmaEriIconMode();
2547 } else {
2548 return -1;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
2556 * Returns the CDMA ERI text,
2557 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002558 @Override
2559 public String getCdmaEriText(String callingPackage) {
2560 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return null;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriText();
2575 } else {
2576 return null;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002584 * Returns the CDMA MDN.
2585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 return phone.getLine1Number();
2596 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002597 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 return null;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002602 }
2603 }
2604
2605 /**
2606 * Returns the CDMA MIN.
2607 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002609 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2611 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2617 return phone.getCdmaMin();
2618 } else {
2619 return null;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002623 }
2624 }
2625
Hall Liud892bec2018-11-30 14:51:45 -08002626 @Override
2627 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2628 INumberVerificationCallback callback, String callingPackage) {
2629 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2630 != PERMISSION_GRANTED) {
2631 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2632 }
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2634
2635 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2636 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2637 throw new SecurityException("Calling package must be configured in the device config");
2638 }
2639
2640 if (range == null) {
2641 throw new NullPointerException("Range must be non-null");
2642 }
2643
2644 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002645 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002646
2647 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2648 }
2649
Junda Liuca05d5d2014-08-14 22:36:34 -07002650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 * Returns true if CDMA provisioning needs to run.
2652 */
2653 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002656 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
2661
2662 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002663 * Sets the voice mail number of a given subId.
2664 */
2665 @Override
2666 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2672 new Pair<String, String>(alphaTag, number), new Integer(subId));
2673 return success;
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 }
2678
Ta-wei Yen87c49842016-05-13 21:19:52 -07002679 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002680 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2683 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002684 if (!TextUtils.equals(callingPackage, systemDialer)) {
2685 throw new SecurityException("caller must be system dialer");
2686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2691 if (phoneAccountHandle == null) {
2692 return null;
2693 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002697 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 }
2699
2700 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002701 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002704 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002705 return null;
2706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002708 final long identity = Binder.clearCallingIdentity();
2709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002710 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002714 }
2715
2716 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002717 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2718 VisualVoicemailSmsFilterSettings settings) {
2719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002724 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 } finally {
2726 Binder.restoreCallingIdentity(identity);
2727 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002728 }
2729
2730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002731 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2745 String callingPackage, int subId) {
2746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002755 }
2756
2757 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002758 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002759 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002768 }
2769
2770 @Override
2771 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2772 String number, int port, String text, PendingIntent sentIntent) {
2773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002774 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002776 SmsController smsController = PhoneFactory.getSmsController();
2777 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2778 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002779 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002780
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002781 /**
fionaxu0152e512016-11-14 13:36:14 -08002782 * Sets the voice activation state of a given subId.
2783 */
2784 @Override
2785 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2787 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 final Phone phone = getPhone(subId);
2792 if (phone != null) {
2793 phone.setVoiceActivationState(activationState);
2794 } else {
2795 loge("setVoiceActivationState fails with invalid subId: " + subId);
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002799 }
2800 }
2801
2802 /**
2803 * Sets the data activation state of a given subId.
2804 */
2805 @Override
2806 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2808 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 final Phone phone = getPhone(subId);
2813 if (phone != null) {
2814 phone.setDataActivationState(activationState);
2815 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002816 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002820 }
2821 }
2822
2823 /**
2824 * Returns the voice activation state of a given subId.
2825 */
2826 @Override
2827 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002828 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
fionaxu0152e512016-11-14 13:36:14 -08002830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 if (phone != null) {
2834 return phone.getVoiceActivationState();
2835 } else {
2836 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002840 }
2841 }
2842
2843 /**
2844 * Returns the data activation state of a given subId.
2845 */
2846 @Override
2847 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002848 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
fionaxu0152e512016-11-14 13:36:14 -08002850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (phone != null) {
2854 return phone.getDataActivationState();
2855 } else {
2856 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002860 }
2861 }
2862
2863 /**
Wink Saville36469e72014-06-11 15:17:00 -07002864 * Returns the unread count of voicemails for a subId
2865 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002866 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002867 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2869 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2870 return 0;
2871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 final Phone phone = getPhone(subId);
2875 if (phone != null) {
2876 return phone.getVoiceMessageCount();
2877 } else {
2878 return 0;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
2885 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002886 * returns true, if the device is in a state where both voice and data
2887 * are supported simultaneously. This can change based on location or network condition.
2888 */
2889 @Override
2890 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002898 }
2899
2900 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002901 * Send the dialer code if called from the current default dialer or the caller has
2902 * carrier privilege.
2903 * @param inputCode The dialer code to send
2904 */
2905 @Override
2906 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002909 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2910 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002911 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002912 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2913 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
fionaxu235cc5e2017-03-06 22:25:57 -08002922 }
2923
Pengquan Menga1bb6272018-09-06 09:59:22 -07002924 @Override
2925 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002926 if (!isActiveSubscription(subId)) {
2927 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2928 }
2929
Pengquan Menga1bb6272018-09-06 09:59:22 -07002930 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2931 }
2932
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002934 public boolean isInEmergencySmsMode() {
2935 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 for (Phone phone : PhoneFactory.getPhones()) {
2939 if (phone.isInEmergencySmsMode()) {
2940 return true;
2941 }
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 return false;
2947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2951 throws RemoteException {
2952 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002953 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2954 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2955 "IMS not available on device.");
2956 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 final long token = Binder.clearCallingIdentity();
2958 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002962 } catch (ImsException e) {
2963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 } finally {
2965 Binder.restoreCallingIdentity(token);
2966 }
2967 }
2968
2969 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002970 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2971 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2973 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2974 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002975 final long token = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2979 .removeRegistrationCallbackForSubscription(c, subId);
2980 } catch (ImsException e) {
2981 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2982 + "is inactive, ignoring unregister.");
2983 // If the subscription is no longer active, just return, since the callback
2984 // will already have been removed internally.
2985 } finally {
2986 Binder.restoreCallingIdentity(token);
2987 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 }
2989
Brad Ebinger774ba362019-10-22 17:36:18 -07002990 /**
2991 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2992 */
2993 @Override
2994 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2995 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2998 "IMS not available on device.");
2999 }
3000 final long token = Binder.clearCallingIdentity();
3001 try {
3002 Phone phone = getPhone(subId);
3003 if (phone == null) {
3004 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3005 + subId + "'");
3006 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3007 }
3008 phone.getImsRegistrationState(regState -> {
3009 try {
3010 consumer.accept((regState == null)
3011 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3012 } catch (RemoteException e) {
3013 // Ignore if the remote process is no longer available to call back.
3014 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3015 }
3016 });
3017 } finally {
3018 Binder.restoreCallingIdentity(token);
3019 }
3020 }
3021
3022 /**
3023 * Get the transport type for the IMS service registration state.
3024 */
3025 @Override
3026 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3027 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3030 "IMS not available on device.");
3031 }
3032 final long token = Binder.clearCallingIdentity();
3033 try {
3034 Phone phone = getPhone(subId);
3035 if (phone == null) {
3036 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3037 + subId + "'");
3038 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3039 }
3040 phone.getImsRegistrationTech(regTech -> {
3041 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3042 int regTechConverted = (regTech == null)
3043 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3044 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3045 regTechConverted);
3046 try {
3047 consumer.accept(regTechConverted);
3048 } catch (RemoteException e) {
3049 // Ignore if the remote process is no longer available to call back.
3050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3051 }
3052 });
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
3056 }
3057
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003059 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3060 throws RemoteException {
3061 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003062 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3063 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3064 "IMS not available on device.");
3065 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3067 final long token = Binder.clearCallingIdentity();
3068 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003069 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003071 } catch (ImsException e) {
3072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 } finally {
3074 Binder.restoreCallingIdentity(token);
3075 }
3076 }
3077
3078 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003079 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3080 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3082 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3083 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003084
3085 final long token = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003089 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003090 } catch (ImsException e) {
3091 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3092 + "is inactive, ignoring unregister.");
3093 // If the subscription is no longer active, just return, since the callback
3094 // will already have been removed internally.
3095 } finally {
3096 Binder.restoreCallingIdentity(token);
3097 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003098 }
3099
3100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003101 public boolean isCapable(int subId, int capability, int regTech) {
3102 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3104 final long token = Binder.clearCallingIdentity();
3105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003108 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3110 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003111 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003112 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3113 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
3117 }
3118
3119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003120 public boolean isAvailable(int subId, int capability, int regTech) {
3121 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 final long token = Binder.clearCallingIdentity();
3123 try {
3124 Phone phone = getPhone(subId);
3125 if (phone == null) return false;
3126 return phone.isImsCapabilityAvailable(capability, regTech);
3127 } finally {
3128 Binder.restoreCallingIdentity(token);
3129 }
3130 }
3131
Brad Ebinger77b832e2019-10-17 17:03:22 -07003132 /**
3133 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3134 * subscription.
3135 * @param subId The subscription to use to check the configuration.
3136 * @param callback The callback that will be used to send the result.
3137 * @param capability The MmTelFeature capability that will be used to send the result.
3138 * @param transportType The transport type of the MmTelFeature capability.
3139 */
3140 @Override
3141 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3142 int transportType) {
3143 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3144 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3146 "IMS not available on device.");
3147 }
3148 final long token = Binder.clearCallingIdentity();
3149 try {
3150 int slotId = getSlotIndex(subId);
3151 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3152 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3153 + subId + "'");
3154 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3155 }
3156 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3157 transportType, aBoolean -> {
3158 try {
3159 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3160 } catch (RemoteException e) {
3161 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3162 + "running. Ignore");
3163 }
3164 });
3165 } finally {
3166 Binder.restoreCallingIdentity(token);
3167 }
3168 }
3169
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 @Override
3171 public boolean isAdvancedCallingSettingEnabled(int subId) {
3172 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3174 final long token = Binder.clearCallingIdentity();
3175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003176 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003178 } catch (ImsException e) {
3179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 } finally {
3181 Binder.restoreCallingIdentity(token);
3182 }
3183 }
3184
3185 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003186 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003188 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003194 } catch (ImsException e) {
3195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
3200
3201 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003202 public boolean isVtSettingEnabled(int subId) {
3203 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003207 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3208 } catch (ImsException e) {
3209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
3213 }
3214
3215 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003216 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003218 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003222 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
3231 public boolean isVoWiFiSettingEnabled(int subId) {
3232 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003236 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003238 } catch (ImsException e) {
3239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
3245 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003246 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003248 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003253 } catch (ImsException e) {
3254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
3261 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3262 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003276 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003278 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 final long identity = Binder.clearCallingIdentity();
3280 try {
3281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003284 } catch (ImsException e) {
3285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3294 "setVoWiFiNonPersistent");
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003298 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003299 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003300 } catch (ImsException e) {
3301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
3305 }
3306
3307 @Override
3308 public int getVoWiFiModeSetting(int subId) {
3309 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003315 } catch (ImsException e) {
3316 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
3323 public void setVoWiFiModeSetting(int subId, int mode) {
3324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3325 "setVoWiFiModeSetting");
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (ImsException e) {
3332 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
3336 }
3337
3338 @Override
3339 public int getVoWiFiRoamingModeSetting(int subId) {
3340 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
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(identity);
3350 }
3351 }
3352
3353 @Override
3354 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3356 "setVoWiFiRoamingModeSetting");
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003361 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003362 } catch (ImsException e) {
3363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
3369 @Override
3370 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3372 "setRttCapabilityEnabled");
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003376 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3377 } catch (ImsException e) {
3378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
3384 @Override
3385 public boolean isTtyOverVolteEnabled(int subId) {
3386 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003392 } catch (ImsException e) {
3393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 @Override
3400 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3401 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003406 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003407 } catch (ImsException e) {
3408 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
3412 }
3413
3414 @Override
3415 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3416 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3417 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003418 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3419 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3420 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003424 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003426 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3427 + "is inactive, ignoring unregister.");
3428 // If the subscription is no longer active, just return, since the callback will already
3429 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
3435 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3437 boolean isProvisioned) {
3438 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3439 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3440 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3441 }
3442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3443 "setProvisioningStatusForCapability");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3447 Phone phone = getPhone(subId);
3448 if (phone == null) {
3449 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3450 + subId);
3451 return;
3452 }
3453 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3454 return;
3455 }
3456
3457 // this capability requires provisioning, route to the correct API.
3458 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3459 switch (capability) {
3460 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3461 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3462 ims.setVolteProvisioned(isProvisioned);
3463 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3464 ims.setWfcProvisioned(isProvisioned);
3465 }
3466 break;
3467 }
3468 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3469 // There is currently no difference in VT provisioning type.
3470 ims.setVtProvisioned(isProvisioned);
3471 break;
3472 }
3473 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3474 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3475 // change the capability of the feature instead if needed.
3476 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3477 == isProvisioned) {
3478 // No change in provisioning.
3479 return;
3480 }
3481 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3482 try {
3483 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003484 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003485 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3486 + ", Exception" + e.getMessage());
3487 }
3488 break;
3489 }
3490 default: {
3491 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3492 + capability + "', which does not require provisioning.");
3493 }
3494 }
3495
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
3499 }
3500
3501 @Override
3502 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3503 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3504 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3505 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3506 }
3507 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3511 Phone phone = getPhone(subId);
3512 if (phone == null) {
3513 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3514 + subId);
3515 // We will fail with "true" as the provisioning status because this is the default
3516 // if we do not require provisioning.
3517 return true;
3518 }
3519
3520 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3521 return true;
3522 }
3523
3524 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3525 switch (capability) {
3526 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3527 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3528 return ims.isVolteProvisionedOnDevice();
3529 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3530 return ims.isWfcProvisionedOnDevice();
3531 }
3532 // This should never happen, since we are checking tech above to make sure it
3533 // is either LTE or IWLAN.
3534 throw new IllegalArgumentException("Invalid radio technology for voice "
3535 + "capability.");
3536 }
3537 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3538 // There is currently no difference in VT provisioning type.
3539 return ims.isVtProvisionedOnDevice();
3540 }
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3542 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3543 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3544 }
3545 default: {
3546 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3547 + capability + "', which does not require provisioning.");
3548 }
3549 }
3550
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
3554 }
3555
3556 @Override
3557 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3558 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3559 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3560 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3561 }
3562 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3563 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3564 return (provisionedBits & capability) > 0;
3565 }
3566
3567 @Override
3568 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3569 boolean isProvisioned) {
3570 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3571 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3572 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3573 }
3574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3575 "setProvisioningStatusForCapability");
3576 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3577 // If the current provisioning status for capability already matches isProvisioned,
3578 // do nothing.
3579 if (((provisionedBits & capability) > 0) == isProvisioned) {
3580 return;
3581 }
3582 if (isProvisioned) {
3583 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3584 } else {
3585 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3586 }
3587 }
3588
3589 /**
3590 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3591 * technology. The bitfield should mirror the bitfield defined by
3592 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3593 */
3594 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3595 String key = getMmTelProvisioningKey(subId, tech);
3596 // Default is no capabilities are provisioned.
3597 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3598 }
3599
3600 /**
3601 * Sets the MmTel capability provisioning bitfield (defined by
3602 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3603 * technology specified.
3604 *
3605 * Note: This is a synchronous command and should not be called on UI thread.
3606 */
3607 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3608 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3609 String key = getMmTelProvisioningKey(subId, tech);
3610 editor.putInt(key, newField);
3611 editor.commit();
3612 }
3613
3614 private static String getMmTelProvisioningKey(int subId, int tech) {
3615 // resulting key is provision_ims_mmtel_{subId}_{tech}
3616 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3617 }
3618
3619 /**
3620 * Query CarrierConfig to see if the specified capability requires provisioning for the
3621 * carrier associated with the subscription id.
3622 */
3623 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3624 int capability) {
3625 CarrierConfigManager configManager = new CarrierConfigManager(context);
3626 PersistableBundle c = configManager.getConfigForSubId(subId);
3627 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003628 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003629 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3630 false);
3631 boolean requireVoiceVtProvisioning = c.getBoolean(
3632 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3633
3634 // First check to make sure that the capability requires provisioning.
3635 switch (capability) {
3636 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3637 // intentional fallthrough
3638 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3639 if (requireVoiceVtProvisioning) {
3640 // Voice and Video requires provisioning
3641 return true;
3642 }
3643 break;
3644 }
3645 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3646 if (requireUtProvisioning) {
3647 // UT requires provisioning
3648 return true;
3649 }
3650 break;
3651 }
3652 }
3653 return false;
3654 }
3655
3656 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003657 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3659 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3660 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003661 enforceReadPrivilegedPermission("getImsProvisioningInt");
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 int slotId = getSlotIndex(subId);
3666 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3667 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3668 + subId + "' for key:" + key);
3669 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3670 }
3671 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003672 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003673 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3674 + subId + "' for key:" + key);
3675 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
3682 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3684 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3685 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003686 enforceReadPrivilegedPermission("getImsProvisioningString");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003690 int slotId = getSlotIndex(subId);
3691 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3692 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3693 + subId + "' for key:" + key);
3694 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3695 }
3696 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3699 + subId + "' for key:" + key);
3700 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
3707 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3709 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3710 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3712 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 int slotId = getSlotIndex(subId);
3717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3718 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3719 + subId + "' for key:" + key);
3720 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3721 }
3722 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003724 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3725 + "' for key:" + key);
3726 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3736 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3738 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003742 int slotId = getSlotIndex(subId);
3743 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3744 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3745 + subId + "' for key:" + key);
3746 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3747 }
3748 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003749 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003750 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3751 + "' for key:" + key);
3752 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
3756 }
3757
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 int slotId = SubscriptionManager.getSlotIndex(subId);
3760 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003761 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3762 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 }
3764 return slotId;
3765 }
3766
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003767 private int getSlotIndex(int subId) {
3768 int slotId = SubscriptionManager.getSlotIndex(subId);
3769 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3770 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3771 }
3772 return slotId;
3773 }
3774
Wink Saville36469e72014-06-11 15:17:00 -07003775 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003776 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003777 */
3778 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003779 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003780 final int targetSdk = getTargetSdk(callingPackage);
3781 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3782 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3783 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003784 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3785 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3787 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
3792 if (phone != null) {
3793 return phone.getServiceState().getDataNetworkType();
3794 } else {
3795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003800 }
3801
3802 /**
3803 * Returns the data network type
3804 */
3805 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003806 public int getDataNetworkType(String callingPackage) {
3807 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003808 }
3809
3810 /**
3811 * Returns the data network type for a subId
3812 */
3813 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003814 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003816 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003817 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3818 }
3819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 if (phone != null) {
3824 return phone.getServiceState().getDataNetworkType();
3825 } else {
3826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 }
3832
3833 /**
Wink Saville36469e72014-06-11 15:17:00 -07003834 * Returns the Voice network type for a subId
3835 */
3836 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003837 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003839 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003840 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3841 }
3842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 final Phone phone = getPhone(subId);
3846 if (phone != null) {
3847 return phone.getServiceState().getVoiceNetworkType();
3848 } else {
3849 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3850 }
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 }
3855
3856 /**
3857 * @return true if a ICC card is present
3858 */
3859 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003860 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003861 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3862 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003863 }
3864
3865 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003866 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003869 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = PhoneFactory.getPhone(slotIndex);
3873 if (phone != null) {
3874 return phone.getIccCard().hasIccCard();
3875 } else {
3876 return false;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 }
3882
3883 /**
3884 * Return if the current radio is LTE on CDMA. This
3885 * is a tri-state return value as for a period of time
3886 * the mode may be unknown.
3887 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003888 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003890 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 @Override
3893 public int getLteOnCdmaMode(String callingPackage) {
3894 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003895 }
3896
Sanket Padawe356d7632015-06-22 14:03:32 -07003897 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003900 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003901 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3902 }
3903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 final Phone phone = getPhone(subId);
3907 if (phone == null) {
3908 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3909 } else {
3910 return phone.getLteOnCdmaMode();
3911 }
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003914 }
Wink Saville36469e72014-06-11 15:17:00 -07003915 }
3916
Wink Saville36469e72014-06-11 15:17:00 -07003917 /**
3918 * {@hide}
3919 * Returns Default subId, 0 in the case of single standby.
3920 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003921 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003922 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003923 }
3924
Shishir Agrawala9f32182016-04-12 12:00:16 -07003925 private int getSlotForDefaultSubscription() {
3926 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3927 }
3928
Wink Savilleb564aae2014-10-23 10:18:09 -07003929 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003930 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003932
Pengquan Menge92a50d2018-09-21 15:54:48 -07003933 private boolean isActiveSubscription(int subId) {
3934 return mSubscriptionController.isActiveSubId(subId);
3935 }
3936
Ihab Awadf2177b72013-11-25 13:33:23 -08003937 /**
3938 * @see android.telephony.TelephonyManager.WifiCallingChoices
3939 */
3940 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 final long identity = Binder.clearCallingIdentity();
3942 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3945 getWhenToMakeWifiCallsDefaultPreference());
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003949 }
3950
3951 /**
3952 * @see android.telephony.TelephonyManager.WifiCallingChoices
3953 */
3954 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003963 }
3964
Sailesh Nepald1e68152013-12-12 19:08:02 -08003965 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003966 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003967 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003968 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003969
Jordan Liu4c733742019-02-28 12:03:40 -08003970 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3971 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3972 if (phoneId == -1) {
3973 throw new IllegalArgumentException("Given slot index: " + slotIndex
3974 + " does not correspond to an active phone");
3975 }
3976 return PhoneFactory.getPhone(phoneId);
3977 }
3978
Shishir Agrawal566b7612013-10-28 14:41:00 -07003979 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003980 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3981 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3983 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003985 if (DBG) {
3986 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3987 }
3988 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3989 p2);
3990 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003991
Jordan Liu4c733742019-02-28 12:03:40 -08003992
3993 @Override
3994 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3995 int slotIndex, String callingPackage, String aid, int p2) {
3996 enforceModifyPermission();
3997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3998 if (DBG) {
3999 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4000 }
4001 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4002 callingPackage, aid, p2);
4003 }
4004
4005 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4006 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 if (TextUtils.equals(ISDR_AID, aid)) {
4010 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4012 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 if (bestComponent == null
4014 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4015 loge("The calling package is not allowed to access ISD-R.");
4016 throw new SecurityException(
4017 "The calling package is not allowed to access ISD-R.");
4018 }
Derek Tan740e1672017-06-27 14:56:27 -07004019 }
Derek Tan740e1672017-06-27 14:56:27 -07004020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004022 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4023 null /* workSource */);
4024 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 return response;
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004029 }
4030
4031 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004032 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4034 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004035 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4036 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004038
Jordan Liu4c733742019-02-28 12:03:40 -08004039 @Override
4040 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4041 enforceModifyPermission();
4042 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4043 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4044 channel);
4045 }
4046
4047 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 if (channel < 0) {
4051 return false;
4052 }
Jordan Liu4c733742019-02-28 12:03:40 -08004053 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4054 null /* workSource */);
4055 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 return success;
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004060 }
4061
4062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004063 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004067 if (DBG) {
4068 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4069 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4070 + p3 + " data=" + data);
4071 }
4072 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4073 command, p1, p2, p3, data);
4074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004075
Jordan Liu4c733742019-02-28 12:03:40 -08004076 @Override
4077 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4078 int command, int p1, int p2, int p3, String data) {
4079 enforceModifyPermission();
4080 if (DBG) {
4081 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4082 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4083 + p3 + " data=" + data);
4084 }
4085 return iccTransmitApduLogicalChannelWithPermission(
4086 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4087 data);
4088 }
4089
4090 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4091 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004094 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 return "";
4096 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004099 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4100 null /* workSource */);
4101 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 // Append the returned status code to the end of the response payload.
4104 String s = Integer.toHexString(
4105 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4106 if (response.payload != null) {
4107 s = IccUtils.bytesToHexString(response.payload) + s;
4108 }
4109 return s;
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004112 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004113 }
Jake Hambye994d462014-02-03 13:10:13 -08004114
Evan Charltonc66da362014-05-16 14:06:40 -07004115 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004116 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4117 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4119 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004121 if (DBG) {
4122 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4123 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4124 }
4125 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4126 cla, command, p1, p2, p3, data);
4127 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004128
Jordan Liu4c733742019-02-28 12:03:40 -08004129 @Override
4130 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4131 int command, int p1, int p2, int p3, String data) {
4132 enforceModifyPermission();
4133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4134 if (DBG) {
4135 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4136 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4137 + " data=" + data);
4138 }
4139
4140 return iccTransmitApduBasicChannelWithPermission(
4141 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4142 p2, p3, data);
4143 }
4144
4145 // open APDU basic channel assuming the caller has sufficient permissions
4146 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4147 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4151 && TextUtils.equals(ISDR_AID, data)) {
4152 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4154 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 if (bestComponent == null
4156 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4157 loge("The calling package is not allowed to select ISD-R.");
4158 throw new SecurityException(
4159 "The calling package is not allowed to select ISD-R.");
4160 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004164 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4165 null /* workSource */);
4166 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 // Append the returned status code to the end of the response payload.
4169 String s = Integer.toHexString(
4170 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4171 if (response.payload != null) {
4172 s = IccUtils.bytesToHexString(response.payload) + s;
4173 }
4174 return s;
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004177 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004178 }
4179
4180 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004181 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004182 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4184 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 if (DBG) {
4189 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4190 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4191 }
4192
4193 IccIoResult response =
4194 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4195 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4196 subId);
4197
4198 if (DBG) {
4199 log("Exchange SIM_IO [R]" + response);
4200 }
4201
4202 byte[] result = null;
4203 int length = 2;
4204 if (response.payload != null) {
4205 length = 2 + response.payload.length;
4206 result = new byte[length];
4207 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4208 } else {
4209 result = new byte[length];
4210 }
4211
4212 result[length - 1] = (byte) response.sw2;
4213 result[length - 2] = (byte) response.sw1;
4214 return result;
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004217 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004218 }
4219
Nathan Haroldb3014052017-01-25 15:57:32 -08004220 /**
4221 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4222 * on a particular subscription
4223 */
sqianb6e41952018-03-12 14:54:01 -07004224 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4226 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4227 return null;
4228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 if (appType != TelephonyManager.APPTYPE_USIM
4233 && appType != TelephonyManager.APPTYPE_SIM) {
4234 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4235 return null;
4236 }
4237 Object response = sendRequest(
4238 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4239 if (response instanceof String[]) {
4240 return (String[]) response;
4241 }
yincheng zhaod698b842019-09-06 17:06:54 -07004242 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004244 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004247 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004248 }
4249
yincheng zhaod698b842019-09-06 17:06:54 -07004250 /**
4251 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4252 * subscription.
4253 *
4254 * @param subId the id of the subscription.
4255 * @param appType the uicc app type, must be USIM or SIM.
4256 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4257 * @param callingPackage the op Package name.
4258 * @return number of fplmns that is successfully written to the SIM.
4259 */
4260 public int setForbiddenPlmns(
4261 int subId, int appType, List<String> fplmns, String callingPackage) {
4262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4263 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4264 if (DBG) logv("no permissions for setForbiddenplmns");
4265 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4266 }
4267 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4268 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4269 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4270 }
4271 if (fplmns == null) {
4272 throw new IllegalArgumentException("Fplmn List provided is null");
4273 }
4274 for (String fplmn : fplmns) {
4275 if (!CellIdentity.isValidPlmn(fplmn)) {
4276 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4277 }
4278 }
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 Object response = sendRequest(
4282 CMD_SET_FORBIDDEN_PLMNS,
4283 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4284 subId);
4285 return (int) response;
4286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004292 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4294 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4299 if (response.payload == null) {
4300 return "";
4301 }
Evan Charltonc66da362014-05-16 14:06:40 -07004302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 // Append the returned status code to the end of the response payload.
4304 String s = Integer.toHexString(
4305 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4306 s = IccUtils.bytesToHexString(response.payload) + s;
4307 return s;
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Evan Charltonc66da362014-05-16 14:06:40 -07004311 }
4312
Jake Hambye994d462014-02-03 13:10:13 -08004313 /**
4314 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4315 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4316 *
4317 * @param itemID the ID of the item to read
4318 * @return the NV item as a String, or null on error.
4319 */
4320 @Override
4321 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4324 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004329 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4331 return value;
4332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Jake Hambye994d462014-02-03 13:10:13 -08004335 }
4336
4337 /**
4338 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4339 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4340 *
4341 * @param itemID the ID of the item to read
4342 * @param itemValue the value to write, as a String
4343 * @return true on success; false on any failure
4344 */
4345 @Override
4346 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4349 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4354 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004355 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4357 return success;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Jake Hambye994d462014-02-03 13:10:13 -08004361 }
4362
4363 /**
4364 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4365 * Used for device configuration by some CDMA operators.
4366 *
4367 * @param preferredRoamingList byte array containing the new PRL
4368 * @return true on success; false on any failure
4369 */
4370 @Override
4371 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4373 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374
4375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4378 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4379 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4380 return success;
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Jake Hambye994d462014-02-03 13:10:13 -08004384 }
4385
4386 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004387 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004388 * Used for device configuration by some CDMA operators.
4389 *
chen xu6dac5ab2018-10-26 17:39:23 -07004390 * @param slotIndex - device slot.
4391 *
Jake Hambye994d462014-02-03 13:10:13 -08004392 * @return true on success; false on any failure
4393 */
4394 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004395 public boolean resetModemConfig(int slotIndex) {
4396 Phone phone = PhoneFactory.getPhone(slotIndex);
4397 if (phone != null) {
4398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4399 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400
chen xu6dac5ab2018-10-26 17:39:23 -07004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4404 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 }
chen xu6dac5ab2018-10-26 17:39:23 -07004410 return false;
4411 }
4412
4413 /**
4414 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4415 *
4416 * @param slotIndex - device slot.
4417 *
4418 * @return true on success; false on any failure
4419 */
4420 @Override
4421 public boolean rebootModem(int slotIndex) {
4422 Phone phone = PhoneFactory.getPhone(slotIndex);
4423 if (phone != null) {
4424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, phone.getSubId(), "rebootModem");
4426
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4430 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4431 return success;
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004437 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004438
Svet Ganovb320e182015-04-16 12:30:10 -07004439 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004440 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004442 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004443 return new String[0];
4444 }
4445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004448 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Wink Saville36469e72014-06-11 15:17:00 -07004452 }
4453
Brad Ebinger51f743a2017-01-23 13:50:20 -08004454 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004455 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4456 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004457 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004458 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004463 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004464 // may happen if the device does not support IMS.
4465 return;
4466 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004467 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004471 }
4472
4473 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004474 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4475 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004476 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004477 public void disableIms(int slotId) {
4478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004483 // may happen if the device does not support IMS.
4484 return;
4485 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004486 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004490 }
4491
4492 /**
4493 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4494 * feature or {@link null} if the service is not available. If the feature is available, the
4495 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4496 */
4497 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004498 IImsServiceFeatureCallback callback) {
4499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500
4501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004503 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004504 // may happen if the device does not support IMS.
4505 return null;
4506 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004507 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004511 }
4512
4513 /**
4514 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4515 * feature during emergency calling or {@link null} if the service is not available. If the
4516 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4517 * listener for feature updates.
4518 */
4519 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004524 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004525 // may happen if the device does not support IMS.
4526 return null;
4527 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004528 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004532 }
4533
Brad Ebinger5f64b052017-12-14 14:26:15 -08004534 /**
4535 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004536 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004537 */
4538 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4539 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540
4541 final long identity = Binder.clearCallingIdentity();
4542 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004543 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004544 // may happen if the device does not support IMS.
4545 return null;
4546 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004547 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004551 }
4552
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004553 /**
4554 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004555 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004556 */
4557 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004562 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004563 // may happen if the device does not support IMS.
4564 return null;
4565 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004566 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004570 }
4571
Brad Ebinger884c07b2018-02-15 16:17:40 -08004572 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004573 * Sets the ImsService Package Name that Telephony will bind to.
4574 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004575 * @param slotIndex the slot ID that the ImsService should bind for.
4576 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004577 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004578 * @param featureTypes An integer array of feature types associated with a packageName.
4579 * @param packageName The name of the package that the current configuration will be replaced
4580 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004581 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004582 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004583 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4584 int[] featureTypes, String packageName) {
4585 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4588 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004589 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004593 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004594 // may happen if the device does not support IMS.
4595 return false;
4596 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004597 Map<Integer, String> featureConfig = new HashMap<>();
4598 for (int featureType : featureTypes) {
4599 featureConfig.put(featureType, packageName);
4600 }
4601 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4602 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004606 }
4607
4608 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004609 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004610 *
4611 * @param slotId The slot that the ImsService is associated with.
4612 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4613 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004614 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004615 * @return the package name of the ImsService configuration.
4616 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004617 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4618 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004619 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004620 TelephonyPermissions
4621 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4622 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4623 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004627 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004628 // may happen if the device does not support IMS.
4629 return "";
4630 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004631 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004632 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4633 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004637 }
4638
Brad Ebinger77b832e2019-10-17 17:03:22 -07004639 /**
4640 * Get the MmTelFeature state associated with the requested subscription id.
4641 * @param subId The subscription that the MmTelFeature is associated with.
4642 * @param callback A callback with an integer containing the
4643 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4644 */
4645 @Override
4646 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4647 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4648 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4650 "IMS not available on device.");
4651 }
4652 final long token = Binder.clearCallingIdentity();
4653 try {
4654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4657 + subId + "'");
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4659 }
4660 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4661 try {
4662 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4663 } catch (RemoteException e) {
4664 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4665 + "Ignore");
4666 }
4667 });
4668 } finally {
4669 Binder.restoreCallingIdentity(token);
4670 }
4671 }
4672
Wink Saville36469e72014-06-11 15:17:00 -07004673 public void setImsRegistrationState(boolean registered) {
4674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675
4676 final long identity = Binder.clearCallingIdentity();
4677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004678 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
Wink Saville36469e72014-06-11 15:17:00 -07004682 }
4683
4684 /**
Stuart Scott54788802015-03-30 13:18:01 -07004685 * Set the network selection mode to automatic.
4686 *
4687 */
4688 @Override
4689 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4691 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692
Pengquan Menge92a50d2018-09-21 15:54:48 -07004693 if (!isActiveSubscription(subId)) {
4694 return;
4695 }
4696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4700 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
Stuart Scott54788802015-03-30 13:18:01 -07004704 }
4705
Pengquan Mengea84e042018-09-20 14:57:26 -07004706 /**
4707 * Ask the radio to connect to the input network and change selection mode to manual.
4708 *
4709 * @param subId the id of the subscription.
4710 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4711 * the operator to attach to.
4712 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4713 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4714 * normal network selection next time.
4715 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004716 */
4717 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004718 public boolean setNetworkSelectionModeManual(
4719 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4721 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004722
4723 if (!isActiveSubscription(subId)) {
4724 return false;
4725 }
4726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004729 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004731 if (DBG) {
4732 log("setNetworkSelectionModeManual: subId: " + subId
4733 + " operator: " + operatorInfo);
4734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004739 }
4740
4741 /**
4742 * Scans for available networks.
4743 */
4744 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004745 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004748 LocationAccessPolicy.LocationPermissionResult locationResult =
4749 LocationAccessPolicy.checkLocationPermission(mApp,
4750 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4751 .setCallingPackage(callingPackage)
4752 .setCallingPid(Binder.getCallingPid())
4753 .setCallingUid(Binder.getCallingUid())
4754 .setMethod("getCellNetworkScanResults")
4755 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4756 .build());
4757 switch (locationResult) {
4758 case DENIED_HARD:
4759 throw new SecurityException("Not allowed to access scan results -- location");
4760 case DENIED_SOFT:
4761 return null;
4762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763
Pengquan Menga1bb6272018-09-06 09:59:22 -07004764 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 try {
4766 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004767 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004772 }
4773
4774 /**
yinxub1bed742017-04-17 11:45:04 -07004775 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004776 *
yinxub1bed742017-04-17 11:45:04 -07004777 * @param subId id of the subscription
4778 * @param request contains the radio access networks with bands/channels to scan
4779 * @param messenger callback messenger for scan results or errors
4780 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004781 * @return the id of the requested scan which can be used to stop the scan.
4782 */
4783 @Override
4784 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004785 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004788 LocationAccessPolicy.LocationPermissionResult locationResult =
4789 LocationAccessPolicy.checkLocationPermission(mApp,
4790 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4791 .setCallingPackage(callingPackage)
4792 .setCallingPid(Binder.getCallingPid())
4793 .setCallingUid(Binder.getCallingUid())
4794 .setMethod("requestNetworkScan")
4795 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4796 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004797 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004798 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004799 if (e != null) {
4800 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4801 throw e;
4802 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004803 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004804 return TelephonyScanManager.INVALID_SCAN_ID;
4805 }
4806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 }
Hall Liu912dfd32019-04-25 14:02:26 -07004808 int callingUid = Binder.getCallingUid();
4809 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004810 final long identity = Binder.clearCallingIdentity();
4811 try {
4812 return mNetworkScanRequestTracker.startNetworkScan(
4813 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004814 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
yinxu504e1392017-04-12 16:03:22 -07004818 }
4819
Hall Liub2ac8ef2019-02-28 15:56:23 -08004820 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004821 NetworkScanRequest request, int subId) {
4822 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4823 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4824 boolean hasNetworkScanPermission =
4825 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4826 == PERMISSION_GRANTED;
4827
4828 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4829 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4830 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004831 }
4832
4833 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4834 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004835 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4836 return new SecurityException("Specific channels must not be"
4837 + " scanned without location access.");
4838 }
4839 }
4840 }
4841
Hall Liub2ac8ef2019-02-28 15:56:23 -08004842 return null;
4843 }
4844
yinxu504e1392017-04-12 16:03:22 -07004845 /**
4846 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004847 *
4848 * @param subId id of the subscription
4849 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004850 */
4851 @Override
4852 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4854 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855
Hall Liu912dfd32019-04-25 14:02:26 -07004856 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004859 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
yinxu504e1392017-04-12 16:03:22 -07004863 }
4864
4865 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004866 * Get the calculated preferred network type.
4867 * Used for debugging incorrect network type.
4868 *
4869 * @return the preferred network type, defined in RILConstants.java.
4870 */
4871 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004872 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 final Phone defaultPhone = getDefaultPhone();
4874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4875 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004876 return RILConstants.PREFERRED_NETWORK_MODE;
4877 }
4878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Junda Liu84d15a22014-07-02 11:21:04 -07004886 }
4887
4888 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004889 * Get the preferred network type.
4890 * Used for device configuration by some CDMA operators.
4891 *
4892 * @return the preferred network type, defined in RILConstants.java.
4893 */
4894 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004895 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004896 TelephonyPermissions
4897 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4898 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 if (DBG) log("getPreferredNetworkType");
4903 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4904 int networkType = (result != null ? result[0] : -1);
4905 if (DBG) log("getPreferredNetworkType: " + networkType);
4906 return networkType;
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004910 }
4911
4912 /**
4913 * Set the preferred network type.
4914 * Used for device configuration by some CDMA operators.
4915 *
4916 * @param networkType the preferred network type, defined in RILConstants.java.
4917 * @return true on success; false on any failure.
4918 */
4919 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004920 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4922 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4927 Boolean success = (Boolean) sendRequest(
4928 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4929 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4930 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4933 }
4934 return success;
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004937 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004938 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004939
4940 /**
Miaoa84611c2019-03-15 09:21:10 +08004941 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004942 *
Miaoa84611c2019-03-15 09:21:10 +08004943 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004944 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004945 * @hide
4946 */
4947 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004948 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004951 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 try {
Miaoa84611c2019-03-15 09:21:10 +08004953 if (phone != null) {
4954 return phone.hasMatchedTetherApnSetting();
4955 } else {
4956 return false;
4957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004960 }
Junda Liu475951f2014-11-07 16:45:03 -08004961 }
4962
4963 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004964 * Set mobile data enabled
4965 * Used by the user through settings etc to turn on/off mobile data
4966 *
4967 * @param enable {@code true} turn turn data on, else {@code false}
4968 */
4969 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004970 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973
4974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 int phoneId = mSubscriptionController.getPhoneId(subId);
4977 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4978 Phone phone = PhoneFactory.getPhone(phoneId);
4979 if (phone != null) {
4980 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004981 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004983 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 }
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004987 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004988 }
4989
4990 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004991 * Get the user enabled state of Mobile Data.
4992 *
4993 * TODO: remove and use isUserDataEnabled.
4994 * This can't be removed now because some vendor codes
4995 * calls through ITelephony directly while they should
4996 * use TelephonyManager.
4997 *
4998 * @return true on enabled
4999 */
5000 @Override
5001 public boolean getDataEnabled(int subId) {
5002 return isUserDataEnabled(subId);
5003 }
5004
5005 /**
5006 * Get whether mobile data is enabled per user setting.
5007 *
5008 * There are other factors deciding whether mobile data is actually enabled, but they are
5009 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005010 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005011 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005012 *
5013 * @return {@code true} if data is enabled else {@code false}
5014 */
5015 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005016 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005017 try {
5018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5019 null);
5020 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 int phoneId = mSubscriptionController.getPhoneId(subId);
5028 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5029 Phone phone = PhoneFactory.getPhone(phoneId);
5030 if (phone != null) {
5031 boolean retVal = phone.isUserDataEnabled();
5032 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5033 return retVal;
5034 } else {
5035 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5036 return false;
5037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005040 }
5041 }
5042
5043 /**
5044 * Get whether mobile data is enabled.
5045 *
5046 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5047 * whether mobile data is actually enabled.
5048 *
5049 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5050 *
5051 * @return {@code true} if data is enabled else {@code false}
5052 */
5053 @Override
5054 public boolean isDataEnabled(int subId) {
5055 try {
5056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5057 null);
5058 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
5063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 int phoneId = mSubscriptionController.getPhoneId(subId);
5066 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5067 Phone phone = PhoneFactory.getPhone(phoneId);
5068 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005069 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5071 return retVal;
5072 } else {
5073 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5074 return false;
5075 }
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005078 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005079 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005080
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005081 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5082 Phone phone) {
5083 //load access rules from carrier configs, and check those as well: b/139133814
5084 SubscriptionController subController = SubscriptionController.getInstance();
5085 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5086 || subController == null) return privilegeFromSim;
5087
5088 int uid = Binder.getCallingUid();
5089 PackageManager pkgMgr = phone.getContext().getPackageManager();
5090 String[] packages = pkgMgr.getPackagesForUid(uid);
5091
5092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5095 SubscriptionManager subManager = (SubscriptionManager)
5096 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5097 for (String pkg : packages) {
5098 if (subManager.canManageSubscription(subInfo, pkg)) {
5099 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5100 }
5101 }
5102 return privilegeFromSim;
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
5106 }
5107
5108 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5109 String pkgName) {
5110 //load access rules from carrier configs, and check those as well: b/139133814
5111 SubscriptionController subController = SubscriptionController.getInstance();
5112 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5113 || subController == null) return privilegeFromSim;
5114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5118 SubscriptionManager subManager = (SubscriptionManager)
5119 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5120 return subManager.canManageSubscription(subInfo, pkgName)
5121 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
5125 }
5126
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public int getCarrierPrivilegeStatus(int subId) {
5129 final Phone phone = getPhone(subId);
5130 if (phone == null) {
5131 loge("getCarrierPrivilegeStatus: Invalid subId");
5132 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5133 }
5134 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005135 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005136 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005137 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5138 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005139
5140 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5141 card.getCarrierPrivilegeStatusForCurrentTransaction(
5142 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005143 }
Junda Liu29340342014-07-10 15:23:27 -07005144
5145 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005146 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5147 final Phone phone = getPhone(subId);
5148 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005149 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5151 }
5152 UiccProfile profile =
5153 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5154 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005155 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005156 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5157 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005158 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5159 profile.getCarrierPrivilegeStatusForUid(
5160 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005161 }
5162
5163 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005164 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5165 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005167 }
5168
5169 int phoneId = SubscriptionManager.getPhoneId(subId);
5170 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005171 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005172 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005173 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5174 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005175 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5176 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5177 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005178 }
5179
5180 @Override
5181 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005182 if (TextUtils.isEmpty(pkgName))
5183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005184 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5185 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5186 UiccCard card = UiccController.getInstance().getUiccCard(i);
5187 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005188 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005189 continue;
5190 }
5191
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005192 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5193 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5194 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005195 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5196 break;
5197 }
5198 }
5199
5200 return result;
Junda Liu29340342014-07-10 15:23:27 -07005201 }
Derek Tan89e89d42014-07-08 17:00:10 -07005202
5203 @Override
Junda Liue64de782015-04-16 17:19:16 -07005204 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5205 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5206 loge("phoneId " + phoneId + " is not valid.");
5207 return null;
5208 }
5209 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005210 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005211 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005212 return null ;
5213 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005214 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005215 }
5216
Amith Yamasani6e118872016-02-19 12:53:51 -08005217 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005218 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005220 List<String> privilegedPackages = new ArrayList<>();
5221 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005222 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5223 // has UICC in that slot.
5224 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005225 if (card.hasCarrierPrivilegeRules()) {
5226 if (packages == null) {
5227 // Only check packages in user 0 for now
5228 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005229 PackageManager.MATCH_DISABLED_COMPONENTS
5230 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005231 | PackageManager.GET_SIGNING_CERTIFICATES,
5232 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005233 }
5234 for (int p = packages.size() - 1; p >= 0; p--) {
5235 PackageInfo pkgInfo = packages.get(p);
5236 if (pkgInfo != null && pkgInfo.packageName != null
5237 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005238 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005239 privilegedPackages.add(pkgInfo.packageName);
5240 }
5241 }
5242 }
5243 }
5244 return privilegedPackages;
5245 }
5246
chen xuf7e9fe82019-05-09 19:31:02 -07005247 @Override
5248 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005249 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5250
5251 final long identity = Binder.clearCallingIdentity();
5252
chen xuf7e9fe82019-05-09 19:31:02 -07005253 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005254 try {
5255 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5256 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005260 }
5261 return privilegedPackages;
5262 }
5263
Wink Savilleb564aae2014-10-23 10:18:09 -07005264 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005265 final Phone phone = getPhone(subId);
5266 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005267 if (card == null) {
5268 loge("getIccId: No UICC");
5269 return null;
5270 }
5271 String iccId = card.getIccId();
5272 if (TextUtils.isEmpty(iccId)) {
5273 loge("getIccId: ICC ID is null or empty.");
5274 return null;
5275 }
5276 return iccId;
5277 }
5278
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005279 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005280 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5281 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5283 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 final String iccId = getIccId(subId);
5288 final Phone phone = getPhone(subId);
5289 if (phone == null) {
5290 return false;
5291 }
5292 final String subscriberId = phone.getSubscriberId();
5293
5294 if (DBG_MERGE) {
5295 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5296 + subscriberId + " to " + number);
5297 }
5298
5299 if (TextUtils.isEmpty(iccId)) {
5300 return false;
5301 }
5302
5303 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5304
5305 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5306 if (alphaTag == null) {
5307 editor.remove(alphaTagPrefKey);
5308 } else {
5309 editor.putString(alphaTagPrefKey, alphaTag);
5310 }
5311
5312 // Record both the line number and IMSI for this ICCID, since we need to
5313 // track all merged IMSIs based on line number
5314 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5315 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5316 if (number == null) {
5317 editor.remove(numberPrefKey);
5318 editor.remove(subscriberPrefKey);
5319 } else {
5320 editor.putString(numberPrefKey, number);
5321 editor.putString(subscriberPrefKey, subscriberId);
5322 }
5323
5324 editor.commit();
5325 return true;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005328 }
Derek Tan7226c842014-07-02 17:42:23 -07005329 }
5330
5331 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005332 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005333 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005335 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005336 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005337 return null;
5338 }
Derek Tan97ebb422014-09-05 16:55:38 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 String iccId = getIccId(subId);
5343 if (iccId != null) {
5344 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5345 if (DBG_MERGE) {
5346 log("getLine1NumberForDisplay returning "
5347 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5348 }
5349 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5352 return null;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005355 }
Derek Tan7226c842014-07-02 17:42:23 -07005356 }
5357
5358 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005359 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005361 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005362 return null;
5363 }
Derek Tan97ebb422014-09-05 16:55:38 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 String iccId = getIccId(subId);
5368 if (iccId != null) {
5369 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5370 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5371 }
5372 return null;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005375 }
Derek Tan7226c842014-07-02 17:42:23 -07005376 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005377
5378 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005379 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005380 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5381 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005383 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5384 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005385 return null;
5386 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005387
Jordan Liub49b04b2019-05-06 14:45:15 -07005388 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5389 // the process, where TelephonyManager was instantiated.
5390 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005391 final long identity = Binder.clearCallingIdentity();
5392 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final TelephonyManager tele = TelephonyManager.from(context);
5395 final SubscriptionManager sub = SubscriptionManager.from(context);
5396
5397 // Figure out what subscribers are currently active
5398 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
Jordan Liub49b04b2019-05-06 14:45:15 -07005400 // Only consider subs which match the current subId
5401 // This logic can be simplified. See b/131189269 for progress.
5402 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005403 activeSubscriberIds.add(tele.getSubscriberId(subId));
5404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405
5406 // First pass, find a number override for an active subscriber
5407 String mergeNumber = null;
5408 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5409 for (String key : prefs.keySet()) {
5410 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5411 final String subscriberId = (String) prefs.get(key);
5412 if (activeSubscriberIds.contains(subscriberId)) {
5413 final String iccId = key.substring(
5414 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5415 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5416 mergeNumber = (String) prefs.get(numberKey);
5417 if (DBG_MERGE) {
5418 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5419 + " for active subscriber " + subscriberId);
5420 }
5421 if (!TextUtils.isEmpty(mergeNumber)) {
5422 break;
5423 }
5424 }
5425 }
5426 }
5427
5428 // Shortcut when no active merged subscribers
5429 if (TextUtils.isEmpty(mergeNumber)) {
5430 return null;
5431 }
5432
5433 // Second pass, find all subscribers under that line override
5434 final ArraySet<String> result = new ArraySet<>();
5435 for (String key : prefs.keySet()) {
5436 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5437 final String number = (String) prefs.get(key);
5438 if (mergeNumber.equals(number)) {
5439 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5440 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5441 final String subscriberId = (String) prefs.get(subscriberKey);
5442 if (!TextUtils.isEmpty(subscriberId)) {
5443 result.add(subscriberId);
5444 }
5445 }
5446 }
5447 }
5448
5449 final String[] resultArray = result.toArray(new String[result.size()]);
5450 Arrays.sort(resultArray);
5451 if (DBG_MERGE) {
5452 Slog.d(LOG_TAG,
5453 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5454 }
5455 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005458 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005459 }
5460
5461 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005462 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5463 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 final TelephonyManager telephonyManager = mApp.getSystemService(
5468 TelephonyManager.class);
5469 String subscriberId = telephonyManager.getSubscriberId(subId);
5470 if (subscriberId == null) {
5471 if (DBG) {
5472 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5473 + subId);
5474 }
5475 return null;
5476 }
5477
5478 final SubscriptionInfo info = SubscriptionController.getInstance()
5479 .getSubscriptionInfo(subId);
5480 final ParcelUuid groupUuid = info.getGroupUuid();
5481 // If it doesn't belong to any group, return just subscriberId of itself.
5482 if (groupUuid == null) {
5483 return new String[]{subscriberId};
5484 }
5485
5486 // Get all subscriberIds from the group.
5487 final List<String> mergedSubscriberIds = new ArrayList<>();
5488 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5489 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5490 for (SubscriptionInfo subInfo : groupInfos) {
5491 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5492 if (subscriberId != null) {
5493 mergedSubscriberIds.add(subscriberId);
5494 }
5495 }
5496
5497 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500
5501 }
5502 }
5503
5504 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005505 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5507 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 final Phone phone = getPhone(subId);
5512 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005516 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005517
5518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005519 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005520 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5521 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 final Phone phone = getPhone(subId);
5527 if (phone == null) {
5528 return false;
5529 }
5530 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5531 cdmaNonRoamingList);
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005534 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005535 }
5536
5537 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005538 @Deprecated
5539 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5540 enforceModifyPermission();
5541
5542 int returnValue = 0;
5543 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005544 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005545 if(result.exception == null) {
5546 if (result.result != null) {
5547 byte[] responseData = (byte[])(result.result);
5548 if(responseData.length > oemResp.length) {
5549 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5550 responseData.length + "bytes. Buffer Size is " +
5551 oemResp.length + "bytes.");
5552 }
5553 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5554 returnValue = responseData.length;
5555 }
5556 } else {
5557 CommandException ex = (CommandException) result.exception;
5558 returnValue = ex.getCommandError().ordinal();
5559 if(returnValue > 0) returnValue *= -1;
5560 }
5561 } catch (RuntimeException e) {
5562 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5563 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5564 if(returnValue > 0) returnValue *= -1;
5565 }
5566
5567 return returnValue;
5568 }
5569
5570 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005571 public void setRadioCapability(RadioAccessFamily[] rafs) {
5572 try {
5573 ProxyController.getInstance().setRadioCapability(rafs);
5574 } catch (RuntimeException e) {
5575 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5576 }
5577 }
5578
5579 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005580 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005581 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005582 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005583 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005584 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 final long identity = Binder.clearCallingIdentity();
5587 try {
chen xub97461a2018-10-26 14:17:57 -07005588 TelephonyPermissions
5589 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5590 mApp, phone.getSubId(), "getRadioAccessFamily");
5591 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
chen xub97461a2018-10-26 14:17:57 -07005595 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005596 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005597
5598 @Override
5599 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005600 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 ImsManager.getInstance(defaultPhone.getContext(),
5606 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005610 }
5611
5612 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005613 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005616 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005617 return false;
5618 }
Svet Ganovb320e182015-04-16 12:30:10 -07005619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 // Check the user preference and the system-level IMS setting. Even if the user has
5623 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5624 // In the long run, we may instead need to check if there exists a connection service
5625 // which can support video calling.
5626 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005627 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 return imsManager.isVtEnabledByPlatform()
5629 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5630 && imsManager.isVtEnabledByUser();
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005634 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005635
Andrew Leea1239f22015-03-02 17:44:07 -08005636 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5639 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5640 return false;
5641 }
5642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 CarrierConfigManager configManager =
5646 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005647 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Andrew Leea1239f22015-03-02 17:44:07 -08005652 }
5653
5654 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 public boolean isWorldPhone(int subId, String callingPackage) {
5656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5657 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5658 return false;
5659 }
5660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 CarrierConfigManager configManager =
5664 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Andrew Leea1239f22015-03-02 17:44:07 -08005670 }
5671
Andrew Lee9431b832015-03-09 18:46:45 -07005672 @Override
5673 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005674 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005675 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005676 }
5677
5678 @Override
5679 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005682 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Andrew Lee9431b832015-03-09 18:46:45 -07005686 }
5687
Hall Liuf6668912018-10-31 17:05:23 -07005688 /**
5689 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5690 * support for the feature and device firmware support.
5691 *
5692 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5693 */
5694 @Override
5695 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005697 final Phone phone = getPhone(subscriptionId);
5698 if (phone == null) {
5699 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5700 return false;
5701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5705 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 return isCarrierSupported && isDeviceSupported;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Hall Liu98187582018-01-22 19:15:32 -08005711 }
5712
Hall Liuf6668912018-10-31 17:05:23 -07005713 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005714 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5715 * RTT setting, will return true if the device and carrier both support RTT.
5716 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005717 */
5718 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005721 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005725 }
5726
Sanket Padawe7310cc72015-01-14 09:53:20 -08005727 /**
5728 * Returns the unique device ID of phone, for example, the IMEI for
5729 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5730 *
5731 * <p>Requires Permission:
5732 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5733 */
5734 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005735 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005736 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005737 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005738 return null;
5739 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005740 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005741 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5742 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005743 return null;
5744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 return phone.getDeviceId();
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005752 }
5753
Ping Sunc67b7c22016-03-02 19:16:45 +08005754 /**
5755 * {@hide}
5756 * Returns the IMS Registration Status on a particular subid
5757 *
5758 * @param subId
5759 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005760 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005761 Phone phone = getPhone(subId);
5762 if (phone != null) {
5763 return phone.isImsRegistered();
5764 } else {
5765 return false;
5766 }
5767 }
5768
Santos Cordon7a1885b2015-02-03 11:15:19 -08005769 @Override
5770 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005777 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005778
Tyler Gunnf70ed162019-04-03 15:28:53 -07005779 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005780 public int getSubIdForPhoneAccountHandle(
5781 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5783 callingPackage, "getSubIdForPhoneAccountHandle")) {
5784 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5785 }
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
5792 }
5793
5794 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005795 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 Phone phone = getPhone(subscriptionId);
5799 if (phone == null) {
5800 return null;
5801 }
5802 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
5806 }
5807
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005808 /**
5809 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005810 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005811 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 Phone phone = getPhone(subId);
5815 if (phone != null) {
5816 return phone.isWifiCallingEnabled();
5817 } else {
5818 return false;
5819 }
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005822 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005823 }
5824
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005825 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005826 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005827 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005828 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 final long identity = Binder.clearCallingIdentity();
5830 try {
5831 Phone phone = getPhone(subId);
5832 if (phone != null) {
5833 return phone.isVideoEnabled();
5834 } else {
5835 return false;
5836 }
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005839 }
5840 }
5841
5842 /**
5843 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5844 * defined in {@link ImsRegistrationImplBase}.
5845 */
5846 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 Phone phone = getPhone(subId);
5850 if (phone != null) {
5851 return phone.getImsRegistrationTech();
5852 } else {
5853 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005857 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005858 }
5859
Stuart Scott8eef64f2015-04-08 15:13:54 -07005860 @Override
5861 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005862 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005863 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5864 return;
5865 }
5866
Svet Ganovcc087f82015-05-12 20:35:54 -07005867 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005868
Svet Ganovcc087f82015-05-12 20:35:54 -07005869 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005870 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5871 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005872 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005873 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005874 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005875 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5876 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005877 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005878 // There has been issues when Sms raw table somehow stores orphan
5879 // fragments. They lead to garbled message when new fragments come
5880 // in and combined with those stale ones. In case this happens again,
5881 // user can reset all network settings which will clean up this table.
5882 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005883 // Clean up IMS settings as well here.
5884 int slotId = getSlotIndex(subId);
5885 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5886 ImsManager.getInstance(mApp, slotId).factoryReset();
5887 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005888
5889 // Erase modem config if erase modem on network setting is enabled.
5890 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5891 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5892 if (configValue != null && Boolean.parseBoolean(configValue)) {
5893 sendEraseModemConfig(getDefaultPhone());
5894 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005897 }
5898 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005899
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005900 private void cleanUpSmsRawTable(Context context) {
5901 ContentResolver resolver = context.getContentResolver();
5902 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5903 resolver.delete(uri, null, null);
5904 }
5905
Narayan Kamath1c496c22015-04-16 14:40:19 +01005906 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005907 public String getSimLocaleForSubscriber(int subId) {
5908 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5909 final Phone phone = getPhone(subId);
5910 if (phone == null) {
5911 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005912 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
chen xu5d3637b2019-01-21 23:31:38 -08005916 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5917 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005918 if (info == null) {
5919 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5920 return null;
5921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 // Try and fetch the locale from the carrier properties or from the SIM language
5923 // preferences (EF-PL and EF-LI)...
5924 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005926 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5927 if (localeFromDefaultSim != null) {
5928 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5929 if (DBG) log("Using locale from subId: " + subId + " locale: "
5930 + localeFromDefaultSim);
5931 return localeFromDefaultSim.toLanguageTag();
5932 } else {
5933 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 }
5935 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 // The SIM language preferences only store a language (e.g. fr = French), not an
5938 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5939 // the SIM and carrier preferences does not include a country we add the country
5940 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08005941 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005943 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 return mccLocale.toLanguageTag();
5945 }
5946
5947 if (DBG) log("No locale found - returning null");
5948 return null;
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005952 }
5953
5954 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005955 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005956 }
5957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 /**
5959 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5960 */
5961 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005962 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005963 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005964
Chenjie Yu1ba97252018-01-11 18:16:20 -08005965 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07005966 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005967
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005968 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005969 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5970 * representing the state of the modem.
5971 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005972 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5973 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005974 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005975 */
5976 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005977 public void requestModemActivityInfo(ResultReceiver result) {
5978 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
5983 ModemActivityInfo ret = null;
5984 synchronized (mLastModemActivityInfo) {
5985 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5986 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005987 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005988 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07005990 int[] txTimeMs = info.getTransmitTimeMillis();
5991 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07005993 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 }
5995 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005996 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5997 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 mLastModemActivityInfo.setIdleTimeMillis(
5999 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006000 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6001 mLastModemActivityInfo.setReceiveTimeMillis(
6002 info.getReceiveTimeMillis() + mLastModemActivityInfo
6003 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006004 }
Chen Xu13851032019-09-10 18:49:52 -07006005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6007 mLastModemActivityInfo.getSleepTimeMillis(),
6008 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006009 mLastModemActivityInfo.getTransmitTimeMillis(),
6010 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 Bundle bundle = new Bundle();
6013 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6014 result.send(0, bundle);
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006017 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006018 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006019
Siddharth Rayb8114062018-06-17 15:02:38 -07006020 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6021 // less than total activity duration.
6022 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6023 if (info == null) {
6024 return false;
6025 }
6026 int activityDurationMs =
6027 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6028 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006029 int[] txTimeMs = info.getTransmitTimeMillis();
6030 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6031 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006032 }
6033 return (info.isValid()
6034 && (info.getSleepTimeMillis() <= activityDurationMs)
6035 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006036 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006037 && (totalTxTimeMs <= activityDurationMs));
6038 }
6039
Jack Yu85bd38a2015-11-09 11:34:32 -08006040 /**
6041 * {@hide}
6042 * Returns the service state information on specified subscription.
6043 */
6044 @Override
6045 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006047 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006048 return null;
6049 }
6050
Hall Liuf19c44f2018-11-27 14:38:17 -08006051 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6052 LocationAccessPolicy.checkLocationPermission(mApp,
6053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6054 .setCallingPackage(callingPackage)
6055 .setCallingPid(Binder.getCallingPid())
6056 .setCallingUid(Binder.getCallingUid())
6057 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006058 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6060 .build());
6061
6062 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6063 LocationAccessPolicy.checkLocationPermission(mApp,
6064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6065 .setCallingPackage(callingPackage)
6066 .setCallingPid(Binder.getCallingPid())
6067 .setCallingUid(Binder.getCallingUid())
6068 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006069 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006070 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6071 .build());
6072 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6073 boolean hasFinePermission =
6074 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6075 boolean hasCoarsePermission =
6076 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 final Phone phone = getPhone(subId);
6081 if (phone == null) {
6082 return null;
6083 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006084
Hall Liuf19c44f2018-11-27 14:38:17 -08006085 ServiceState ss = phone.getServiceState();
6086
6087 // Scrub out the location info in ServiceState depending on what level of access
6088 // the caller has.
6089 if (hasFinePermission) return ss;
6090 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6091 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006095 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006096
6097 /**
6098 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6099 *
6100 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6101 * voicemail ringtone.
6102 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6103 * PhoneAccount.
6104 */
6105 @Override
6106 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6110 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006111 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006118 }
6119
6120 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006121 * Sets the per-account voicemail ringtone.
6122 *
6123 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6124 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6125 *
6126 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6127 * voicemail ringtone.
6128 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6129 * PhoneAccount.
6130 */
6131 @Override
6132 public void setVoicemailRingtoneUri(String callingPackage,
6133 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006136 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6137 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6139 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6140 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142
6143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6146 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 }
6149 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006152 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006153 }
6154
6155 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006156 * Returns whether vibration is set for voicemail notification in Phone settings.
6157 *
6158 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6159 * voicemail vibration setting.
6160 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6161 */
6162 @Override
6163 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6167 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006168 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006175 }
6176
Youhan Wange64578a2016-05-02 15:32:42 -07006177 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006178 * Sets the per-account voicemail vibration.
6179 *
6180 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6181 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6182 *
6183 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6184 * voicemail vibration setting.
6185 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6186 * specific PhoneAccount.
6187 */
6188 @Override
6189 public void setVoicemailVibrationEnabled(String callingPackage,
6190 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006191 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006193 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6194 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6196 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6197 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006198 }
6199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6203 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006204 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 }
6206 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006209 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 }
6211
6212 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006213 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6214 *
6215 * @throws SecurityException if the caller does not have the required permission
6216 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006217 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006219 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006220 }
6221
6222 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006223 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6224 * permission.
6225 *
6226 * @throws SecurityException if the caller does not have the required permission
6227 */
6228 private void enforceSendSmsPermission() {
6229 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6230 }
6231
6232 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006233 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006234 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006235 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006236 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006237 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006241 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 if (componentName == null) {
6243 throw new SecurityException(
6244 "Caller not current active visual voicemail package[null]");
6245 }
6246 String vvmPackage = componentName.getPackageName();
6247 if (!callingPackage.equals(vvmPackage)) {
6248 throw new SecurityException("Caller not current active visual voicemail package["
6249 + vvmPackage + "]");
6250 }
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006253 }
6254 }
6255
6256 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006257 * Return the application ID for the app type.
6258 *
6259 * @param subId the subscription ID that this request applies to.
6260 * @param appType the uicc app type.
6261 * @return Application ID for specificied app type, or null if no uicc.
6262 */
6263 @Override
6264 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006265 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006266 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006269 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 if (phone == null) {
6271 return null;
6272 }
6273 String aid = null;
6274 try {
6275 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6276 .getApplicationByType(appType).getAid();
6277 } catch (Exception e) {
6278 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6279 }
6280 return aid;
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006283 }
Youhan Wange64578a2016-05-02 15:32:42 -07006284 }
6285
Youhan Wang4001d252016-05-11 10:29:41 -07006286 /**
6287 * Return the Electronic Serial Number.
6288 *
6289 * @param subId the subscription ID that this request applies to.
6290 * @return ESN or null if error.
6291 */
6292 @Override
6293 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006294 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006295 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296
6297 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006298 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 if (phone == null) {
6300 return null;
6301 }
6302 String esn = null;
6303 try {
6304 esn = phone.getEsn();
6305 } catch (Exception e) {
6306 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6307 }
6308 return esn;
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006311 }
Youhan Wang4001d252016-05-11 10:29:41 -07006312 }
6313
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006314 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006315 * Return the Preferred Roaming List Version.
6316 *
6317 * @param subId the subscription ID that this request applies to.
6318 * @return PRLVersion or null if error.
6319 */
6320 @Override
6321 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006322 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006323 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324
6325 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006326 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 if (phone == null) {
6328 return null;
6329 }
6330 String cdmaPrlVersion = null;
6331 try {
6332 cdmaPrlVersion = phone.getCdmaPrlVersion();
6333 } catch (Exception e) {
6334 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6335 }
6336 return cdmaPrlVersion;
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006339 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006340 }
6341
6342 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006343 * Get snapshot of Telephony histograms
6344 * @return List of Telephony histograms
6345 * @hide
6346 */
6347 @Override
6348 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 return RIL.getTelephonyRILTimingHistograms();
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006358 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006359
6360 /**
6361 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006362 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6363 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006364 * Require system privileges. In the future we may add this to carrier APIs.
6365 *
Michele Berionne482f8202018-11-27 18:57:59 -08006366 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006367 */
6368 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006369 @TelephonyManager.SetCarrierRestrictionResult
6370 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006371 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006373
Michele Berionne482f8202018-11-27 18:57:59 -08006374 if (carrierRestrictionRules == null) {
6375 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006376 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006380 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006381 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006385 }
6386
6387 /**
6388 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006389 * Get the allowed carrier list and the excluded carrier list, including the priority between
6390 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006391 * Require system privileges. In the future we may add this to carrier APIs.
6392 *
Michele Berionne482f8202018-11-27 18:57:59 -08006393 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006394 */
6395 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006396 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006397 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006398 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006402 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6403 if (response instanceof CarrierRestrictionRules) {
6404 return (CarrierRestrictionRules) response;
6405 }
6406 // Response is an Exception of some kind,
6407 // which is signalled to the user as a NULL retval
6408 return null;
6409 } catch (Exception e) {
6410 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6411 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006415 }
6416
fionaxu59545b42016-05-25 15:53:37 -07006417 /**
6418 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6419 * @param subId the subscription ID that this action applies to.
6420 * @param enabled control enable or disable metered apns.
6421 * {@hide}
6422 */
6423 @Override
6424 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6425 enforceModifyPermission();
6426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
6428 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006429 if (phone == null) {
6430 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6431 return;
6432 }
6433 try {
6434 phone.carrierActionSetMeteredApnsEnabled(enabled);
6435 } catch (Exception e) {
6436 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006439 }
6440 }
6441
6442 /**
6443 * Action set from carrier signalling broadcast receivers to enable/disable radio
6444 * @param subId the subscription ID that this action applies to.
6445 * @param enabled control enable or disable radio.
6446 * {@hide}
6447 */
6448 @Override
6449 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6450 enforceModifyPermission();
6451 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452
6453 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006454 if (phone == null) {
6455 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6456 return;
6457 }
6458 try {
6459 phone.carrierActionSetRadioEnabled(enabled);
6460 } catch (Exception e) {
6461 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006464 }
6465 }
6466
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006467 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006468 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6469 * network status based on which carrier apps could apply actions accordingly,
6470 * enable/disable default url handler for example.
6471 *
6472 * @param subId the subscription ID that this action applies to.
6473 * @param report control start/stop reporting the default network status.
6474 * {@hide}
6475 */
6476 @Override
6477 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6478 enforceModifyPermission();
6479 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480
6481 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006482 if (phone == null) {
6483 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6484 return;
6485 }
6486 try {
6487 phone.carrierActionReportDefaultNetworkStatus(report);
6488 } catch (Exception e) {
6489 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006492 }
6493 }
6494
6495 /**
fionaxud9622282017-07-17 17:51:30 -07006496 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6497 * @param subId the subscription ID that this action applies to.
6498 * {@hide}
6499 */
6500 @Override
6501 public void carrierActionResetAll(int subId) {
6502 enforceModifyPermission();
6503 final Phone phone = getPhone(subId);
6504 if (phone == null) {
6505 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6506 return;
6507 }
6508 try {
6509 phone.carrierActionResetAll();
6510 } catch (Exception e) {
6511 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6512 }
6513 }
6514
6515 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006516 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6517 * bug report is being generated.
6518 */
6519 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006520 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6522 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006523 writer.println("Permission Denial: can't dump Phone from pid="
6524 + Binder.getCallingPid()
6525 + ", uid=" + Binder.getCallingUid()
6526 + "without permission "
6527 + android.Manifest.permission.DUMP);
6528 return;
6529 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006531 }
Jack Yueb89b242016-06-22 13:27:47 -07006532
Brad Ebingerdac2f002018-04-03 15:17:52 -07006533 @Override
6534 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6535 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6536 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006537 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6538 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006539 }
6540
Jack Yueb89b242016-06-22 13:27:47 -07006541 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006542 * Get aggregated video call data usage since boot.
6543 *
6544 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6545 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006546 * {@hide}
6547 */
6548 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006549 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006550 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6551 null);
6552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 final long identity = Binder.clearCallingIdentity();
6554 try {
6555 // NetworkStatsService keeps tracking the active network interface and identity. It
6556 // records the delta with the corresponding network identity.
6557 // We just return the total video call data usage snapshot since boot.
6558 Phone phone = getPhone(subId);
6559 if (phone != null) {
6560 return phone.getVtDataUsage(perUidStats);
6561 }
6562 return null;
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006565 }
Jack Yueb89b242016-06-22 13:27:47 -07006566 }
Jack Yu75ab2952016-07-08 14:29:33 -07006567
6568 /**
6569 * Policy control of data connection. Usually used when data limit is passed.
6570 * @param enabled True if enabling the data, otherwise disabling.
6571 * @param subId Subscription index
6572 * {@hide}
6573 */
6574 @Override
6575 public void setPolicyDataEnabled(boolean enabled, int subId) {
6576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 Phone phone = getPhone(subId);
6581 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006582 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 }
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006586 }
6587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006588
6589 /**
6590 * Get Client request stats
6591 * @return List of Client Request Stats
6592 * @hide
6593 */
6594 @Override
6595 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006597 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006598 return null;
6599 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006600 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 if (phone != null) {
6605 return phone.getClientRequestStats();
6606 }
6607
6608 return null;
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006612 }
6613
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006614 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006616 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006617 }
Jack Yueb4124c2017-02-16 15:32:43 -08006618
6619 /**
Grace Chen70990072017-03-24 17:21:30 -07006620 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006621 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006622 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006623 * @param state State of SIM (power down, power up, pass through)
6624 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6625 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6626 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006627 *
6628 **/
6629 @Override
Grace Chen70990072017-03-24 17:21:30 -07006630 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006631 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006632 Phone phone = PhoneFactory.getPhone(slotIndex);
6633
vagdeviaf9a5b92018-08-15 16:01:53 -07006634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006639 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 }
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006643 }
6644 }
Shuo Qiandd210312017-04-12 22:11:33 +00006645
Tyler Gunn65d45c22017-06-05 11:22:26 -07006646 private boolean isUssdApiAllowed(int subId) {
6647 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006648 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006649 if (configManager == null) {
6650 return false;
6651 }
6652 PersistableBundle pb = configManager.getConfigForSubId(subId);
6653 if (pb == null) {
6654 return false;
6655 }
6656 return pb.getBoolean(
6657 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6658 }
6659
Shuo Qiandd210312017-04-12 22:11:33 +00006660 /**
6661 * Check if phone is in emergency callback mode
6662 * @return true if phone is in emergency callback mode
6663 * @param subId sub id
6664 */
goneil9c5f4872017-12-05 14:07:56 -08006665 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006666 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006667 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006668 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 if (phone != null) {
6673 return phone.isInEcm();
6674 } else {
6675 return false;
6676 }
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006679 }
6680 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006681
6682 /**
6683 * Get the current signal strength information for the given subscription.
6684 * Because this information is not updated when the device is in a low power state
6685 * it should not be relied-upon to be current.
6686 * @param subId Subscription index
6687 * @return the most recent cached signal strength info from the modem
6688 */
6689 @Override
6690 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 Phone p = getPhone(subId);
6694 if (p == null) {
6695 return null;
6696 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 return p.getSignalStrength();
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006702 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006703
Pengquan Meng77b7f132018-08-22 14:49:57 -07006704 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006705 * Get the current modem radio state for the given slot.
6706 * @param slotIndex slot index.
6707 * @param callingPackage the name of the package making the call.
6708 * @return the current radio power state from the modem
6709 */
6710 @Override
6711 public int getRadioPowerState(int slotIndex, String callingPackage) {
6712 Phone phone = PhoneFactory.getPhone(slotIndex);
6713 if (phone != null) {
6714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6715 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6716 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6717 }
6718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 return phone.getRadioPowerState();
6722 } finally {
6723 Binder.restoreCallingIdentity(identity);
6724 }
6725 }
6726 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6727 }
6728
6729 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006730 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6731 *
6732 * <p>Requires one of the following permissions:
6733 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6734 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6735 * privileges.
6736 *
6737 * @param subId subscription id
6738 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6739 * {@code false}.
6740 */
6741 @Override
6742 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006743 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6744 null /* message */);
6745
Pengquan Menga1bb6272018-09-06 09:59:22 -07006746 boolean isEnabled = false;
6747 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006748 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006749 Phone phone = getPhone(subId);
6750 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 } catch (Exception e) {
6752 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6753 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006754 } finally {
6755 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006757 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006758 }
6759
6760
6761 /**
6762 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6763 *
6764 * <p> Requires permission:
6765 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6766 * privileges.
6767 *
6768 * @param subId subscription id
6769 * @param isEnabled {@code true} means enable, {@code false} means disable.
6770 */
6771 @Override
6772 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6774 mApp, subId, "setDataRoamingEnabled");
6775
Pengquan Menga1bb6272018-09-06 09:59:22 -07006776 final long identity = Binder.clearCallingIdentity();
6777 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006778 Phone phone = getPhone(subId);
6779 if (phone != null) {
6780 phone.setDataRoamingEnabled(isEnabled);
6781 }
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006784 }
6785 }
6786
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006787 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006788 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006789 TelephonyPermissions
6790 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006791 mApp, subId, "isManualNetworkSelectionAllowed");
6792
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006793 boolean isAllowed = true;
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006796 Phone phone = getPhone(subId);
6797 if (phone != null) {
6798 isAllowed = phone.isCspPlmnEnabled();
6799 }
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 return isAllowed;
6804 }
6805
6806 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006807 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006808 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006809 try {
6810 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006811 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006812 } catch (SecurityException e) {
6813 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6814 // has carrier privileges on an active UICC
6815 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6816 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006817 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006818 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006819 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006820
6821 final long identity = Binder.clearCallingIdentity();
6822 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006823 UiccController uiccController = UiccController.getInstance();
6824 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006825 if (hasReadPermission) {
6826 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006827 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006828
6829 // Remove private info if the caller doesn't have access
6830 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6831 for (UiccCardInfo cardInfo : cardInfos) {
6832 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6833 // is available
6834 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6835 if (card == null || card.getUiccProfile() == null) {
6836 // assume no access if the card or profile is unavailable
6837 filteredInfos.add(cardInfo.getUnprivileged());
6838 continue;
6839 }
6840 UiccProfile profile = card.getUiccProfile();
6841 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6842 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6843 filteredInfos.add(cardInfo);
6844 } else {
6845 filteredInfos.add(cardInfo.getUnprivileged());
6846 }
6847 }
6848 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006849 } finally {
6850 Binder.restoreCallingIdentity(identity);
6851 }
6852 }
6853
6854 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006855 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006856 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6861 if (slots == null) {
6862 Rlog.i(LOG_TAG, "slots is null.");
6863 return null;
6864 }
6865
6866 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6867 for (int i = 0; i < slots.length; i++) {
6868 UiccSlot slot = slots[i];
6869 if (slot == null) {
6870 continue;
6871 }
6872
Jordan Liu7be7e652019-05-06 18:55:02 +00006873 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 UiccCard card = slot.getUiccCard();
6875 if (card != null) {
6876 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006877 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006878 cardId = slot.getEid();
6879 if (TextUtils.isEmpty(cardId)) {
6880 cardId = slot.getIccId();
6881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 }
6883
Jordan Liu857451f2019-05-09 16:35:35 -07006884 if (cardId != null) {
6885 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6886 // if cardId is an EID, it's all digits so this is fine
6887 cardId = IccUtils.stripTrailingFs(cardId);
6888 }
6889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 int cardState = 0;
6891 switch (slot.getCardState()) {
6892 case CARDSTATE_ABSENT:
6893 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6894 break;
6895 case CARDSTATE_PRESENT:
6896 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6897 break;
6898 case CARDSTATE_ERROR:
6899 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6900 break;
6901 case CARDSTATE_RESTRICTED:
6902 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6903 break;
6904 default:
6905 break;
6906
6907 }
6908
6909 infos[i] = new UiccSlotInfo(
6910 slot.isActive(),
6911 slot.isEuicc(),
6912 cardId,
6913 cardState,
6914 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006915 slot.isExtendedApduSupported(),
6916 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 }
6918 return infos;
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006921 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006922 }
6923
6924 @Override
6925 public boolean switchSlots(int[] physicalSlots) {
6926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006934 }
Jack Yu4c988042018-02-27 15:30:01 -08006935
6936 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006937 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006938 final long identity = Binder.clearCallingIdentity();
6939 try {
6940 return UiccController.getInstance().getCardIdForDefaultEuicc();
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
6943 }
6944 }
6945
6946 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006947 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6948 enforceModifyPermission();
6949 final Phone phone = getPhone(subId);
6950 if (phone == null) {
6951 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6952 return;
6953 }
6954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 phone.setRadioIndicationUpdateMode(filters, mode);
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
Jack Yu4c988042018-02-27 15:30:01 -08006961 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006962
6963 /**
goneil47ffb6e2018-04-06 15:40:58 -07006964 * A test API to reload the UICC profile.
6965 *
6966 * <p>Requires that the calling app has permission
6967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6968 * @hide
6969 */
6970 @Override
6971 public void refreshUiccProfile(int subId) {
6972 enforceModifyPermission();
6973
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
6976 Phone phone = getPhone(subId);
6977 if (phone == null) {
6978 return;
6979 }
6980 UiccCard uiccCard = phone.getUiccCard();
6981 if (uiccCard == null) {
6982 return;
6983 }
6984 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6985 if (uiccProfile == null) {
6986 return;
6987 }
6988 uiccProfile.refresh();
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
6992 }
6993
6994 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006995 * Returns false if the mobile data is disabled by default, otherwise return true.
6996 */
6997 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09006998 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006999 }
7000
7001 /**
7002 * Returns true if the data roaming is enabled by default, i.e the system property
7003 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7004 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7005 */
7006 private boolean getDefaultDataRoamingEnabled(int subId) {
7007 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007008 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007009 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007010 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7011 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7012 return isDataRoamingEnabled;
7013 }
7014
7015 /**
7016 * Returns the default network type for the given {@code subId}, if the default network type is
7017 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7018 */
7019 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007020 List<Integer> list = TelephonyProperties.default_network();
7021 int phoneId = mSubscriptionController.getPhoneId(subId);
7022 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7023 return list.get(phoneId);
7024 }
7025 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007026 }
fionaxua13278b2018-03-21 00:08:13 -07007027
7028 @Override
7029 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007030 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 final Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7038 return;
7039 }
chen xueaba88a2019-03-15 13:15:10 -07007040 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7041 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 } finally {
7043 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007044 }
fionaxua13278b2018-03-21 00:08:13 -07007045 }
7046
7047 @Override
7048 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007049 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 final Phone phone = getPhone(subId);
7054 if (phone == null) {
7055 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7056 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7057 }
7058 return phone.getCarrierIdListVersion();
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007061 }
fionaxua13278b2018-03-21 00:08:13 -07007062 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007063
7064 @Override
7065 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7067 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7068 return -1;
7069 }
7070
7071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076 }
7077 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007078
7079 @Override
7080 public int getCdmaRoamingMode(int subId) {
7081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7082 mApp, subId, "getCdmaRoamingMode");
7083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
7090 }
7091
7092 @Override
7093 public boolean setCdmaRoamingMode(int subId, int mode) {
7094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7095 mApp, subId, "setCdmaRoamingMode");
7096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
7103 }
7104
7105 @Override
7106 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7108 mApp, subId, "setCdmaSubscriptionMode");
7109
7110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007117
sqianc5eccab2018-10-19 18:46:41 -07007118 @Override
sqian8c685422019-02-22 15:55:18 -08007119 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007120 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007122 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007123 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7124 }
7125 final long identity = Binder.clearCallingIdentity();
7126 try {
sqian854d44b2018-12-12 16:48:18 -08007127 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7128 for (Phone phone: PhoneFactory.getPhones()) {
7129 if (phone.getEmergencyNumberTracker() != null
7130 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7131 emergencyNumberListInternal.put(
7132 phone.getSubId(),
7133 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7134 }
sqian11b7a0e2018-12-05 18:48:28 -08007135 }
sqian854d44b2018-12-12 16:48:18 -08007136 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
sqianc5eccab2018-10-19 18:46:41 -07007140 }
7141
7142 @Override
sqian8c685422019-02-22 15:55:18 -08007143 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007145 if (!exactMatch) {
7146 TelephonyPermissions
7147 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007148 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007149 }
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
sqian854d44b2018-12-12 16:48:18 -08007152 for (Phone phone: PhoneFactory.getPhones()) {
7153 if (phone.getEmergencyNumberTracker() != null
7154 && phone.getEmergencyNumberTracker() != null) {
7155 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7156 number, exactMatch)) {
7157 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007158 }
7159 }
sqian11b7a0e2018-12-05 18:48:28 -08007160 }
7161 return false;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
sqianf4ca7ed2019-01-15 18:32:07 -08007167 /**
7168 * Update emergency number list for test mode.
7169 */
7170 @Override
7171 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7173 "updateEmergencyNumberListTestMode");
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 for (Phone phone: PhoneFactory.getPhones()) {
7178 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7179 if (tracker != null) {
7180 tracker.executeEmergencyNumberTestModeCommand(action, num);
7181 }
7182 }
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
7187
7188 /**
7189 * Get the full emergency number list for test mode.
7190 */
7191 @Override
7192 public List<String> getEmergencyNumberListTestMode() {
7193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7194 "getEmergencyNumberListTestMode");
7195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 Set<String> emergencyNumbers = new HashSet<>();
7199 for (Phone phone: PhoneFactory.getPhones()) {
7200 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7201 if (tracker != null) {
7202 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7203 emergencyNumbers.add(num.getNumber());
7204 }
7205 }
7206 }
7207 return new ArrayList<>(emergencyNumbers);
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
7211 }
7212
chen xud6b45bd2018-10-30 22:27:10 -07007213 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007214 public int getEmergencyNumberDbVersion(int subId) {
7215 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 final Phone phone = getPhone(subId);
7220 if (phone == null) {
7221 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7222 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7223 }
7224 return phone.getEmergencyNumberDbVersion();
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
7228 }
7229
7230 @Override
7231 public void notifyOtaEmergencyNumberDbInstalled() {
7232 enforceModifyPermission();
7233
7234 final long identity = Binder.clearCallingIdentity();
7235 try {
7236 for (Phone phone: PhoneFactory.getPhones()) {
7237 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7238 if (tracker != null) {
7239 tracker.updateOtaEmergencyNumberDatabase();
7240 }
7241 }
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
7246
7247 @Override
7248 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7249 enforceActiveEmergencySessionPermission();
7250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 for (Phone phone: PhoneFactory.getPhones()) {
7254 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7255 if (tracker != null) {
7256 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7257 }
7258 }
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
7262 }
7263
7264 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007265 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7266 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7267 Phone phone = getPhone(subId);
7268 if (phone == null) {
7269 return null;
7270 }
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 UiccProfile profile = UiccController.getInstance()
7274 .getUiccProfileForPhone(phone.getPhoneId());
7275 if (profile != null) {
7276 return profile.getCertsFromCarrierPrivilegeAccessRules();
7277 }
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 return null;
7282 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007283
7284 /**
7285 * Enable or disable a modem stack.
7286 */
7287 @Override
7288 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7289 enforceModifyPermission();
7290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 Phone phone = PhoneFactory.getPhone(slotIndex);
7294 if (phone == null) {
7295 return false;
7296 } else {
7297 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7298 }
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 }
Michelecea4cf22018-12-21 15:00:11 -08007303
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007304 /**
7305 * Whether a modem stack is enabled or not.
7306 */
7307 @Override
7308 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7309 Phone phone = PhoneFactory.getPhone(slotIndex);
7310 if (phone == null) return false;
7311
7312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7313 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7314 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7315 }
7316
7317 final long identity = Binder.clearCallingIdentity();
7318 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007319 try {
7320 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7321 } catch (NoSuchElementException ex) {
7322 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7323 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
7327 }
7328
Michelecea4cf22018-12-21 15:00:11 -08007329 @Override
Michele0ea7d782019-03-19 14:58:42 -07007330 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007331 enforceModifyPermission();
7332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007336 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007337 .commit();
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
7341 }
7342
7343 @Override
Michele0ea7d782019-03-19 14:58:42 -07007344 @TelephonyManager.IsMultiSimSupportedResult
7345 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007347 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007349 }
Michelecea4cf22018-12-21 15:00:11 -08007350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
Michele0ea7d782019-03-19 14:58:42 -07007353 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
7357 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007358
Michele0ea7d782019-03-19 14:58:42 -07007359 @TelephonyManager.IsMultiSimSupportedResult
7360 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007361 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7362 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7363 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007364 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7365 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007366 }
7367 // Check if the hardware supports multisim functionality. If usage of multisim is not
7368 // supported by the modem, indicate that it is restricted.
7369 PhoneCapability staticCapability =
7370 mPhoneConfigurationManager.getStaticPhoneCapability();
7371 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007372 loge("isMultiSimSupportedInternal: no static configuration available");
7373 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007374 }
7375 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007376 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7377 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007378 }
7379 // Check if support of multiple SIMs is restricted by carrier
7380 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007381 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007382 }
7383
Michele0ea7d782019-03-19 14:58:42 -07007384 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007385 }
7386
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007387 /**
7388 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007389 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7390 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7391 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007392 * @param numOfSims number of active sims we want to switch to
7393 */
7394 @Override
7395 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007396 if (numOfSims == 1) {
7397 enforceModifyPermission();
7398 } else {
7399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7400 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7401 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007402 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007403
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007404 try {
Michele30b57b22019-03-01 12:01:14 -08007405 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007406 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007407 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7408 return;
7409 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007410 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007416 @Override
7417 public boolean isApplicationOnUicc(int subId, int appType) {
7418 enforceReadPrivilegedPermission("isApplicationOnUicc");
7419 Phone phone = getPhone(subId);
7420 if (phone == null) {
7421 return false;
7422 }
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 UiccCard uiccCard = phone.getUiccCard();
7426 if (uiccCard == null) {
7427 return false;
7428 }
7429 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7430 if (uiccProfile == null) {
7431 return false;
7432 }
7433 if (TelephonyManager.APPTYPE_SIM <= appType
7434 && appType <= TelephonyManager.APPTYPE_ISIM) {
7435 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7436 }
7437 return false;
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007443 /**
chen xub4baa772019-04-03 10:23:41 -07007444 * Get whether making changes to modem configurations will trigger reboot.
7445 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007446 */
7447 @Override
chen xub4baa772019-04-03 10:23:41 -07007448 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7450 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7451 return false;
7452 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
7459 }
7460
Nathan Harold29f5f052019-02-15 13:41:57 -08007461 private void updateModemStateMetrics() {
7462 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7463 // TODO: check the state for each modem if the api is ready.
7464 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7465 }
7466
Pengquan Meng3889a572019-01-23 11:16:29 -08007467 @Override
7468 public int[] getSlotsMapping() {
7469 enforceReadPrivilegedPermission("getSlotsMapping");
7470
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7474 // All logical slots should have a mapping to a physical slot.
7475 int[] logicalSlotsMapping = new int[phoneCount];
7476 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7477 for (int i = 0; i < slotInfos.length; i++) {
7478 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7479 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7480 }
7481 }
7482 return logicalSlotsMapping;
7483 } finally {
7484 Binder.restoreCallingIdentity(identity);
7485 }
7486 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007487
7488 /**
7489 * Get the IRadio HAL Version
7490 */
7491 @Override
7492 public int getRadioHalVersion() {
7493 Phone phone = getDefaultPhone();
7494 if (phone == null) return -1;
7495 HalVersion hv = phone.getHalVersion();
7496 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7497 return hv.major * 100 + hv.minor;
7498 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007499
7500 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007501 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7502 * corresponding network requests on a subId.
7503 *
7504 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007505 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007506 * 2) APN is un-metered for this subscription, or
7507 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7508 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7509 *
7510 * @return whether data is allowed for a apn type.
7511 *
7512 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007513 */
7514 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007515 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007516 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7517 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007518
7519 // Now that all security checks passes, perform the operation as ourselves.
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 Phone phone = getPhone(subId);
7523 if (phone == null) return false;
7524
Jack Yu41407ee2019-05-13 16:54:09 -07007525 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007526 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 }
7531
7532 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007533 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007534 enforceReadPrivilegedPermission("isApnMetered");
7535
7536 // Now that all security checks passes, perform the operation as ourselves.
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 Phone phone = getPhone(subId);
7540 if (phone == null) return true; // By default return true.
7541
Jack Yu41407ee2019-05-13 16:54:09 -07007542 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
7546 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007547
7548 @Override
7549 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7550 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7551 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7552 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7553 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7554 }
7555 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7556 Intent intent = new Intent();
7557 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7558 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7559 // Bring up choose default SMS subscription dialog right now
7560 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7561 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7562 mApp.startActivity(intent);
7563 }
chen xud5ca2d52019-05-28 15:20:57 -07007564
7565 @Override
7566 public String getMmsUAProfUrl(int subId) {
7567 //TODO investigate if this API should require proper permission check in R b/133791609
7568 final long identity = Binder.clearCallingIdentity();
7569 try {
7570 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7571 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
7576
7577 @Override
7578 public String getMmsUserAgent(int subId) {
7579 //TODO investigate if this API should require proper permission check in R b/133791609
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7583 .getString(com.android.internal.R.string.config_mms_user_agent);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
Jack Yub07d4972019-05-28 16:12:25 -07007588
7589 @Override
7590 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7591 enforceModifyPermission();
7592
7593 // Now that all security checks passes, perform the operation as ourselves.
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 Phone phone = getPhone(subId);
7597 if (phone == null) return false;
7598
7599 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
7605 @Override
7606 public boolean isDataAllowedInVoiceCall(int subId) {
7607 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7608
7609 // Now that all security checks passes, perform the operation as ourselves.
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone == null) return false;
7614
7615 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007620
7621 /**
7622 * Updates whether conference event pacakge handling is enabled.
7623 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7624 * otherwise.
7625 */
7626 @Override
7627 public void setCepEnabled(boolean isCepEnabled) {
7628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7633 for (Phone phone : PhoneFactory.getPhones()) {
7634 Phone defaultPhone = phone.getImsPhone();
7635 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7636 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7637 ImsPhoneCallTracker imsPhoneCallTracker =
7638 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7639 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7640 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7641 + imsPhone.getMsisdn());
7642 }
7643 }
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007648}