blob: 01a2a2c0b74c5e88beeccb84f5ce0627ed2fc303 [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;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100136import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
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;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
880 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
1104 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1114 ? new CdmaCellLocation() : new GsmCellLocation();
1115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1394 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001395 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001396 mTelephonySharedPreferences =
1397 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001398 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001399 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 publish();
1402 }
1403
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001404 private Phone getDefaultPhone() {
1405 Phone thePhone = getPhone(getDefaultSubscription());
1406 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 private void publish() {
1410 if (DBG) log("publish: " + this);
1411
1412 ServiceManager.addService("phone", this);
1413 }
1414
Stuart Scott584921c2015-01-15 17:10:34 -08001415 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001416 if (request.phone != null) {
1417 return request.phone;
1418 } else {
1419 return getPhoneFromSubId(request.subId);
1420 }
1421 }
1422
1423 private Phone getPhoneFromSubId(int subId) {
1424 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1425 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001426 }
1427
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001428 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1429 Phone phone = getPhoneFromRequest(request);
1430 return phone == null ? null :
1431 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1432 }
1433
Wink Saville36469e72014-06-11 15:17:00 -07001434 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001436 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001439 private void sendEraseModemConfig(Phone phone) {
1440 if (phone != null) {
1441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1442 mApp, phone.getSubId(), "eraseModemConfig");
1443 final long identity = Binder.clearCallingIdentity();
1444 try {
1445 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1446 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1447 } finally {
1448 Binder.restoreCallingIdentity(identity);
1449 }
1450 }
1451 }
1452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("dial: " + number);
1459 // No permission check needed here: This is just a wrapper around the
1460 // ACTION_DIAL intent, which is available to any app since it puts up
1461 // the UI before it does anything.
1462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001463 final long identity = Binder.clearCallingIdentity();
1464 try {
1465 String url = createTelUrl(number);
1466 if (url == null) {
1467 return;
1468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 // PENDING: should we just silently fail if phone is offhook or ringing?
1471 PhoneConstants.State state = mCM.getState(subId);
1472 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1473 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1474 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1475 mApp.startActivity(intent);
1476 }
1477 } finally {
1478 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480 }
1481
1482 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 if (DBG) log("call: " + number);
1488
1489 // This is just a wrapper around the ACTION_CALL intent, but we still
1490 // need to do a permission check since we're calling startActivity()
1491 // from the context of the phone app.
1492 enforceCallPermission();
1493
Jordan Liu1617b712019-07-10 15:06:26 -07001494 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 != AppOpsManager.MODE_ALLOWED) {
1496 return;
1497 }
1498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001499 final long identity = Binder.clearCallingIdentity();
1500 try {
1501 String url = createTelUrl(number);
1502 if (url == null) {
1503 return;
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001506 boolean isValid = false;
1507 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1508 if (slist != null) {
1509 for (SubscriptionInfo subInfoRecord : slist) {
1510 if (subInfoRecord.getSubscriptionId() == subId) {
1511 isValid = true;
1512 break;
1513 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001514 }
Wink Saville08874612014-08-31 19:19:58 -07001515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001516 if (!isValid) {
1517 return;
1518 }
Wink Saville08874612014-08-31 19:19:58 -07001519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1521 intent.putExtra(SUBSCRIPTION_KEY, subId);
1522 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1523 mApp.startActivity(intent);
1524 } finally {
1525 Binder.restoreCallingIdentity(identity);
1526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001530 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
1538 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1545 }
1546
1547 /** {@hide} */
1548 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001554
1555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1558 checkSimPin.start();
1559 return checkSimPin.unlockSim(null, pin);
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville9de0f752013-10-22 19:04:03 -07001565 /** {@hide} */
1566 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001567 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001568 }
1569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1576 checkSimPuk.start();
1577 return checkSimPuk.unlockSim(puk, pin);
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
1580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
1583 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001584 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 * a synchronous one.
1586 */
1587 private static class UnlockSim extends Thread {
1588
1589 private final IccCard mSimCard;
1590
1591 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001592 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1593 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594
1595 // For replies from SimCard interface
1596 private Handler mHandler;
1597
1598 // For async handler to identify request type
1599 private static final int SUPPLY_PIN_COMPLETE = 100;
1600
1601 public UnlockSim(IccCard simCard) {
1602 mSimCard = simCard;
1603 }
1604
1605 @Override
1606 public void run() {
1607 Looper.prepare();
1608 synchronized (UnlockSim.this) {
1609 mHandler = new Handler() {
1610 @Override
1611 public void handleMessage(Message msg) {
1612 AsyncResult ar = (AsyncResult) msg.obj;
1613 switch (msg.what) {
1614 case SUPPLY_PIN_COMPLETE:
1615 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1616 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001617 mRetryCount = msg.arg1;
1618 if (ar.exception != null) {
1619 if (ar.exception instanceof CommandException &&
1620 ((CommandException)(ar.exception)).getCommandError()
1621 == CommandException.Error.PASSWORD_INCORRECT) {
1622 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1623 } else {
1624 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1625 }
1626 } else {
1627 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 mDone = true;
1630 UnlockSim.this.notifyAll();
1631 }
1632 break;
1633 }
1634 }
1635 };
1636 UnlockSim.this.notifyAll();
1637 }
1638 Looper.loop();
1639 }
1640
1641 /*
1642 * Use PIN or PUK to unlock SIM card
1643 *
1644 * If PUK is null, unlock SIM card with PIN
1645 *
1646 * If PUK is not null, unlock SIM card with PUK and set PIN code
1647 */
Wink Saville9de0f752013-10-22 19:04:03 -07001648 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649
1650 while (mHandler == null) {
1651 try {
1652 wait();
1653 } catch (InterruptedException e) {
1654 Thread.currentThread().interrupt();
1655 }
1656 }
1657 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1658
1659 if (puk == null) {
1660 mSimCard.supplyPin(pin, callback);
1661 } else {
1662 mSimCard.supplyPuk(puk, pin, callback);
1663 }
1664
1665 while (!mDone) {
1666 try {
1667 Log.d(LOG_TAG, "wait for done");
1668 wait();
1669 } catch (InterruptedException e) {
1670 // Restore the interrupted status
1671 Thread.currentThread().interrupt();
1672 }
1673 }
1674 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001675 int[] resultArray = new int[2];
1676 resultArray[0] = mResult;
1677 resultArray[1] = mRetryCount;
1678 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680 }
1681
1682 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001683 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001684
1685 }
1686
Wink Savilleb564aae2014-10-23 10:18:09 -07001687 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 // No permission check needed here: this call is harmless, and it's
1689 // needed for the ServiceState.requestStateUpdate() call (which is
1690 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.updateServiceLocation();
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public boolean isRadioOn(String callingPackage) {
1704 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001705 }
1706
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001707 @Override
1708 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001710 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
1777 /*
1778 * If any of the Radios are available, it will need to be
1779 * shutdown. So return true if any Radio is available.
1780 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1784 Phone phone = PhoneFactory.getPhone(i);
1785 if (phone != null && phone.isRadioAvailable()) return true;
1786 }
1787 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1788 return false;
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001791 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
1793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 enforceModifyPermission();
1797
1798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1801 logv("Shutting down Phone " + i);
1802 shutdownRadioUsingPhoneId(i);
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 }
1807 }
1808
1809 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 Phone phone = PhoneFactory.getPhone(phoneId);
1811 if (phone != null && phone.isRadioAvailable()) {
1812 phone.shutdownRadio();
1813 }
1814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001817 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001818
1819 final long identity = Binder.clearCallingIdentity();
1820 try {
1821 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1822 if (defaultPhone != null) {
1823 defaultPhone.setRadioPower(turnOn);
1824 return true;
1825 } else {
1826 loge("There's no default phone.");
1827 return false;
1828 }
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001831 }
Wink Saville36469e72014-06-11 15:17:00 -07001832 }
1833
Wink Savilleb564aae2014-10-23 10:18:09 -07001834 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 final Phone phone = getPhone(subId);
1840 if (phone != null) {
1841 phone.setRadioPower(turnOn);
1842 return true;
1843 } else {
1844 return false;
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Wink Saville36469e72014-06-11 15:17:00 -07001851 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 public boolean enableDataConnectivity() {
1854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855
1856 final long identity = Binder.clearCallingIdentity();
1857 try {
1858 int subId = mSubscriptionController.getDefaultDataSubId();
1859 final Phone phone = getPhone(subId);
1860 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001861 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 return true;
1863 } else {
1864 return false;
1865 }
1866 } finally {
1867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
Wink Saville36469e72014-06-11 15:17:00 -07001871 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 public boolean disableDataConnectivity() {
1874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001875
1876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 int subId = mSubscriptionController.getDefaultDataSubId();
1879 final Phone phone = getPhone(subId);
1880 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001881 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 return true;
1883 } else {
1884 return false;
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001892 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001897 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 } else {
1899 return false;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001907 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001908 }
1909
pkanwarae03a6b2016-11-06 20:37:09 -08001910 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911 enforceCallPermission();
1912
1913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1916 return;
1917 }
1918 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1919 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
pkanwar32d516d2016-10-14 19:37:38 -07001923 };
1924
Wink Savilleb564aae2014-10-23 10:18:09 -07001925 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1931 return false;
1932 }
1933 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001940 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001943 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 Phone phone = PhoneFactory.getPhone(slotIndex);
1947 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1948 PhoneConstantConversions.convertCallState(phone.getState());
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
1951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001955 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001956 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1957 }
1958
1959 @Override
1960 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001961 final long identity = Binder.clearCallingIdentity();
1962 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001963 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 if (phone != null) {
1965 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1966 } else {
1967 return PhoneConstantConversions.convertDataState(
1968 PhoneConstants.DataState.DISCONNECTED);
1969 }
1970 } finally {
1971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001976 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001977 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1978 }
1979
1980 @Override
1981 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982 final long identity = Binder.clearCallingIdentity();
1983 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001984 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 if (phone != null) {
1986 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1987 } else {
1988 return TelephonyManager.DATA_ACTIVITY_NONE;
1989 }
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
1995 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001996 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001997 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001998 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001999
2000 LocationAccessPolicy.LocationPermissionResult locationResult =
2001 LocationAccessPolicy.checkLocationPermission(mApp,
2002 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2003 .setCallingPackage(callingPackage)
2004 .setCallingPid(Binder.getCallingPid())
2005 .setCallingUid(Binder.getCallingUid())
2006 .setMethod("getCellLocation")
2007 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2008 .build());
2009 switch (locationResult) {
2010 case DENIED_HARD:
2011 throw new SecurityException("Not allowed to access cell location");
2012 case DENIED_SOFT:
2013 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
2015
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017 final long identity = Binder.clearCallingIdentity();
2018 try {
2019 if (DBG_LOC) log("getCellLocation: is active user");
2020 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002021 int subId = mSubscriptionController.getDefaultDataSubId();
2022 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2023 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 return data;
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2032 if (!TextUtils.isEmpty(callingPackage)) {
2033 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2035 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2036 return "";
2037 }
2038 }
2039
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002040 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2041 // registered cell info, so return a NULL country instead.
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002044 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2045 // Get default phone in this case.
2046 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2047 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002048 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002049 // Todo: fix this when we can get the actual cellular network info when the device
2050 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002051 if (TelephonyManager.NETWORK_TYPE_IWLAN
2052 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2053 return "";
2054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 Phone phone = PhoneFactory.getPhone(phoneId);
2056 if (phone != null) {
2057 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002058 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 if (sst != null) {
2060 LocaleTracker lt = sst.getLocaleTracker();
2061 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002062 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2063 return lt.getCurrentCountry();
2064 } else if (emergencyNumberTracker != null) {
2065 return emergencyNumberTracker.getEmergencyCountryIso();
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067 }
2068 }
2069 }
2070 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002074 }
2075
2076 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002078 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002079 }
2080
Sanket Padawe356d7632015-06-22 14:03:32 -07002081 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002082 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 mApp.enforceCallingOrSelfPermission(
2084 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002085
2086 final long identity = Binder.clearCallingIdentity();
2087 try {
2088 final Phone phone = getPhone(subId);
2089 if (phone != null) {
2090 phone.enableLocationUpdates();
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
2097 @Override
2098 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002099 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002100 }
2101
Sanket Padawe356d7632015-06-22 14:03:32 -07002102 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002103 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 mApp.enforceCallingOrSelfPermission(
2105 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 final Phone phone = getPhone(subId);
2110 if (phone != null) {
2111 phone.disableLocationUpdates();
2112 }
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 }
2117
Nathan Harold31d7ff32018-10-15 20:20:30 -07002118 /**
2119 * Returns the target SDK version number for a given package name.
2120 *
Nathan Haroldec184742019-07-10 17:04:16 -07002121 * This call MUST be invoked before clearing the calling UID.
2122 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002123 * @return target SDK if the package is found or INT_MAX.
2124 */
2125 private int getTargetSdk(String packageName) {
2126 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002127 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002128 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002129 if (ai != null) return ai.targetSdkVersion;
2130 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002131 loge("Failed to get package info for pkg="
2132 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002133 }
2134 return Integer.MAX_VALUE;
2135 }
2136
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 @Override
2138 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002139 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2140 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002141 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2142 throw new SecurityException(
2143 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2144 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002145
Jordan Liu1617b712019-07-10 15:06:26 -07002146 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2148 return null;
2149 }
Svetoslav64fad262015-04-14 14:35:21 -07002150
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002151 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152
Nathan Haroldf180aac2018-06-01 18:43:55 -07002153 List<CellInfo> info = getAllCellInfo(callingPackage);
2154 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Nathan Haroldf180aac2018-06-01 18:43:55 -07002156 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2157 for (CellInfo ci : info) {
2158 if (ci instanceof CellInfoGsm) {
2159 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2160 } else if (ci instanceof CellInfoWcdma) {
2161 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002164 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002167 private List<CellInfo> getCachedCellInfo() {
2168 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2169 for (Phone phone : PhoneFactory.getPhones()) {
2170 List<CellInfo> info = phone.getAllCellInfo();
2171 if (info != null) cellInfos.addAll(info);
2172 }
2173 return cellInfos;
2174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
2176 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002177 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002178 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002179 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002180
2181 LocationAccessPolicy.LocationPermissionResult locationResult =
2182 LocationAccessPolicy.checkLocationPermission(mApp,
2183 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2184 .setCallingPackage(callingPackage)
2185 .setCallingPid(Binder.getCallingPid())
2186 .setCallingUid(Binder.getCallingUid())
2187 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2190 .build());
2191 switch (locationResult) {
2192 case DENIED_HARD:
2193 throw new SecurityException("Not allowed to access cell info");
2194 case DENIED_SOFT:
2195 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002198 final int targetSdk = getTargetSdk(callingPackage);
2199 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2200 return getCachedCellInfo();
2201 }
2202
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002203 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002204 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2208 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002209 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002210 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211 if (info != null) cellInfos.addAll(info);
2212 }
2213 return cellInfos;
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217 }
2218
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002219 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2221 requestCellInfoUpdateInternal(
2222 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2223 }
2224
2225 @Override
2226 public void requestCellInfoUpdateWithWorkSource(
2227 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2228 enforceModifyPermission();
2229 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2230 }
2231
2232 private void requestCellInfoUpdateInternal(
2233 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002234 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002236
2237 LocationAccessPolicy.LocationPermissionResult locationResult =
2238 LocationAccessPolicy.checkLocationPermission(mApp,
2239 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2240 .setCallingPackage(callingPackage)
2241 .setCallingPid(Binder.getCallingPid())
2242 .setCallingUid(Binder.getCallingUid())
2243 .setMethod("requestCellInfoUpdate")
2244 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2245 .build());
2246 switch (locationResult) {
2247 case DENIED_HARD:
2248 throw new SecurityException("Not allowed to access cell info");
2249 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002250 try {
2251 cb.onCellInfo(new ArrayList<CellInfo>());
2252 } catch (RemoteException re) {
2253 // Drop without consequences
2254 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002255 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002256 }
2257
Nathan Harolda939a962019-05-09 10:13:47 -07002258
2259 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002260 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2261
2262 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2263 }
2264
2265 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002267 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002272 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
Shishir Agrawala9f32182016-04-12 12:00:16 -07002278 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002279 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 Phone phone = PhoneFactory.getPhone(slotIndex);
2281 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002282 return null;
2283 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002285 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2286 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 return null;
2288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 return phone.getImei();
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002296 }
2297
2298 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002299 public String getTypeAllocationCodeForSlot(int slotIndex) {
2300 Phone phone = PhoneFactory.getPhone(slotIndex);
2301 String tac = null;
2302 if (phone != null) {
2303 String imei = phone.getImei();
2304 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2305 }
2306 return tac;
2307 }
2308
2309 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002310 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 Phone phone = PhoneFactory.getPhone(slotIndex);
2312 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002313 return null;
2314 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002315
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002317 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2318 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 return null;
2320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 return phone.getMeid();
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
Jack Yu2af8d712017-03-15 17:14:14 -07002328 }
2329
2330 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002331 public String getManufacturerCodeForSlot(int slotIndex) {
2332 Phone phone = PhoneFactory.getPhone(slotIndex);
2333 String manufacturerCode = null;
2334 if (phone != null) {
2335 String meid = phone.getMeid();
2336 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2337 }
2338 return manufacturerCode;
2339 }
2340
2341 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002342 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 Phone phone = PhoneFactory.getPhone(slotIndex);
2344 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 return null;
2346 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 int subId = phone.getSubId();
2348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2349 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2350 return null;
2351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 return phone.getDeviceSvn();
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
2358 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002359 }
2360
fionaxu43304da2017-11-27 22:51:16 -08002361 @Override
2362 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 final Phone phone = getPhone(subId);
2366 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
2369 }
fionaxu43304da2017-11-27 22:51:16 -08002370 }
2371
2372 @Override
2373 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 final Phone phone = getPhone(subId);
2377 return phone == null ? null : phone.getCarrierName();
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
fionaxu43304da2017-11-27 22:51:16 -08002381 }
2382
calvinpanffe225e2018-11-01 19:43:06 +08002383 @Override
chen xu0026ca62019-03-06 15:28:50 -08002384 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = getPhone(subId);
2388 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002389 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
2393 }
2394
2395 @Override
chen xu0026ca62019-03-06 15:28:50 -08002396 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002400 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
2404 }
2405
chen xu651eec72018-11-11 19:03:44 -08002406 @Override
chen xu864e11c2018-12-06 22:10:03 -08002407 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2408 if (!isSubscriptionMccMnc) {
2409 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2410 }
chen xu651eec72018-11-11 19:03:44 -08002411 final Phone phone = PhoneFactory.getPhone(slotIndex);
2412 if (phone == null) {
2413 return TelephonyManager.UNKNOWN_CARRIER_ID;
2414 }
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
2420 }
2421 }
2422
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 //
2424 // Internal helper methods.
2425 //
2426
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002427 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2429 *
2430 * @throws SecurityException if the caller does not have the required permission
2431 */
2432 private void enforceModifyPermission() {
2433 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2434 }
2435
Shuo Qianf2b2df42019-11-13 17:43:31 -08002436 private void enforceActiveEmergencySessionPermission() {
2437 mApp.enforceCallingOrSelfPermission(
2438 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2439 }
2440
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 /**
2442 * Make sure the caller has the CALL_PHONE permission.
2443 *
2444 * @throws SecurityException if the caller does not have the required permission
2445 */
2446 private void enforceCallPermission() {
2447 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2448 }
2449
paulhu423b5f22019-08-23 19:17:33 +08002450 private void enforceSettingsPermission() {
2451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002452 }
2453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 private String createTelUrl(String number) {
2455 if (TextUtils.isEmpty(number)) {
2456 return null;
2457 }
2458
Jake Hambye994d462014-02-03 13:10:13 -08002459 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
Ihab Awadf9e92732013-12-05 18:02:52 -08002462 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2464 }
2465
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002466 private static void logv(String msg) {
2467 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002476 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002477 }
2478
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002480 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 final Phone phone = PhoneFactory.getPhone(slotIndex);
2484 if (phone == null) {
2485 return PhoneConstants.PHONE_TYPE_NONE;
2486 } else {
2487 return phone.getPhoneType();
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
2494 /**
2495 * Returns the CDMA ERI icon index to display
2496 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 @Override
2498 public int getCdmaEriIconIndex(String callingPackage) {
2499 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002500 }
2501
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002505 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002506 return -1;
2507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
2513 return phone.getCdmaEriIconIndex();
2514 } else {
2515 return -1;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
2522 /**
2523 * Returns the CDMA ERI icon mode,
2524 * 0 - ON
2525 * 1 - FLASHING
2526 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002527 @Override
2528 public int getCdmaEriIconMode(String callingPackage) {
2529 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002530 }
2531
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002535 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 return -1;
2537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone != null) {
2543 return phone.getCdmaEriIconMode();
2544 } else {
2545 return -1;
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
2552 /**
2553 * Returns the CDMA ERI text,
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
2556 public String getCdmaEriText(String callingPackage) {
2557 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002561 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002563 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 return null;
2565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 return phone.getCdmaEriText();
2572 } else {
2573 return null;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002581 * Returns the CDMA MDN.
2582 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002584 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2586 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 return phone.getLine1Number();
2593 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 return null;
2596 }
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002599 }
2600 }
2601
2602 /**
2603 * Returns the CDMA MIN.
2604 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002606 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2608 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
2613 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2614 return phone.getCdmaMin();
2615 } else {
2616 return null;
2617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002620 }
2621 }
2622
Hall Liud892bec2018-11-30 14:51:45 -08002623 @Override
2624 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2625 INumberVerificationCallback callback, String callingPackage) {
2626 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2627 != PERMISSION_GRANTED) {
2628 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2629 }
2630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2631
2632 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2633 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2634 throw new SecurityException("Calling package must be configured in the device config");
2635 }
2636
2637 if (range == null) {
2638 throw new NullPointerException("Range must be non-null");
2639 }
2640
2641 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002642 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002643
2644 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2645 }
2646
Junda Liuca05d5d2014-08-14 22:36:34 -07002647 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 * Returns true if CDMA provisioning needs to run.
2649 */
2650 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002653 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
2659 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002660 * Sets the voice mail number of a given subId.
2661 */
2662 @Override
2663 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002664 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2669 new Pair<String, String>(alphaTag, number), new Integer(subId));
2670 return success;
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002674 }
2675
Ta-wei Yen87c49842016-05-13 21:19:52 -07002676 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002677 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002679 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2680 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002681 if (!TextUtils.equals(callingPackage, systemDialer)) {
2682 throw new SecurityException("caller must be system dialer");
2683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2688 if (phoneAccountHandle == null) {
2689 return null;
2690 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002691 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002694 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 }
2696
2697 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002698 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002701 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002702 return null;
2703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002707 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002708 } finally {
2709 Binder.restoreCallingIdentity(identity);
2710 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002711 }
2712
2713 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002714 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2715 VisualVoicemailSmsFilterSettings settings) {
2716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002721 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002725 }
2726
2727 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002728 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002734 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002738 }
2739
2740 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002741 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2742 String callingPackage, int subId) {
2743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002748 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749 } finally {
2750 Binder.restoreCallingIdentity(identity);
2751 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002752 }
2753
2754 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002755 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002756 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002761 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002765 }
2766
2767 @Override
2768 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2769 String number, int port, String text, PendingIntent sentIntent) {
2770 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002771 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002772 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002773 SmsController smsController = PhoneFactory.getSmsController();
2774 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2775 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002776 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002777
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002778 /**
fionaxu0152e512016-11-14 13:36:14 -08002779 * Sets the voice activation state of a given subId.
2780 */
2781 @Override
2782 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2784 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785
2786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 if (phone != null) {
2790 phone.setVoiceActivationState(activationState);
2791 } else {
2792 loge("setVoiceActivationState fails with invalid subId: " + subId);
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002796 }
2797 }
2798
2799 /**
2800 * Sets the data activation state of a given subId.
2801 */
2802 @Override
2803 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2805 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 final Phone phone = getPhone(subId);
2810 if (phone != null) {
2811 phone.setDataActivationState(activationState);
2812 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002813 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002817 }
2818 }
2819
2820 /**
2821 * Returns the voice activation state of a given subId.
2822 */
2823 @Override
2824 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002825 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
fionaxu0152e512016-11-14 13:36:14 -08002827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 if (phone != null) {
2831 return phone.getVoiceActivationState();
2832 } else {
2833 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the data activation state of a given subId.
2842 */
2843 @Override
2844 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getDataActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
Wink Saville36469e72014-06-11 15:17:00 -07002861 * Returns the unread count of voicemails for a subId
2862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002864 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2866 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2867 return 0;
2868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 final Phone phone = getPhone(subId);
2872 if (phone != null) {
2873 return phone.getVoiceMessageCount();
2874 } else {
2875 return 0;
2876 }
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
2882 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002883 * returns true, if the device is in a state where both voice and data
2884 * are supported simultaneously. This can change based on location or network condition.
2885 */
2886 @Override
2887 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
2891 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002895 }
2896
2897 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002898 * Send the dialer code if called from the current default dialer or the caller has
2899 * carrier privilege.
2900 * @param inputCode The dialer code to send
2901 */
2902 @Override
2903 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002906 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2907 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002908 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002909 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2910 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002915 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
fionaxu235cc5e2017-03-06 22:25:57 -08002919 }
2920
Pengquan Menga1bb6272018-09-06 09:59:22 -07002921 @Override
2922 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002923 if (!isActiveSubscription(subId)) {
2924 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2925 }
2926
Pengquan Menga1bb6272018-09-06 09:59:22 -07002927 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2928 }
2929
Brad Ebinger35c841c2018-10-01 10:40:55 -07002930 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002931 public boolean isInEmergencySmsMode() {
2932 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 for (Phone phone : PhoneFactory.getPhones()) {
2936 if (phone.isInEmergencySmsMode()) {
2937 return true;
2938 }
2939 }
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 return false;
2944 }
2945
2946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002947 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2948 throws RemoteException {
2949 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2952 "IMS not available on device.");
2953 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 final long token = Binder.clearCallingIdentity();
2955 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002959 } catch (ImsException e) {
2960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 } finally {
2962 Binder.restoreCallingIdentity(token);
2963 }
2964 }
2965
2966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002967 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2968 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002969 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2970 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2971 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002972 final long token = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2975 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2976 .removeRegistrationCallbackForSubscription(c, subId);
2977 } catch (ImsException e) {
2978 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2979 + "is inactive, ignoring unregister.");
2980 // If the subscription is no longer active, just return, since the callback
2981 // will already have been removed internally.
2982 } finally {
2983 Binder.restoreCallingIdentity(token);
2984 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 }
2986
Brad Ebinger774ba362019-10-22 17:36:18 -07002987 /**
2988 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2989 */
2990 @Override
2991 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2992 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2993 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2994 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2995 "IMS not available on device.");
2996 }
2997 final long token = Binder.clearCallingIdentity();
2998 try {
2999 Phone phone = getPhone(subId);
3000 if (phone == null) {
3001 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3002 + subId + "'");
3003 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3004 }
3005 phone.getImsRegistrationState(regState -> {
3006 try {
3007 consumer.accept((regState == null)
3008 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3009 } catch (RemoteException e) {
3010 // Ignore if the remote process is no longer available to call back.
3011 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3012 }
3013 });
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
3017 }
3018
3019 /**
3020 * Get the transport type for the IMS service registration state.
3021 */
3022 @Override
3023 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3024 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3025 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3027 "IMS not available on device.");
3028 }
3029 final long token = Binder.clearCallingIdentity();
3030 try {
3031 Phone phone = getPhone(subId);
3032 if (phone == null) {
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3034 + subId + "'");
3035 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3036 }
3037 phone.getImsRegistrationTech(regTech -> {
3038 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3039 int regTechConverted = (regTech == null)
3040 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3041 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3042 regTechConverted);
3043 try {
3044 consumer.accept(regTechConverted);
3045 } catch (RemoteException e) {
3046 // Ignore if the remote process is no longer available to call back.
3047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3048 }
3049 });
3050 } finally {
3051 Binder.restoreCallingIdentity(token);
3052 }
3053 }
3054
Brad Ebinger35c841c2018-10-01 10:40:55 -07003055 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003056 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3057 throws RemoteException {
3058 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003059 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3060 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3061 "IMS not available on device.");
3062 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3064 final long token = Binder.clearCallingIdentity();
3065 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003066 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003068 } catch (ImsException e) {
3069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 } finally {
3071 Binder.restoreCallingIdentity(token);
3072 }
3073 }
3074
3075 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003076 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3077 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3079 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3080 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003081
3082 final long token = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3085 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003086 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003087 } catch (ImsException e) {
3088 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3089 + "is inactive, ignoring unregister.");
3090 // If the subscription is no longer active, just return, since the callback
3091 // will already have been removed internally.
3092 } finally {
3093 Binder.restoreCallingIdentity(token);
3094 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 }
3096
3097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003098 public boolean isCapable(int subId, int capability, int regTech) {
3099 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3101 final long token = Binder.clearCallingIdentity();
3102 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003105 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3107 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003108 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003109 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3110 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 } finally {
3112 Binder.restoreCallingIdentity(token);
3113 }
3114 }
3115
3116 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003117 public boolean isAvailable(int subId, int capability, int regTech) {
3118 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 final long token = Binder.clearCallingIdentity();
3120 try {
3121 Phone phone = getPhone(subId);
3122 if (phone == null) return false;
3123 return phone.isImsCapabilityAvailable(capability, regTech);
3124 } finally {
3125 Binder.restoreCallingIdentity(token);
3126 }
3127 }
3128
Brad Ebinger77b832e2019-10-17 17:03:22 -07003129 /**
3130 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3131 * subscription.
3132 * @param subId The subscription to use to check the configuration.
3133 * @param callback The callback that will be used to send the result.
3134 * @param capability The MmTelFeature capability that will be used to send the result.
3135 * @param transportType The transport type of the MmTelFeature capability.
3136 */
3137 @Override
3138 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3139 int transportType) {
3140 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3141 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3142 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3143 "IMS not available on device.");
3144 }
3145 final long token = Binder.clearCallingIdentity();
3146 try {
3147 int slotId = getSlotIndex(subId);
3148 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3149 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3150 + subId + "'");
3151 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3152 }
3153 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3154 transportType, aBoolean -> {
3155 try {
3156 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3157 } catch (RemoteException e) {
3158 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3159 + "running. Ignore");
3160 }
3161 });
3162 } finally {
3163 Binder.restoreCallingIdentity(token);
3164 }
3165 }
3166
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 @Override
3168 public boolean isAdvancedCallingSettingEnabled(int subId) {
3169 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3171 final long token = Binder.clearCallingIdentity();
3172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003175 } catch (ImsException e) {
3176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 } finally {
3178 Binder.restoreCallingIdentity(token);
3179 }
3180 }
3181
3182 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003183 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003185 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003191 } catch (ImsException e) {
3192 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 }
3197
3198 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003199 public boolean isVtSettingEnabled(int subId) {
3200 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003204 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3205 } catch (ImsException e) {
3206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
3210 }
3211
3212 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003213 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003215 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003220 } catch (ImsException e) {
3221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
3226
3227 @Override
3228 public boolean isVoWiFiSettingEnabled(int subId) {
3229 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003235 } catch (ImsException e) {
3236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
3240 }
3241
3242 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003243 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003245 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003250 } catch (ImsException e) {
3251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
3255 }
3256
3257 @Override
3258 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3259 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
3266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
3270 }
3271
3272 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003273 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003275 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 } catch (ImsException e) {
3282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
3286 }
3287
3288 @Override
3289 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3291 "setVoWiFiNonPersistent");
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003296 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
3305 public int getVoWiFiModeSetting(int subId) {
3306 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003312 } catch (ImsException e) {
3313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public void setVoWiFiModeSetting(int subId, int mode) {
3321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3322 "setVoWiFiModeSetting");
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003328 } catch (ImsException e) {
3329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
3335 @Override
3336 public int getVoWiFiRoamingModeSetting(int subId) {
3337 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003341 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003343 } catch (ImsException e) {
3344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
3350 @Override
3351 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3353 "setVoWiFiRoamingModeSetting");
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003357 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003359 } catch (ImsException e) {
3360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003361 } finally {
3362 Binder.restoreCallingIdentity(identity);
3363 }
3364 }
3365
3366 @Override
3367 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3369 "setRttCapabilityEnabled");
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003373 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3374 } catch (ImsException e) {
3375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
3379 }
3380
3381 @Override
3382 public boolean isTtyOverVolteEnabled(int subId) {
3383 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 @Override
3397 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3398 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003402 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003403 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003404 } catch (ImsException e) {
3405 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
3409 }
3410
3411 @Override
3412 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3413 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3414 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 try {
3419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003421 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003422 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003423 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3424 + "is inactive, ignoring unregister.");
3425 // If the subscription is no longer active, just return, since the callback will already
3426 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003433 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3434 boolean isProvisioned) {
3435 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3436 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3437 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3438 }
3439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3440 "setProvisioningStatusForCapability");
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3444 Phone phone = getPhone(subId);
3445 if (phone == null) {
3446 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3447 + subId);
3448 return;
3449 }
3450 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3451 return;
3452 }
3453
3454 // this capability requires provisioning, route to the correct API.
3455 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3456 switch (capability) {
3457 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3458 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3459 ims.setVolteProvisioned(isProvisioned);
3460 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3461 ims.setWfcProvisioned(isProvisioned);
3462 }
3463 break;
3464 }
3465 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3466 // There is currently no difference in VT provisioning type.
3467 ims.setVtProvisioned(isProvisioned);
3468 break;
3469 }
3470 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3471 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3472 // change the capability of the feature instead if needed.
3473 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3474 == isProvisioned) {
3475 // No change in provisioning.
3476 return;
3477 }
3478 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3479 try {
3480 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003481 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3483 + ", Exception" + e.getMessage());
3484 }
3485 break;
3486 }
3487 default: {
3488 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3489 + capability + "', which does not require provisioning.");
3490 }
3491 }
3492
3493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
3498 @Override
3499 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3500 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3501 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3502 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3503 }
3504 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3508 Phone phone = getPhone(subId);
3509 if (phone == null) {
3510 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3511 + subId);
3512 // We will fail with "true" as the provisioning status because this is the default
3513 // if we do not require provisioning.
3514 return true;
3515 }
3516
3517 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3518 return true;
3519 }
3520
3521 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3522 switch (capability) {
3523 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3524 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3525 return ims.isVolteProvisionedOnDevice();
3526 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3527 return ims.isWfcProvisionedOnDevice();
3528 }
3529 // This should never happen, since we are checking tech above to make sure it
3530 // is either LTE or IWLAN.
3531 throw new IllegalArgumentException("Invalid radio technology for voice "
3532 + "capability.");
3533 }
3534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3535 // There is currently no difference in VT provisioning type.
3536 return ims.isVtProvisionedOnDevice();
3537 }
3538 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3539 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3540 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3541 }
3542 default: {
3543 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3544 + capability + "', which does not require provisioning.");
3545 }
3546 }
3547
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
3553 @Override
3554 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3555 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3556 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3557 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3558 }
3559 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3560 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3561 return (provisionedBits & capability) > 0;
3562 }
3563
3564 @Override
3565 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3566 boolean isProvisioned) {
3567 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3568 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3569 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3570 }
3571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3572 "setProvisioningStatusForCapability");
3573 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3574 // If the current provisioning status for capability already matches isProvisioned,
3575 // do nothing.
3576 if (((provisionedBits & capability) > 0) == isProvisioned) {
3577 return;
3578 }
3579 if (isProvisioned) {
3580 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3581 } else {
3582 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3583 }
3584 }
3585
3586 /**
3587 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3588 * technology. The bitfield should mirror the bitfield defined by
3589 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3590 */
3591 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3592 String key = getMmTelProvisioningKey(subId, tech);
3593 // Default is no capabilities are provisioned.
3594 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3595 }
3596
3597 /**
3598 * Sets the MmTel capability provisioning bitfield (defined by
3599 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3600 * technology specified.
3601 *
3602 * Note: This is a synchronous command and should not be called on UI thread.
3603 */
3604 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3605 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3606 String key = getMmTelProvisioningKey(subId, tech);
3607 editor.putInt(key, newField);
3608 editor.commit();
3609 }
3610
3611 private static String getMmTelProvisioningKey(int subId, int tech) {
3612 // resulting key is provision_ims_mmtel_{subId}_{tech}
3613 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3614 }
3615
3616 /**
3617 * Query CarrierConfig to see if the specified capability requires provisioning for the
3618 * carrier associated with the subscription id.
3619 */
3620 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3621 int capability) {
3622 CarrierConfigManager configManager = new CarrierConfigManager(context);
3623 PersistableBundle c = configManager.getConfigForSubId(subId);
3624 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003625 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003626 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3627 false);
3628 boolean requireVoiceVtProvisioning = c.getBoolean(
3629 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3630
3631 // First check to make sure that the capability requires provisioning.
3632 switch (capability) {
3633 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3634 // intentional fallthrough
3635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3636 if (requireVoiceVtProvisioning) {
3637 // Voice and Video requires provisioning
3638 return true;
3639 }
3640 break;
3641 }
3642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3643 if (requireUtProvisioning) {
3644 // UT requires provisioning
3645 return true;
3646 }
3647 break;
3648 }
3649 }
3650 return false;
3651 }
3652
3653 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003654 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3656 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3657 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003658 enforceReadPrivilegedPermission("getImsProvisioningInt");
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003662 int slotId = getSlotIndex(subId);
3663 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3664 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3665 + subId + "' for key:" + key);
3666 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3667 }
3668 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003669 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003670 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3671 + subId + "' for key:" + key);
3672 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
3676 }
3677
3678 @Override
3679 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3681 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3682 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003683 enforceReadPrivilegedPermission("getImsProvisioningString");
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 int slotId = getSlotIndex(subId);
3688 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3689 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3690 + subId + "' for key:" + key);
3691 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3692 }
3693 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3696 + subId + "' for key:" + key);
3697 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
3703 @Override
3704 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3706 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3707 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3709 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003713 int slotId = getSlotIndex(subId);
3714 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3715 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3716 + subId + "' for key:" + key);
3717 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3718 }
3719 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003721 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3722 + "' for key:" + key);
3723 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
3729 @Override
3730 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003731 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3732 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3733 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3735 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003739 int slotId = getSlotIndex(subId);
3740 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3741 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3742 + subId + "' for key:" + key);
3743 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3744 }
3745 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003746 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003747 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3748 + "' for key:" + key);
3749 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
3753 }
3754
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 int slotId = SubscriptionManager.getSlotIndex(subId);
3757 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3759 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 }
3761 return slotId;
3762 }
3763
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003764 private int getSlotIndex(int subId) {
3765 int slotId = SubscriptionManager.getSlotIndex(subId);
3766 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3767 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3768 }
3769 return slotId;
3770 }
3771
Wink Saville36469e72014-06-11 15:17:00 -07003772 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003773 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003774 */
3775 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003776 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003777 final int targetSdk = getTargetSdk(callingPackage);
3778 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3779 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3780 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003781 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3782 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3784 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 return phone.getServiceState().getDataNetworkType();
3791 } else {
3792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003797 }
3798
3799 /**
3800 * Returns the data network type
3801 */
3802 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003803 public int getDataNetworkType(String callingPackage) {
3804 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003805 }
3806
3807 /**
3808 * Returns the data network type for a subId
3809 */
3810 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003811 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003813 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3815 }
3816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 final Phone phone = getPhone(subId);
3820 if (phone != null) {
3821 return phone.getServiceState().getDataNetworkType();
3822 } else {
3823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3824 }
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003828 }
3829
3830 /**
Wink Saville36469e72014-06-11 15:17:00 -07003831 * Returns the Voice network type for a subId
3832 */
3833 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003834 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003836 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003837 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3838 }
3839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 if (phone != null) {
3844 return phone.getServiceState().getVoiceNetworkType();
3845 } else {
3846 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3847 }
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003851 }
3852
3853 /**
3854 * @return true if a ICC card is present
3855 */
3856 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003857 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003858 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3859 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003860 }
3861
3862 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003863 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003864 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003865 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003866 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 final Phone phone = PhoneFactory.getPhone(slotIndex);
3870 if (phone != null) {
3871 return phone.getIccCard().hasIccCard();
3872 } else {
3873 return false;
3874 }
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 }
3879
3880 /**
3881 * Return if the current radio is LTE on CDMA. This
3882 * is a tri-state return value as for a period of time
3883 * the mode may be unknown.
3884 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003885 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003887 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003889 @Override
3890 public int getLteOnCdmaMode(String callingPackage) {
3891 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003892 }
3893
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003895 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003897 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3899 }
3900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 final Phone phone = getPhone(subId);
3904 if (phone == null) {
3905 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3906 } else {
3907 return phone.getLteOnCdmaMode();
3908 }
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 }
Wink Saville36469e72014-06-11 15:17:00 -07003912 }
3913
Wink Saville36469e72014-06-11 15:17:00 -07003914 /**
3915 * {@hide}
3916 * Returns Default subId, 0 in the case of single standby.
3917 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003918 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003919 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003920 }
3921
Shishir Agrawala9f32182016-04-12 12:00:16 -07003922 private int getSlotForDefaultSubscription() {
3923 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3924 }
3925
Wink Savilleb564aae2014-10-23 10:18:09 -07003926 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003927 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003928 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003929
Pengquan Menge92a50d2018-09-21 15:54:48 -07003930 private boolean isActiveSubscription(int subId) {
3931 return mSubscriptionController.isActiveSubId(subId);
3932 }
3933
Ihab Awadf2177b72013-11-25 13:33:23 -08003934 /**
3935 * @see android.telephony.TelephonyManager.WifiCallingChoices
3936 */
3937 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3942 getWhenToMakeWifiCallsDefaultPreference());
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003946 }
3947
3948 /**
3949 * @see android.telephony.TelephonyManager.WifiCallingChoices
3950 */
3951 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003960 }
3961
Sailesh Nepald1e68152013-12-12 19:08:02 -08003962 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003963 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003964 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003965 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003966
Jordan Liu4c733742019-02-28 12:03:40 -08003967 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3968 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3969 if (phoneId == -1) {
3970 throw new IllegalArgumentException("Given slot index: " + slotIndex
3971 + " does not correspond to an active phone");
3972 }
3973 return PhoneFactory.getPhone(phoneId);
3974 }
3975
Shishir Agrawal566b7612013-10-28 14:41:00 -07003976 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003977 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3978 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003982 if (DBG) {
3983 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3984 }
3985 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3986 p2);
3987 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003988
Jordan Liu4c733742019-02-28 12:03:40 -08003989
3990 @Override
3991 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3992 int slotIndex, String callingPackage, String aid, int p2) {
3993 enforceModifyPermission();
3994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3995 if (DBG) {
3996 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3997 }
3998 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3999 callingPackage, aid, p2);
4000 }
4001
4002 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4003 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 if (TextUtils.equals(ISDR_AID, aid)) {
4007 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4009 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 if (bestComponent == null
4011 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4012 loge("The calling package is not allowed to access ISD-R.");
4013 throw new SecurityException(
4014 "The calling package is not allowed to access ISD-R.");
4015 }
Derek Tan740e1672017-06-27 14:56:27 -07004016 }
Derek Tan740e1672017-06-27 14:56:27 -07004017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004019 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4020 null /* workSource */);
4021 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022 return response;
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004026 }
4027
4028 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004029 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4031 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004032 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4033 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4034 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004035
Jordan Liu4c733742019-02-28 12:03:40 -08004036 @Override
4037 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4038 enforceModifyPermission();
4039 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4040 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4041 channel);
4042 }
4043
4044 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 if (channel < 0) {
4048 return false;
4049 }
Jordan Liu4c733742019-02-28 12:03:40 -08004050 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4051 null /* workSource */);
4052 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 return success;
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004056 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004057 }
4058
4059 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004060 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004061 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4063 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004064 if (DBG) {
4065 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4066 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4067 + p3 + " data=" + data);
4068 }
4069 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4070 command, p1, p2, p3, data);
4071 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004072
Jordan Liu4c733742019-02-28 12:03:40 -08004073 @Override
4074 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4075 int command, int p1, int p2, int p3, String data) {
4076 enforceModifyPermission();
4077 if (DBG) {
4078 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4079 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4080 + p3 + " data=" + data);
4081 }
4082 return iccTransmitApduLogicalChannelWithPermission(
4083 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4084 data);
4085 }
4086
4087 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4088 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 final long identity = Binder.clearCallingIdentity();
4090 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004091 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 return "";
4093 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004096 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4097 null /* workSource */);
4098 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 // Append the returned status code to the end of the response payload.
4101 String s = Integer.toHexString(
4102 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4103 if (response.payload != null) {
4104 s = IccUtils.bytesToHexString(response.payload) + s;
4105 }
4106 return s;
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004109 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004110 }
Jake Hambye994d462014-02-03 13:10:13 -08004111
Evan Charltonc66da362014-05-16 14:06:40 -07004112 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004113 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4114 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4116 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004118 if (DBG) {
4119 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4120 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4121 }
4122 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4123 cla, command, p1, p2, p3, data);
4124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004125
Jordan Liu4c733742019-02-28 12:03:40 -08004126 @Override
4127 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4128 int command, int p1, int p2, int p3, String data) {
4129 enforceModifyPermission();
4130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4131 if (DBG) {
4132 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4133 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4134 + " data=" + data);
4135 }
4136
4137 return iccTransmitApduBasicChannelWithPermission(
4138 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4139 p2, p3, data);
4140 }
4141
4142 // open APDU basic channel assuming the caller has sufficient permissions
4143 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4144 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4148 && TextUtils.equals(ISDR_AID, data)) {
4149 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4151 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 if (bestComponent == null
4153 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4154 loge("The calling package is not allowed to select ISD-R.");
4155 throw new SecurityException(
4156 "The calling package is not allowed to select ISD-R.");
4157 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004158 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004161 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4162 null /* workSource */);
4163 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 // Append the returned status code to the end of the response payload.
4166 String s = Integer.toHexString(
4167 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4168 if (response.payload != null) {
4169 s = IccUtils.bytesToHexString(response.payload) + s;
4170 }
4171 return s;
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004174 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004175 }
4176
4177 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004178 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004179 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4181 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 if (DBG) {
4186 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4187 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4188 }
4189
4190 IccIoResult response =
4191 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4192 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4193 subId);
4194
4195 if (DBG) {
4196 log("Exchange SIM_IO [R]" + response);
4197 }
4198
4199 byte[] result = null;
4200 int length = 2;
4201 if (response.payload != null) {
4202 length = 2 + response.payload.length;
4203 result = new byte[length];
4204 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4205 } else {
4206 result = new byte[length];
4207 }
4208
4209 result[length - 1] = (byte) response.sw2;
4210 result[length - 2] = (byte) response.sw1;
4211 return result;
4212 } finally {
4213 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004214 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004215 }
4216
Nathan Haroldb3014052017-01-25 15:57:32 -08004217 /**
4218 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4219 * on a particular subscription
4220 */
sqianb6e41952018-03-12 14:54:01 -07004221 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4223 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4224 return null;
4225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
4227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 if (appType != TelephonyManager.APPTYPE_USIM
4230 && appType != TelephonyManager.APPTYPE_SIM) {
4231 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4232 return null;
4233 }
4234 Object response = sendRequest(
4235 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4236 if (response instanceof String[]) {
4237 return (String[]) response;
4238 }
yincheng zhaod698b842019-09-06 17:06:54 -07004239 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004241 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004244 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004245 }
4246
yincheng zhaod698b842019-09-06 17:06:54 -07004247 /**
4248 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4249 * subscription.
4250 *
4251 * @param subId the id of the subscription.
4252 * @param appType the uicc app type, must be USIM or SIM.
4253 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4254 * @param callingPackage the op Package name.
4255 * @return number of fplmns that is successfully written to the SIM.
4256 */
4257 public int setForbiddenPlmns(
4258 int subId, int appType, List<String> fplmns, String callingPackage) {
4259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4260 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4261 if (DBG) logv("no permissions for setForbiddenplmns");
4262 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4263 }
4264 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4265 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4266 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4267 }
4268 if (fplmns == null) {
4269 throw new IllegalArgumentException("Fplmn List provided is null");
4270 }
4271 for (String fplmn : fplmns) {
4272 if (!CellIdentity.isValidPlmn(fplmn)) {
4273 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4274 }
4275 }
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 Object response = sendRequest(
4279 CMD_SET_FORBIDDEN_PLMNS,
4280 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4281 subId);
4282 return (int) response;
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004289 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4291 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4296 if (response.payload == null) {
4297 return "";
4298 }
Evan Charltonc66da362014-05-16 14:06:40 -07004299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 // Append the returned status code to the end of the response payload.
4301 String s = Integer.toHexString(
4302 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4303 s = IccUtils.bytesToHexString(response.payload) + s;
4304 return s;
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
Evan Charltonc66da362014-05-16 14:06:40 -07004308 }
4309
Jake Hambye994d462014-02-03 13:10:13 -08004310 /**
4311 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4312 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4313 *
4314 * @param itemID the ID of the item to read
4315 * @return the NV item as a String, or null on error.
4316 */
4317 @Override
4318 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4321 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004326 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4328 return value;
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
Jake Hambye994d462014-02-03 13:10:13 -08004332 }
4333
4334 /**
4335 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4336 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4337 *
4338 * @param itemID the ID of the item to read
4339 * @param itemValue the value to write, as a String
4340 * @return true on success; false on any failure
4341 */
4342 @Override
4343 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4346 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4351 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004352 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4354 return success;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Jake Hambye994d462014-02-03 13:10:13 -08004358 }
4359
4360 /**
4361 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4362 * Used for device configuration by some CDMA operators.
4363 *
4364 * @param preferredRoamingList byte array containing the new PRL
4365 * @return true on success; false on any failure
4366 */
4367 @Override
4368 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4375 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4376 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4377 return success;
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
Jake Hambye994d462014-02-03 13:10:13 -08004381 }
4382
4383 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004384 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004385 * Used for device configuration by some CDMA operators.
4386 *
chen xu6dac5ab2018-10-26 17:39:23 -07004387 * @param slotIndex - device slot.
4388 *
Jake Hambye994d462014-02-03 13:10:13 -08004389 * @return true on success; false on any failure
4390 */
4391 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004392 public boolean resetModemConfig(int slotIndex) {
4393 Phone phone = PhoneFactory.getPhone(slotIndex);
4394 if (phone != null) {
4395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
chen xu6dac5ab2018-10-26 17:39:23 -07004398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4401 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4402 return success;
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 }
chen xu6dac5ab2018-10-26 17:39:23 -07004407 return false;
4408 }
4409
4410 /**
4411 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4412 *
4413 * @param slotIndex - device slot.
4414 *
4415 * @return true on success; false on any failure
4416 */
4417 @Override
4418 public boolean rebootModem(int slotIndex) {
4419 Phone phone = PhoneFactory.getPhone(slotIndex);
4420 if (phone != null) {
4421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4422 mApp, phone.getSubId(), "rebootModem");
4423
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4427 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4428 return success;
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
4432 }
4433 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004434 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004435
Svet Ganovb320e182015-04-16 12:30:10 -07004436 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004437 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004439 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004440 return new String[0];
4441 }
4442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004445 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
Wink Saville36469e72014-06-11 15:17:00 -07004449 }
4450
Brad Ebinger51f743a2017-01-23 13:50:20 -08004451 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004452 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4453 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004454 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004455 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004460 ImsResolver resolver = PhoneFactory.getImsResolver();
4461 if (resolver == null) {
4462 // may happen if the device does not support IMS.
4463 return;
4464 }
4465 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004469 }
4470
4471 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004472 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4473 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004474 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004475 public void disableIms(int slotId) {
4476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004480 ImsResolver resolver = PhoneFactory.getImsResolver();
4481 if (resolver == null) {
4482 // may happen if the device does not support IMS.
4483 return;
4484 }
4485 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004489 }
4490
4491 /**
4492 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4493 * feature or {@link null} if the service is not available. If the feature is available, the
4494 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4495 */
4496 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004497 IImsServiceFeatureCallback callback) {
4498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004502 ImsResolver resolver = PhoneFactory.getImsResolver();
4503 if (resolver == null) {
4504 // may happen if the device does not support IMS.
4505 return null;
4506 }
4507 return resolver.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 Ebinger9c0eb502019-01-23 15:06:19 -08004524 ImsResolver resolver = PhoneFactory.getImsResolver();
4525 if (resolver == null) {
4526 // may happen if the device does not support IMS.
4527 return null;
4528 }
4529 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004533 }
4534
Brad Ebinger5f64b052017-12-14 14:26:15 -08004535 /**
4536 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004537 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004538 */
4539 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004544 ImsResolver resolver = PhoneFactory.getImsResolver();
4545 if (resolver == null) {
4546 // may happen if the device does not support IMS.
4547 return null;
4548 }
4549 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004553 }
4554
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004555 /**
4556 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004557 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004558 */
4559 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561
4562 final long identity = Binder.clearCallingIdentity();
4563 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004564 ImsResolver resolver = PhoneFactory.getImsResolver();
4565 if (resolver == null) {
4566 // may happen if the device does not support IMS.
4567 return null;
4568 }
4569 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004573 }
4574
Brad Ebinger884c07b2018-02-15 16:17:40 -08004575 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004576 * Sets the ImsService Package Name that Telephony will bind to.
4577 *
4578 * @param slotId the slot ID that the ImsService should bind for.
4579 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4580 * ImsService is the device default ImsService.
4581 * @param packageName The package name of the application that contains the ImsService to bind
4582 * to.
4583 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4584 * @hide
4585 */
4586 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004587 int[] subIds = SubscriptionManager.getSubId(slotId);
4588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4589 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4590 "setImsService");
4591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004594 ImsResolver resolver = PhoneFactory.getImsResolver();
4595 if (resolver == null) {
4596 // may happen if the device does not support IMS.
4597 return false;
4598 }
4599 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4600 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004604 }
4605
4606 /**
4607 * Return the ImsService configuration.
4608 *
4609 * @param slotId The slot that the ImsService is associated with.
4610 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4611 * the device default.
4612 * @return the package name of the ImsService configuration.
4613 */
4614 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004615 int[] subIds = SubscriptionManager.getSubId(slotId);
4616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4617 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4618 "getImsService");
4619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004622 ImsResolver resolver = PhoneFactory.getImsResolver();
4623 if (resolver == null) {
4624 // may happen if the device does not support IMS.
4625 return "";
4626 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004627 // TODO: change API to query RCS separately.
4628 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4629 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004633 }
4634
Brad Ebinger77b832e2019-10-17 17:03:22 -07004635 /**
4636 * Get the MmTelFeature state associated with the requested subscription id.
4637 * @param subId The subscription that the MmTelFeature is associated with.
4638 * @param callback A callback with an integer containing the
4639 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4640 */
4641 @Override
4642 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4643 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4644 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4646 "IMS not available on device.");
4647 }
4648 final long token = Binder.clearCallingIdentity();
4649 try {
4650 int slotId = getSlotIndex(subId);
4651 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4652 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4653 + subId + "'");
4654 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4655 }
4656 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4657 try {
4658 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4659 } catch (RemoteException e) {
4660 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4661 + "Ignore");
4662 }
4663 });
4664 } finally {
4665 Binder.restoreCallingIdentity(token);
4666 }
4667 }
4668
Wink Saville36469e72014-06-11 15:17:00 -07004669 public void setImsRegistrationState(boolean registered) {
4670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671
4672 final long identity = Binder.clearCallingIdentity();
4673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004674 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
Wink Saville36469e72014-06-11 15:17:00 -07004678 }
4679
4680 /**
Stuart Scott54788802015-03-30 13:18:01 -07004681 * Set the network selection mode to automatic.
4682 *
4683 */
4684 @Override
4685 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4687 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688
Pengquan Menge92a50d2018-09-21 15:54:48 -07004689 if (!isActiveSubscription(subId)) {
4690 return;
4691 }
4692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4696 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Stuart Scott54788802015-03-30 13:18:01 -07004700 }
4701
Pengquan Mengea84e042018-09-20 14:57:26 -07004702 /**
4703 * Ask the radio to connect to the input network and change selection mode to manual.
4704 *
4705 * @param subId the id of the subscription.
4706 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4707 * the operator to attach to.
4708 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4709 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4710 * normal network selection next time.
4711 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004712 */
4713 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004714 public boolean setNetworkSelectionModeManual(
4715 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4717 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004718
4719 if (!isActiveSubscription(subId)) {
4720 return false;
4721 }
4722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004725 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004727 if (DBG) {
4728 log("setNetworkSelectionModeManual: subId: " + subId
4729 + " operator: " + operatorInfo);
4730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004735 }
4736
4737 /**
4738 * Scans for available networks.
4739 */
4740 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004741 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4743 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004744 LocationAccessPolicy.LocationPermissionResult locationResult =
4745 LocationAccessPolicy.checkLocationPermission(mApp,
4746 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4747 .setCallingPackage(callingPackage)
4748 .setCallingPid(Binder.getCallingPid())
4749 .setCallingUid(Binder.getCallingUid())
4750 .setMethod("getCellNetworkScanResults")
4751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4752 .build());
4753 switch (locationResult) {
4754 case DENIED_HARD:
4755 throw new SecurityException("Not allowed to access scan results -- location");
4756 case DENIED_SOFT:
4757 return null;
4758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759
Pengquan Menga1bb6272018-09-06 09:59:22 -07004760 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 try {
4762 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004763 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004768 }
4769
4770 /**
yinxub1bed742017-04-17 11:45:04 -07004771 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004772 *
yinxub1bed742017-04-17 11:45:04 -07004773 * @param subId id of the subscription
4774 * @param request contains the radio access networks with bands/channels to scan
4775 * @param messenger callback messenger for scan results or errors
4776 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004777 * @return the id of the requested scan which can be used to stop the scan.
4778 */
4779 @Override
4780 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004781 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4783 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004784 LocationAccessPolicy.LocationPermissionResult locationResult =
4785 LocationAccessPolicy.checkLocationPermission(mApp,
4786 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4787 .setCallingPackage(callingPackage)
4788 .setCallingPid(Binder.getCallingPid())
4789 .setCallingUid(Binder.getCallingUid())
4790 .setMethod("requestNetworkScan")
4791 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4792 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004793 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004794 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004795 if (e != null) {
4796 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4797 throw e;
4798 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004799 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004800 return TelephonyScanManager.INVALID_SCAN_ID;
4801 }
4802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 }
Hall Liu912dfd32019-04-25 14:02:26 -07004804 int callingUid = Binder.getCallingUid();
4805 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 return mNetworkScanRequestTracker.startNetworkScan(
4809 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004810 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
yinxu504e1392017-04-12 16:03:22 -07004814 }
4815
Hall Liub2ac8ef2019-02-28 15:56:23 -08004816 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004817 NetworkScanRequest request, int subId) {
4818 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4819 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4820 boolean hasNetworkScanPermission =
4821 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4822 == PERMISSION_GRANTED;
4823
4824 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4825 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4826 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004827 }
4828
4829 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4830 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004831 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4832 return new SecurityException("Specific channels must not be"
4833 + " scanned without location access.");
4834 }
4835 }
4836 }
4837
Hall Liub2ac8ef2019-02-28 15:56:23 -08004838 return null;
4839 }
4840
yinxu504e1392017-04-12 16:03:22 -07004841 /**
4842 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004843 *
4844 * @param subId id of the subscription
4845 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004846 */
4847 @Override
4848 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4850 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851
Hall Liu912dfd32019-04-25 14:02:26 -07004852 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004855 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
yinxu504e1392017-04-12 16:03:22 -07004859 }
4860
4861 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004862 * Get the calculated preferred network type.
4863 * Used for debugging incorrect network type.
4864 *
4865 * @return the preferred network type, defined in RILConstants.java.
4866 */
4867 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004868 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 final Phone defaultPhone = getDefaultPhone();
4870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4871 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004872 return RILConstants.PREFERRED_NETWORK_MODE;
4873 }
4874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004878 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Junda Liu84d15a22014-07-02 11:21:04 -07004882 }
4883
4884 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004885 * Get the preferred network type.
4886 * Used for device configuration by some CDMA operators.
4887 *
4888 * @return the preferred network type, defined in RILConstants.java.
4889 */
4890 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004891 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004892 TelephonyPermissions
4893 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4894 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 if (DBG) log("getPreferredNetworkType");
4899 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4900 int networkType = (result != null ? result[0] : -1);
4901 if (DBG) log("getPreferredNetworkType: " + networkType);
4902 return networkType;
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004906 }
4907
4908 /**
4909 * Set the preferred network type.
4910 * Used for device configuration by some CDMA operators.
4911 *
4912 * @param networkType the preferred network type, defined in RILConstants.java.
4913 * @return true on success; false on any failure.
4914 */
4915 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004916 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4918 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919
4920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4923 Boolean success = (Boolean) sendRequest(
4924 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4925 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4926 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004927 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4929 }
4930 return success;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004933 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004934 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004935
4936 /**
Miaoa84611c2019-03-15 09:21:10 +08004937 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004938 *
Miaoa84611c2019-03-15 09:21:10 +08004939 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004940 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004941 * @hide
4942 */
4943 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004944 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004947 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 try {
Miaoa84611c2019-03-15 09:21:10 +08004949 if (phone != null) {
4950 return phone.hasMatchedTetherApnSetting();
4951 } else {
4952 return false;
4953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004956 }
Junda Liu475951f2014-11-07 16:45:03 -08004957 }
4958
4959 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004960 * Set mobile data enabled
4961 * Used by the user through settings etc to turn on/off mobile data
4962 *
4963 * @param enable {@code true} turn turn data on, else {@code false}
4964 */
4965 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004966 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4968 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 int phoneId = mSubscriptionController.getPhoneId(subId);
4973 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4974 Phone phone = PhoneFactory.getPhone(phoneId);
4975 if (phone != null) {
4976 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004977 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004979 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 }
4981 } finally {
4982 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004983 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004984 }
4985
4986 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004987 * Get the user enabled state of Mobile Data.
4988 *
4989 * TODO: remove and use isUserDataEnabled.
4990 * This can't be removed now because some vendor codes
4991 * calls through ITelephony directly while they should
4992 * use TelephonyManager.
4993 *
4994 * @return true on enabled
4995 */
4996 @Override
4997 public boolean getDataEnabled(int subId) {
4998 return isUserDataEnabled(subId);
4999 }
5000
5001 /**
5002 * Get whether mobile data is enabled per user setting.
5003 *
5004 * There are other factors deciding whether mobile data is actually enabled, but they are
5005 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005006 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005007 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005008 *
5009 * @return {@code true} if data is enabled else {@code false}
5010 */
5011 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005012 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005013 try {
5014 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5015 null);
5016 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5018 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 int phoneId = mSubscriptionController.getPhoneId(subId);
5024 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5025 Phone phone = PhoneFactory.getPhone(phoneId);
5026 if (phone != null) {
5027 boolean retVal = phone.isUserDataEnabled();
5028 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5029 return retVal;
5030 } else {
5031 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5032 return false;
5033 }
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005036 }
5037 }
5038
5039 /**
5040 * Get whether mobile data is enabled.
5041 *
5042 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5043 * whether mobile data is actually enabled.
5044 *
5045 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5046 *
5047 * @return {@code true} if data is enabled else {@code false}
5048 */
5049 @Override
5050 public boolean isDataEnabled(int subId) {
5051 try {
5052 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5053 null);
5054 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5056 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 int phoneId = mSubscriptionController.getPhoneId(subId);
5062 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5063 Phone phone = PhoneFactory.getPhone(phoneId);
5064 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005065 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5067 return retVal;
5068 } else {
5069 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5070 return false;
5071 }
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005074 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005075 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005076
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005077 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5078 Phone phone) {
5079 //load access rules from carrier configs, and check those as well: b/139133814
5080 SubscriptionController subController = SubscriptionController.getInstance();
5081 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5082 || subController == null) return privilegeFromSim;
5083
5084 int uid = Binder.getCallingUid();
5085 PackageManager pkgMgr = phone.getContext().getPackageManager();
5086 String[] packages = pkgMgr.getPackagesForUid(uid);
5087
5088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5091 SubscriptionManager subManager = (SubscriptionManager)
5092 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5093 for (String pkg : packages) {
5094 if (subManager.canManageSubscription(subInfo, pkg)) {
5095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5096 }
5097 }
5098 return privilegeFromSim;
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
5102 }
5103
5104 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5105 String pkgName) {
5106 //load access rules from carrier configs, and check those as well: b/139133814
5107 SubscriptionController subController = SubscriptionController.getInstance();
5108 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5109 || subController == null) return privilegeFromSim;
5110
5111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5114 SubscriptionManager subManager = (SubscriptionManager)
5115 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5116 return subManager.canManageSubscription(subInfo, pkgName)
5117 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
5121 }
5122
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005123 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005124 public int getCarrierPrivilegeStatus(int subId) {
5125 final Phone phone = getPhone(subId);
5126 if (phone == null) {
5127 loge("getCarrierPrivilegeStatus: Invalid subId");
5128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5129 }
5130 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005131 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005132 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005133 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5134 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005135
5136 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5137 card.getCarrierPrivilegeStatusForCurrentTransaction(
5138 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005139 }
Junda Liu29340342014-07-10 15:23:27 -07005140
5141 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005142 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5143 final Phone phone = getPhone(subId);
5144 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005145 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005146 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5147 }
5148 UiccProfile profile =
5149 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5150 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005151 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005152 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5153 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005154 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5155 profile.getCarrierPrivilegeStatusForUid(
5156 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 }
5158
5159 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005160 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5161 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005162 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005163 }
5164
5165 int phoneId = SubscriptionManager.getPhoneId(subId);
5166 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005167 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005168 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005169 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5170 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005171 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5172 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5173 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005174 }
5175
5176 @Override
5177 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005178 if (TextUtils.isEmpty(pkgName))
5179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005180 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5181 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5182 UiccCard card = UiccController.getInstance().getUiccCard(i);
5183 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005184 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005185 continue;
5186 }
5187
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005188 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5189 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5190 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005191 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5192 break;
5193 }
5194 }
5195
5196 return result;
Junda Liu29340342014-07-10 15:23:27 -07005197 }
Derek Tan89e89d42014-07-08 17:00:10 -07005198
5199 @Override
Junda Liue64de782015-04-16 17:19:16 -07005200 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5201 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5202 loge("phoneId " + phoneId + " is not valid.");
5203 return null;
5204 }
5205 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005206 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005207 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005208 return null ;
5209 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005210 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005211 }
5212
Amith Yamasani6e118872016-02-19 12:53:51 -08005213 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005214 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005216 List<String> privilegedPackages = new ArrayList<>();
5217 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005218 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5219 // has UICC in that slot.
5220 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005221 if (card.hasCarrierPrivilegeRules()) {
5222 if (packages == null) {
5223 // Only check packages in user 0 for now
5224 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005225 PackageManager.MATCH_DISABLED_COMPONENTS
5226 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005227 | PackageManager.GET_SIGNING_CERTIFICATES,
5228 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005229 }
5230 for (int p = packages.size() - 1; p >= 0; p--) {
5231 PackageInfo pkgInfo = packages.get(p);
5232 if (pkgInfo != null && pkgInfo.packageName != null
5233 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005234 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005235 privilegedPackages.add(pkgInfo.packageName);
5236 }
5237 }
5238 }
5239 }
5240 return privilegedPackages;
5241 }
5242
chen xuf7e9fe82019-05-09 19:31:02 -07005243 @Override
5244 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005245 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5246
5247 final long identity = Binder.clearCallingIdentity();
5248
chen xuf7e9fe82019-05-09 19:31:02 -07005249 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005250 try {
5251 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5252 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5253 }
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005256 }
5257 return privilegedPackages;
5258 }
5259
Wink Savilleb564aae2014-10-23 10:18:09 -07005260 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005261 final Phone phone = getPhone(subId);
5262 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005263 if (card == null) {
5264 loge("getIccId: No UICC");
5265 return null;
5266 }
5267 String iccId = card.getIccId();
5268 if (TextUtils.isEmpty(iccId)) {
5269 loge("getIccId: ICC ID is null or empty.");
5270 return null;
5271 }
5272 return iccId;
5273 }
5274
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005275 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005276 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5277 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005278 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5279 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 final long identity = Binder.clearCallingIdentity();
5282 try {
5283 final String iccId = getIccId(subId);
5284 final Phone phone = getPhone(subId);
5285 if (phone == null) {
5286 return false;
5287 }
5288 final String subscriberId = phone.getSubscriberId();
5289
5290 if (DBG_MERGE) {
5291 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5292 + subscriberId + " to " + number);
5293 }
5294
5295 if (TextUtils.isEmpty(iccId)) {
5296 return false;
5297 }
5298
5299 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5300
5301 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5302 if (alphaTag == null) {
5303 editor.remove(alphaTagPrefKey);
5304 } else {
5305 editor.putString(alphaTagPrefKey, alphaTag);
5306 }
5307
5308 // Record both the line number and IMSI for this ICCID, since we need to
5309 // track all merged IMSIs based on line number
5310 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5311 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5312 if (number == null) {
5313 editor.remove(numberPrefKey);
5314 editor.remove(subscriberPrefKey);
5315 } else {
5316 editor.putString(numberPrefKey, number);
5317 editor.putString(subscriberPrefKey, subscriberId);
5318 }
5319
5320 editor.commit();
5321 return true;
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005324 }
Derek Tan7226c842014-07-02 17:42:23 -07005325 }
5326
5327 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005328 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005329 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005331 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005332 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005333 return null;
5334 }
Derek Tan97ebb422014-09-05 16:55:38 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 String iccId = getIccId(subId);
5339 if (iccId != null) {
5340 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5341 if (DBG_MERGE) {
5342 log("getLine1NumberForDisplay returning "
5343 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5344 }
5345 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5348 return null;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005351 }
Derek Tan7226c842014-07-02 17:42:23 -07005352 }
5353
5354 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005355 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005357 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005358 return null;
5359 }
Derek Tan97ebb422014-09-05 16:55:38 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 String iccId = getIccId(subId);
5364 if (iccId != null) {
5365 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5366 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5367 }
5368 return null;
5369 } finally {
5370 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005371 }
Derek Tan7226c842014-07-02 17:42:23 -07005372 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005373
5374 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005375 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005376 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5377 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005379 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5380 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005381 return null;
5382 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005383
Jordan Liub49b04b2019-05-06 14:45:15 -07005384 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5385 // the process, where TelephonyManager was instantiated.
5386 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005387 final long identity = Binder.clearCallingIdentity();
5388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final TelephonyManager tele = TelephonyManager.from(context);
5391 final SubscriptionManager sub = SubscriptionManager.from(context);
5392
5393 // Figure out what subscribers are currently active
5394 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395
Jordan Liub49b04b2019-05-06 14:45:15 -07005396 // Only consider subs which match the current subId
5397 // This logic can be simplified. See b/131189269 for progress.
5398 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005399 activeSubscriberIds.add(tele.getSubscriberId(subId));
5400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401
5402 // First pass, find a number override for an active subscriber
5403 String mergeNumber = null;
5404 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5405 for (String key : prefs.keySet()) {
5406 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5407 final String subscriberId = (String) prefs.get(key);
5408 if (activeSubscriberIds.contains(subscriberId)) {
5409 final String iccId = key.substring(
5410 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5411 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5412 mergeNumber = (String) prefs.get(numberKey);
5413 if (DBG_MERGE) {
5414 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5415 + " for active subscriber " + subscriberId);
5416 }
5417 if (!TextUtils.isEmpty(mergeNumber)) {
5418 break;
5419 }
5420 }
5421 }
5422 }
5423
5424 // Shortcut when no active merged subscribers
5425 if (TextUtils.isEmpty(mergeNumber)) {
5426 return null;
5427 }
5428
5429 // Second pass, find all subscribers under that line override
5430 final ArraySet<String> result = new ArraySet<>();
5431 for (String key : prefs.keySet()) {
5432 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5433 final String number = (String) prefs.get(key);
5434 if (mergeNumber.equals(number)) {
5435 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5436 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5437 final String subscriberId = (String) prefs.get(subscriberKey);
5438 if (!TextUtils.isEmpty(subscriberId)) {
5439 result.add(subscriberId);
5440 }
5441 }
5442 }
5443 }
5444
5445 final String[] resultArray = result.toArray(new String[result.size()]);
5446 Arrays.sort(resultArray);
5447 if (DBG_MERGE) {
5448 Slog.d(LOG_TAG,
5449 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5450 }
5451 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005454 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005455 }
5456
5457 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005458 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5459 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 final TelephonyManager telephonyManager = mApp.getSystemService(
5464 TelephonyManager.class);
5465 String subscriberId = telephonyManager.getSubscriberId(subId);
5466 if (subscriberId == null) {
5467 if (DBG) {
5468 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5469 + subId);
5470 }
5471 return null;
5472 }
5473
5474 final SubscriptionInfo info = SubscriptionController.getInstance()
5475 .getSubscriptionInfo(subId);
5476 final ParcelUuid groupUuid = info.getGroupUuid();
5477 // If it doesn't belong to any group, return just subscriberId of itself.
5478 if (groupUuid == null) {
5479 return new String[]{subscriberId};
5480 }
5481
5482 // Get all subscriberIds from the group.
5483 final List<String> mergedSubscriberIds = new ArrayList<>();
5484 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5485 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5486 for (SubscriptionInfo subInfo : groupInfos) {
5487 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5488 if (subscriberId != null) {
5489 mergedSubscriberIds.add(subscriberId);
5490 }
5491 }
5492
5493 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496
5497 }
5498 }
5499
5500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005501 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005502 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5503 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504
5505 final long identity = Binder.clearCallingIdentity();
5506 try {
5507 final Phone phone = getPhone(subId);
5508 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005512 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005513
5514 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005515 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005516 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5517 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005518 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 final Phone phone = getPhone(subId);
5523 if (phone == null) {
5524 return false;
5525 }
5526 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5527 cdmaNonRoamingList);
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005530 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005531 }
5532
5533 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005534 @Deprecated
5535 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5536 enforceModifyPermission();
5537
5538 int returnValue = 0;
5539 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005540 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005541 if(result.exception == null) {
5542 if (result.result != null) {
5543 byte[] responseData = (byte[])(result.result);
5544 if(responseData.length > oemResp.length) {
5545 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5546 responseData.length + "bytes. Buffer Size is " +
5547 oemResp.length + "bytes.");
5548 }
5549 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5550 returnValue = responseData.length;
5551 }
5552 } else {
5553 CommandException ex = (CommandException) result.exception;
5554 returnValue = ex.getCommandError().ordinal();
5555 if(returnValue > 0) returnValue *= -1;
5556 }
5557 } catch (RuntimeException e) {
5558 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5559 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5560 if(returnValue > 0) returnValue *= -1;
5561 }
5562
5563 return returnValue;
5564 }
5565
5566 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005567 public void setRadioCapability(RadioAccessFamily[] rafs) {
5568 try {
5569 ProxyController.getInstance().setRadioCapability(rafs);
5570 } catch (RuntimeException e) {
5571 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5572 }
5573 }
5574
5575 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005576 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005577 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005578 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005579 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005580 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
chen xub97461a2018-10-26 14:17:57 -07005584 TelephonyPermissions
5585 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5586 mApp, phone.getSubId(), "getRadioAccessFamily");
5587 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
chen xub97461a2018-10-26 14:17:57 -07005591 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005592 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005593
5594 @Override
5595 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598
5599 final long identity = Binder.clearCallingIdentity();
5600 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005601 ImsManager.getInstance(defaultPhone.getContext(),
5602 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 } finally {
5604 Binder.restoreCallingIdentity(identity);
5605 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005606 }
5607
5608 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005609 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005610 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005612 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005613 return false;
5614 }
Svet Ganovb320e182015-04-16 12:30:10 -07005615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 // Check the user preference and the system-level IMS setting. Even if the user has
5619 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5620 // In the long run, we may instead need to check if there exists a connection service
5621 // which can support video calling.
5622 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005623 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 return imsManager.isVtEnabledByPlatform()
5625 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5626 && imsManager.isVtEnabledByUser();
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005630 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005631
Andrew Leea1239f22015-03-02 17:44:07 -08005632 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5635 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5636 return false;
5637 }
5638
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 CarrierConfigManager configManager =
5642 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Andrew Leea1239f22015-03-02 17:44:07 -08005648 }
5649
5650 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 public boolean isWorldPhone(int subId, String callingPackage) {
5652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5653 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5654 return false;
5655 }
5656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 CarrierConfigManager configManager =
5660 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005661 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Andrew Leea1239f22015-03-02 17:44:07 -08005666 }
5667
Andrew Lee9431b832015-03-09 18:46:45 -07005668 @Override
5669 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005670 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005671 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005672 }
5673
5674 @Override
5675 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005678 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
Andrew Lee9431b832015-03-09 18:46:45 -07005682 }
5683
Hall Liuf6668912018-10-31 17:05:23 -07005684 /**
5685 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5686 * support for the feature and device firmware support.
5687 *
5688 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5689 */
5690 @Override
5691 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 final Phone phone = getPhone(subscriptionId);
5694 if (phone == null) {
5695 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5696 return false;
5697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5701 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 return isCarrierSupported && isDeviceSupported;
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Hall Liu98187582018-01-22 19:15:32 -08005707 }
5708
Hall Liuf6668912018-10-31 17:05:23 -07005709 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005710 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5711 * RTT setting, will return true if the device and carrier both support RTT.
5712 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005713 */
5714 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 final long identity = Binder.clearCallingIdentity();
5716 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005717 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005721 }
5722
Sanket Padawe7310cc72015-01-14 09:53:20 -08005723 /**
5724 * Returns the unique device ID of phone, for example, the IMEI for
5725 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5726 *
5727 * <p>Requires Permission:
5728 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5729 */
5730 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005731 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005732 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005733 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005734 return null;
5735 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005736 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005737 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5738 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005739 return null;
5740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 return phone.getDeviceId();
5745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005748 }
5749
Ping Sunc67b7c22016-03-02 19:16:45 +08005750 /**
5751 * {@hide}
5752 * Returns the IMS Registration Status on a particular subid
5753 *
5754 * @param subId
5755 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005756 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005757 Phone phone = getPhone(subId);
5758 if (phone != null) {
5759 return phone.isImsRegistered();
5760 } else {
5761 return false;
5762 }
5763 }
5764
Santos Cordon7a1885b2015-02-03 11:15:19 -08005765 @Override
5766 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005773 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005774
Tyler Gunnf70ed162019-04-03 15:28:53 -07005775 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005776 public int getSubIdForPhoneAccountHandle(
5777 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5779 callingPackage, "getSubIdForPhoneAccountHandle")) {
5780 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5781 }
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
5788 }
5789
5790 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005791 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Phone phone = getPhone(subscriptionId);
5795 if (phone == null) {
5796 return null;
5797 }
5798 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
5802 }
5803
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005804 /**
5805 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005806 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005807 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 Phone phone = getPhone(subId);
5811 if (phone != null) {
5812 return phone.isWifiCallingEnabled();
5813 } else {
5814 return false;
5815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005818 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005819 }
5820
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005821 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005822 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005823 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005824 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 Phone phone = getPhone(subId);
5828 if (phone != null) {
5829 return phone.isVideoEnabled();
5830 } else {
5831 return false;
5832 }
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005835 }
5836 }
5837
5838 /**
5839 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5840 * defined in {@link ImsRegistrationImplBase}.
5841 */
5842 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 Phone phone = getPhone(subId);
5846 if (phone != null) {
5847 return phone.getImsRegistrationTech();
5848 } else {
5849 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5850 }
5851 } finally {
5852 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005853 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005854 }
5855
Stuart Scott8eef64f2015-04-08 15:13:54 -07005856 @Override
5857 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005858 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005859 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5860 return;
5861 }
5862
Svet Ganovcc087f82015-05-12 20:35:54 -07005863 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005864
Svet Ganovcc087f82015-05-12 20:35:54 -07005865 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005866 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5867 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005868 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005869 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005870 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005871 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5872 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005873 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005874 // There has been issues when Sms raw table somehow stores orphan
5875 // fragments. They lead to garbled message when new fragments come
5876 // in and combined with those stale ones. In case this happens again,
5877 // user can reset all network settings which will clean up this table.
5878 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005879 // Clean up IMS settings as well here.
5880 int slotId = getSlotIndex(subId);
5881 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5882 ImsManager.getInstance(mApp, slotId).factoryReset();
5883 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005884
5885 // Erase modem config if erase modem on network setting is enabled.
5886 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5887 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5888 if (configValue != null && Boolean.parseBoolean(configValue)) {
5889 sendEraseModemConfig(getDefaultPhone());
5890 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005893 }
5894 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005895
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005896 private void cleanUpSmsRawTable(Context context) {
5897 ContentResolver resolver = context.getContentResolver();
5898 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5899 resolver.delete(uri, null, null);
5900 }
5901
Narayan Kamath1c496c22015-04-16 14:40:19 +01005902 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005903 public String getSimLocaleForSubscriber(int subId) {
5904 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5905 final Phone phone = getPhone(subId);
5906 if (phone == null) {
5907 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005908 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
5911 try {
chen xu5d3637b2019-01-21 23:31:38 -08005912 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5913 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005914 if (info == null) {
5915 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5916 return null;
5917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 // Try and fetch the locale from the carrier properties or from the SIM language
5919 // preferences (EF-PL and EF-LI)...
5920 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005922 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5923 if (localeFromDefaultSim != null) {
5924 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5925 if (DBG) log("Using locale from subId: " + subId + " locale: "
5926 + localeFromDefaultSim);
5927 return localeFromDefaultSim.toLanguageTag();
5928 } else {
5929 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 }
5931 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 // The SIM language preferences only store a language (e.g. fr = French), not an
5934 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5935 // the SIM and carrier preferences does not include a country we add the country
5936 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005937 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005939 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 return mccLocale.toLanguageTag();
5941 }
5942
5943 if (DBG) log("No locale found - returning null");
5944 return null;
5945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005948 }
5949
5950 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005951 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005952 }
5953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 /**
5955 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5956 */
5957 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005958 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005959 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005960
Chenjie Yu1ba97252018-01-11 18:16:20 -08005961 private final ModemActivityInfo mLastModemActivityInfo =
5962 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5963
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005964 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005965 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5966 * representing the state of the modem.
5967 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005968 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5969 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005970 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005971 */
5972 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005973 public void requestModemActivityInfo(ResultReceiver result) {
5974 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976
5977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 ModemActivityInfo ret = null;
5980 synchronized (mLastModemActivityInfo) {
5981 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5982 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005983 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005984 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5986 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005987 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5988 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 }
5990 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005991 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5992 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 mLastModemActivityInfo.setIdleTimeMillis(
5994 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5995 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5996 mLastModemActivityInfo.setRxTimeMillis(
5997 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5998 mLastModemActivityInfo.setEnergyUsed(
5999 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6002 mLastModemActivityInfo.getSleepTimeMillis(),
6003 mLastModemActivityInfo.getIdleTimeMillis(),
6004 mLastModemActivityInfo.getTxTimeMillis(),
6005 mLastModemActivityInfo.getRxTimeMillis(),
6006 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 Bundle bundle = new Bundle();
6009 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6010 result.send(0, bundle);
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006013 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006014 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006015
Siddharth Rayb8114062018-06-17 15:02:38 -07006016 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6017 // less than total activity duration.
6018 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6019 if (info == null) {
6020 return false;
6021 }
6022 int activityDurationMs =
6023 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6024 int totalTxTimeMs = 0;
6025 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6026 totalTxTimeMs += info.getTxTimeMillis()[i];
6027 }
6028 return (info.isValid()
6029 && (info.getSleepTimeMillis() <= activityDurationMs)
6030 && (info.getIdleTimeMillis() <= activityDurationMs)
6031 && (info.getRxTimeMillis() <= activityDurationMs)
6032 && (totalTxTimeMs <= activityDurationMs));
6033 }
6034
Jack Yu85bd38a2015-11-09 11:34:32 -08006035 /**
6036 * {@hide}
6037 * Returns the service state information on specified subscription.
6038 */
6039 @Override
6040 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006042 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006043 return null;
6044 }
6045
Hall Liuf19c44f2018-11-27 14:38:17 -08006046 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6047 LocationAccessPolicy.checkLocationPermission(mApp,
6048 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6049 .setCallingPackage(callingPackage)
6050 .setCallingPid(Binder.getCallingPid())
6051 .setCallingUid(Binder.getCallingUid())
6052 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006053 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006054 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6055 .build());
6056
6057 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6058 LocationAccessPolicy.checkLocationPermission(mApp,
6059 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6060 .setCallingPackage(callingPackage)
6061 .setCallingPid(Binder.getCallingPid())
6062 .setCallingUid(Binder.getCallingUid())
6063 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006064 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006065 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6066 .build());
6067 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6068 boolean hasFinePermission =
6069 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6070 boolean hasCoarsePermission =
6071 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 final Phone phone = getPhone(subId);
6076 if (phone == null) {
6077 return null;
6078 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006079
Hall Liuf19c44f2018-11-27 14:38:17 -08006080 ServiceState ss = phone.getServiceState();
6081
6082 // Scrub out the location info in ServiceState depending on what level of access
6083 // the caller has.
6084 if (hasFinePermission) return ss;
6085 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6086 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006090 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006091
6092 /**
6093 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6094 *
6095 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6096 * voicemail ringtone.
6097 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6098 * PhoneAccount.
6099 */
6100 @Override
6101 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6105 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006113 }
6114
6115 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006116 * Sets the per-account voicemail ringtone.
6117 *
6118 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6119 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6120 *
6121 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6122 * voicemail ringtone.
6123 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6124 * PhoneAccount.
6125 */
6126 @Override
6127 public void setVoicemailRingtoneUri(String callingPackage,
6128 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006129 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006131 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6132 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6134 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6135 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6141 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 }
6144 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006147 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006148 }
6149
6150 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006151 * Returns whether vibration is set for voicemail notification in Phone settings.
6152 *
6153 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6154 * voicemail vibration setting.
6155 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6156 */
6157 @Override
6158 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
6161 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6162 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006163 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006170 }
6171
Youhan Wange64578a2016-05-02 15:32:42 -07006172 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006173 * Sets the per-account voicemail vibration.
6174 *
6175 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6176 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6177 *
6178 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6179 * voicemail vibration setting.
6180 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6181 * specific PhoneAccount.
6182 */
6183 @Override
6184 public void setVoicemailVibrationEnabled(String callingPackage,
6185 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006186 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006188 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6189 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6191 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6192 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006193 }
6194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6198 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006199 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200 }
6201 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006204 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006205 }
6206
6207 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006208 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6209 *
6210 * @throws SecurityException if the caller does not have the required permission
6211 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006212 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006213 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006214 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006215 }
6216
6217 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006218 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6219 * permission.
6220 *
6221 * @throws SecurityException if the caller does not have the required permission
6222 */
6223 private void enforceSendSmsPermission() {
6224 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6225 }
6226
6227 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006228 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006229 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006230 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006231 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006232 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006236 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 if (componentName == null) {
6238 throw new SecurityException(
6239 "Caller not current active visual voicemail package[null]");
6240 }
6241 String vvmPackage = componentName.getPackageName();
6242 if (!callingPackage.equals(vvmPackage)) {
6243 throw new SecurityException("Caller not current active visual voicemail package["
6244 + vvmPackage + "]");
6245 }
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006248 }
6249 }
6250
6251 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006252 * Return the application ID for the app type.
6253 *
6254 * @param subId the subscription ID that this request applies to.
6255 * @param appType the uicc app type.
6256 * @return Application ID for specificied app type, or null if no uicc.
6257 */
6258 @Override
6259 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006260 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006261 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262
6263 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006264 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 if (phone == null) {
6266 return null;
6267 }
6268 String aid = null;
6269 try {
6270 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6271 .getApplicationByType(appType).getAid();
6272 } catch (Exception e) {
6273 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6274 }
6275 return aid;
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006278 }
Youhan Wange64578a2016-05-02 15:32:42 -07006279 }
6280
Youhan Wang4001d252016-05-11 10:29:41 -07006281 /**
6282 * Return the Electronic Serial Number.
6283 *
6284 * @param subId the subscription ID that this request applies to.
6285 * @return ESN or null if error.
6286 */
6287 @Override
6288 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006289 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006290 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291
6292 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006293 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 if (phone == null) {
6295 return null;
6296 }
6297 String esn = null;
6298 try {
6299 esn = phone.getEsn();
6300 } catch (Exception e) {
6301 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6302 }
6303 return esn;
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006306 }
Youhan Wang4001d252016-05-11 10:29:41 -07006307 }
6308
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006309 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006310 * Return the Preferred Roaming List Version.
6311 *
6312 * @param subId the subscription ID that this request applies to.
6313 * @return PRLVersion or null if error.
6314 */
6315 @Override
6316 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006317 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006318 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
6320 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006321 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 if (phone == null) {
6323 return null;
6324 }
6325 String cdmaPrlVersion = null;
6326 try {
6327 cdmaPrlVersion = phone.getCdmaPrlVersion();
6328 } catch (Exception e) {
6329 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6330 }
6331 return cdmaPrlVersion;
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006334 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006335 }
6336
6337 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006338 * Get snapshot of Telephony histograms
6339 * @return List of Telephony histograms
6340 * @hide
6341 */
6342 @Override
6343 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6345 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 return RIL.getTelephonyRILTimingHistograms();
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006353 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006354
6355 /**
6356 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006357 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6358 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006359 * Require system privileges. In the future we may add this to carrier APIs.
6360 *
Michele Berionne482f8202018-11-27 18:57:59 -08006361 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006362 */
6363 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006364 @TelephonyManager.SetCarrierRestrictionResult
6365 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006366 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006368
Michele Berionne482f8202018-11-27 18:57:59 -08006369 if (carrierRestrictionRules == null) {
6370 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006371 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 final long identity = Binder.clearCallingIdentity();
6374 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006375 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006376 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006380 }
6381
6382 /**
6383 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006384 * Get the allowed carrier list and the excluded carrier list, including the priority between
6385 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006386 * Require system privileges. In the future we may add this to carrier APIs.
6387 *
Michele Berionne482f8202018-11-27 18:57:59 -08006388 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006389 */
6390 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006391 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006392 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006397 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6398 if (response instanceof CarrierRestrictionRules) {
6399 return (CarrierRestrictionRules) response;
6400 }
6401 // Response is an Exception of some kind,
6402 // which is signalled to the user as a NULL retval
6403 return null;
6404 } catch (Exception e) {
6405 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6406 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006410 }
6411
fionaxu59545b42016-05-25 15:53:37 -07006412 /**
6413 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6414 * @param subId the subscription ID that this action applies to.
6415 * @param enabled control enable or disable metered apns.
6416 * {@hide}
6417 */
6418 @Override
6419 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6420 enforceModifyPermission();
6421 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422
6423 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006424 if (phone == null) {
6425 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6426 return;
6427 }
6428 try {
6429 phone.carrierActionSetMeteredApnsEnabled(enabled);
6430 } catch (Exception e) {
6431 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006434 }
6435 }
6436
6437 /**
6438 * Action set from carrier signalling broadcast receivers to enable/disable radio
6439 * @param subId the subscription ID that this action applies to.
6440 * @param enabled control enable or disable radio.
6441 * {@hide}
6442 */
6443 @Override
6444 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6445 enforceModifyPermission();
6446 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447
6448 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006449 if (phone == null) {
6450 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6451 return;
6452 }
6453 try {
6454 phone.carrierActionSetRadioEnabled(enabled);
6455 } catch (Exception e) {
6456 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006459 }
6460 }
6461
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006462 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006463 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6464 * network status based on which carrier apps could apply actions accordingly,
6465 * enable/disable default url handler for example.
6466 *
6467 * @param subId the subscription ID that this action applies to.
6468 * @param report control start/stop reporting the default network status.
6469 * {@hide}
6470 */
6471 @Override
6472 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6473 enforceModifyPermission();
6474 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475
6476 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006477 if (phone == null) {
6478 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6479 return;
6480 }
6481 try {
6482 phone.carrierActionReportDefaultNetworkStatus(report);
6483 } catch (Exception e) {
6484 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006487 }
6488 }
6489
6490 /**
fionaxud9622282017-07-17 17:51:30 -07006491 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6492 * @param subId the subscription ID that this action applies to.
6493 * {@hide}
6494 */
6495 @Override
6496 public void carrierActionResetAll(int subId) {
6497 enforceModifyPermission();
6498 final Phone phone = getPhone(subId);
6499 if (phone == null) {
6500 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6501 return;
6502 }
6503 try {
6504 phone.carrierActionResetAll();
6505 } catch (Exception e) {
6506 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6507 }
6508 }
6509
6510 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006511 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6512 * bug report is being generated.
6513 */
6514 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006515 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006516 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6517 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006518 writer.println("Permission Denial: can't dump Phone from pid="
6519 + Binder.getCallingPid()
6520 + ", uid=" + Binder.getCallingUid()
6521 + "without permission "
6522 + android.Manifest.permission.DUMP);
6523 return;
6524 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006525 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006526 }
Jack Yueb89b242016-06-22 13:27:47 -07006527
Brad Ebingerdac2f002018-04-03 15:17:52 -07006528 @Override
6529 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6530 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6531 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006532 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6533 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006534 }
6535
Jack Yueb89b242016-06-22 13:27:47 -07006536 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006537 * Get aggregated video call data usage since boot.
6538 *
6539 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6540 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006541 * {@hide}
6542 */
6543 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006544 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006545 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6546 null);
6547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 // NetworkStatsService keeps tracking the active network interface and identity. It
6551 // records the delta with the corresponding network identity.
6552 // We just return the total video call data usage snapshot since boot.
6553 Phone phone = getPhone(subId);
6554 if (phone != null) {
6555 return phone.getVtDataUsage(perUidStats);
6556 }
6557 return null;
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006560 }
Jack Yueb89b242016-06-22 13:27:47 -07006561 }
Jack Yu75ab2952016-07-08 14:29:33 -07006562
6563 /**
6564 * Policy control of data connection. Usually used when data limit is passed.
6565 * @param enabled True if enabling the data, otherwise disabling.
6566 * @param subId Subscription index
6567 * {@hide}
6568 */
6569 @Override
6570 public void setPolicyDataEnabled(boolean enabled, int subId) {
6571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 Phone phone = getPhone(subId);
6576 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006577 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 }
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006581 }
6582 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006583
6584 /**
6585 * Get Client request stats
6586 * @return List of Client Request Stats
6587 * @hide
6588 */
6589 @Override
6590 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006592 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006593 return null;
6594 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006595 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 if (phone != null) {
6600 return phone.getClientRequestStats();
6601 }
6602
6603 return null;
6604 } finally {
6605 Binder.restoreCallingIdentity(identity);
6606 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006607 }
6608
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006609 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006610 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006611 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006612 }
Jack Yueb4124c2017-02-16 15:32:43 -08006613
6614 /**
Grace Chen70990072017-03-24 17:21:30 -07006615 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006616 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006617 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006618 * @param state State of SIM (power down, power up, pass through)
6619 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6620 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6621 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006622 *
6623 **/
6624 @Override
Grace Chen70990072017-03-24 17:21:30 -07006625 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006626 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006627 Phone phone = PhoneFactory.getPhone(slotIndex);
6628
vagdeviaf9a5b92018-08-15 16:01:53 -07006629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006634 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 }
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006638 }
6639 }
Shuo Qiandd210312017-04-12 22:11:33 +00006640
Tyler Gunn65d45c22017-06-05 11:22:26 -07006641 private boolean isUssdApiAllowed(int subId) {
6642 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006643 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006644 if (configManager == null) {
6645 return false;
6646 }
6647 PersistableBundle pb = configManager.getConfigForSubId(subId);
6648 if (pb == null) {
6649 return false;
6650 }
6651 return pb.getBoolean(
6652 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6653 }
6654
Shuo Qiandd210312017-04-12 22:11:33 +00006655 /**
6656 * Check if phone is in emergency callback mode
6657 * @return true if phone is in emergency callback mode
6658 * @param subId sub id
6659 */
goneil9c5f4872017-12-05 14:07:56 -08006660 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006661 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006662 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 if (phone != null) {
6668 return phone.isInEcm();
6669 } else {
6670 return false;
6671 }
6672 } finally {
6673 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006674 }
6675 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006676
6677 /**
6678 * Get the current signal strength information for the given subscription.
6679 * Because this information is not updated when the device is in a low power state
6680 * it should not be relied-upon to be current.
6681 * @param subId Subscription index
6682 * @return the most recent cached signal strength info from the modem
6683 */
6684 @Override
6685 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 Phone p = getPhone(subId);
6689 if (p == null) {
6690 return null;
6691 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 return p.getSignalStrength();
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006697 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006698
Pengquan Meng77b7f132018-08-22 14:49:57 -07006699 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006700 * Get the current modem radio state for the given slot.
6701 * @param slotIndex slot index.
6702 * @param callingPackage the name of the package making the call.
6703 * @return the current radio power state from the modem
6704 */
6705 @Override
6706 public int getRadioPowerState(int slotIndex, String callingPackage) {
6707 Phone phone = PhoneFactory.getPhone(slotIndex);
6708 if (phone != null) {
6709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6710 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6711 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6712 }
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 return phone.getRadioPowerState();
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
6720 }
6721 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6722 }
6723
6724 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006725 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6726 *
6727 * <p>Requires one of the following permissions:
6728 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6729 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6730 * privileges.
6731 *
6732 * @param subId subscription id
6733 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6734 * {@code false}.
6735 */
6736 @Override
6737 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006738 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6739 null /* message */);
6740
Pengquan Menga1bb6272018-09-06 09:59:22 -07006741 boolean isEnabled = false;
6742 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006743 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006744 Phone phone = getPhone(subId);
6745 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006746 } catch (Exception e) {
6747 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6748 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006749 } finally {
6750 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006752 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006753 }
6754
6755
6756 /**
6757 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6758 *
6759 * <p> Requires permission:
6760 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6761 * privileges.
6762 *
6763 * @param subId subscription id
6764 * @param isEnabled {@code true} means enable, {@code false} means disable.
6765 */
6766 @Override
6767 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6769 mApp, subId, "setDataRoamingEnabled");
6770
Pengquan Menga1bb6272018-09-06 09:59:22 -07006771 final long identity = Binder.clearCallingIdentity();
6772 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006773 Phone phone = getPhone(subId);
6774 if (phone != null) {
6775 phone.setDataRoamingEnabled(isEnabled);
6776 }
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006779 }
6780 }
6781
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006782 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006783 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006784 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6785 mApp, subId, "isManualNetworkSelectionAllowed");
6786
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006787 boolean isAllowed = true;
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006790 Phone phone = getPhone(subId);
6791 if (phone != null) {
6792 isAllowed = phone.isCspPlmnEnabled();
6793 }
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
6796 }
6797 return isAllowed;
6798 }
6799
6800 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006801 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006802 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006803 try {
6804 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006805 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006806 } catch (SecurityException e) {
6807 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6808 // has carrier privileges on an active UICC
6809 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6810 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006811 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006812 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006813 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006817 UiccController uiccController = UiccController.getInstance();
6818 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006819 if (hasReadPermission) {
6820 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006821 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006822
6823 // Remove private info if the caller doesn't have access
6824 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6825 for (UiccCardInfo cardInfo : cardInfos) {
6826 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6827 // is available
6828 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6829 if (card == null || card.getUiccProfile() == null) {
6830 // assume no access if the card or profile is unavailable
6831 filteredInfos.add(cardInfo.getUnprivileged());
6832 continue;
6833 }
6834 UiccProfile profile = card.getUiccProfile();
6835 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6836 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6837 filteredInfos.add(cardInfo);
6838 } else {
6839 filteredInfos.add(cardInfo.getUnprivileged());
6840 }
6841 }
6842 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
6846 }
6847
6848 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006849 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006850 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 final long identity = Binder.clearCallingIdentity();
6853 try {
6854 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6855 if (slots == null) {
6856 Rlog.i(LOG_TAG, "slots is null.");
6857 return null;
6858 }
6859
6860 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6861 for (int i = 0; i < slots.length; i++) {
6862 UiccSlot slot = slots[i];
6863 if (slot == null) {
6864 continue;
6865 }
6866
Jordan Liu7be7e652019-05-06 18:55:02 +00006867 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 UiccCard card = slot.getUiccCard();
6869 if (card != null) {
6870 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006871 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006872 cardId = slot.getEid();
6873 if (TextUtils.isEmpty(cardId)) {
6874 cardId = slot.getIccId();
6875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 }
6877
Jordan Liu857451f2019-05-09 16:35:35 -07006878 if (cardId != null) {
6879 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6880 // if cardId is an EID, it's all digits so this is fine
6881 cardId = IccUtils.stripTrailingFs(cardId);
6882 }
6883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 int cardState = 0;
6885 switch (slot.getCardState()) {
6886 case CARDSTATE_ABSENT:
6887 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6888 break;
6889 case CARDSTATE_PRESENT:
6890 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6891 break;
6892 case CARDSTATE_ERROR:
6893 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6894 break;
6895 case CARDSTATE_RESTRICTED:
6896 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6897 break;
6898 default:
6899 break;
6900
6901 }
6902
6903 infos[i] = new UiccSlotInfo(
6904 slot.isActive(),
6905 slot.isEuicc(),
6906 cardId,
6907 cardState,
6908 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006909 slot.isExtendedApduSupported(),
6910 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 }
6912 return infos;
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006915 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006916 }
6917
6918 @Override
6919 public boolean switchSlots(int[] physicalSlots) {
6920 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6925 } finally {
6926 Binder.restoreCallingIdentity(identity);
6927 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006928 }
Jack Yu4c988042018-02-27 15:30:01 -08006929
6930 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006931 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 return UiccController.getInstance().getCardIdForDefaultEuicc();
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
6937 }
6938 }
6939
6940 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006941 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6942 enforceModifyPermission();
6943 final Phone phone = getPhone(subId);
6944 if (phone == null) {
6945 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6946 return;
6947 }
6948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 phone.setRadioIndicationUpdateMode(filters, mode);
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
Jack Yu4c988042018-02-27 15:30:01 -08006955 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006956
6957 /**
goneil47ffb6e2018-04-06 15:40:58 -07006958 * A test API to reload the UICC profile.
6959 *
6960 * <p>Requires that the calling app has permission
6961 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6962 * @hide
6963 */
6964 @Override
6965 public void refreshUiccProfile(int subId) {
6966 enforceModifyPermission();
6967
6968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return;
6973 }
6974 UiccCard uiccCard = phone.getUiccCard();
6975 if (uiccCard == null) {
6976 return;
6977 }
6978 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6979 if (uiccProfile == null) {
6980 return;
6981 }
6982 uiccProfile.refresh();
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
6986 }
6987
6988 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006989 * Returns false if the mobile data is disabled by default, otherwise return true.
6990 */
6991 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09006992 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006993 }
6994
6995 /**
6996 * Returns true if the data roaming is enabled by default, i.e the system property
6997 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6998 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6999 */
7000 private boolean getDefaultDataRoamingEnabled(int subId) {
7001 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007002 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007003 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007004 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7005 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7006 return isDataRoamingEnabled;
7007 }
7008
7009 /**
7010 * Returns the default network type for the given {@code subId}, if the default network type is
7011 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7012 */
7013 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007014 List<Integer> list = TelephonyProperties.default_network();
7015 int phoneId = mSubscriptionController.getPhoneId(subId);
7016 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7017 return list.get(phoneId);
7018 }
7019 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007020 }
fionaxua13278b2018-03-21 00:08:13 -07007021
7022 @Override
7023 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007024 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 final Phone phone = getPhone(subId);
7030 if (phone == null) {
7031 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7032 return;
7033 }
chen xueaba88a2019-03-15 13:15:10 -07007034 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7035 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 } finally {
7037 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007038 }
fionaxua13278b2018-03-21 00:08:13 -07007039 }
7040
7041 @Override
7042 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007043 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 final Phone phone = getPhone(subId);
7048 if (phone == null) {
7049 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7050 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7051 }
7052 return phone.getCarrierIdListVersion();
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007055 }
fionaxua13278b2018-03-21 00:08:13 -07007056 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007057
7058 @Override
7059 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7061 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7062 return -1;
7063 }
7064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
7071 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007072
7073 @Override
7074 public int getCdmaRoamingMode(int subId) {
7075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7076 mApp, subId, "getCdmaRoamingMode");
7077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
7084 }
7085
7086 @Override
7087 public boolean setCdmaRoamingMode(int subId, int mode) {
7088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7089 mApp, subId, "setCdmaRoamingMode");
7090
7091 final long identity = Binder.clearCallingIdentity();
7092 try {
7093 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
7096 }
7097 }
7098
7099 @Override
7100 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7102 mApp, subId, "setCdmaSubscriptionMode");
7103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
7110 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007111
sqianc5eccab2018-10-19 18:46:41 -07007112 @Override
sqian8c685422019-02-22 15:55:18 -08007113 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007114 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007116 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007117 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7118 }
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
sqian854d44b2018-12-12 16:48:18 -08007121 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7122 for (Phone phone: PhoneFactory.getPhones()) {
7123 if (phone.getEmergencyNumberTracker() != null
7124 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7125 emergencyNumberListInternal.put(
7126 phone.getSubId(),
7127 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7128 }
sqian11b7a0e2018-12-05 18:48:28 -08007129 }
sqian854d44b2018-12-12 16:48:18 -08007130 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
sqianc5eccab2018-10-19 18:46:41 -07007134 }
7135
7136 @Override
sqian8c685422019-02-22 15:55:18 -08007137 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007138 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007139 if (!exactMatch) {
7140 TelephonyPermissions
7141 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007142 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007143 }
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
sqian854d44b2018-12-12 16:48:18 -08007146 for (Phone phone: PhoneFactory.getPhones()) {
7147 if (phone.getEmergencyNumberTracker() != null
7148 && phone.getEmergencyNumberTracker() != null) {
7149 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7150 number, exactMatch)) {
7151 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007152 }
7153 }
sqian11b7a0e2018-12-05 18:48:28 -08007154 }
7155 return false;
7156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
7159 }
7160
sqianf4ca7ed2019-01-15 18:32:07 -08007161 /**
7162 * Update emergency number list for test mode.
7163 */
7164 @Override
7165 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7167 "updateEmergencyNumberListTestMode");
7168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 for (Phone phone: PhoneFactory.getPhones()) {
7172 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7173 if (tracker != null) {
7174 tracker.executeEmergencyNumberTestModeCommand(action, num);
7175 }
7176 }
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 /**
7183 * Get the full emergency number list for test mode.
7184 */
7185 @Override
7186 public List<String> getEmergencyNumberListTestMode() {
7187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7188 "getEmergencyNumberListTestMode");
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 Set<String> emergencyNumbers = new HashSet<>();
7193 for (Phone phone: PhoneFactory.getPhones()) {
7194 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7195 if (tracker != null) {
7196 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7197 emergencyNumbers.add(num.getNumber());
7198 }
7199 }
7200 }
7201 return new ArrayList<>(emergencyNumbers);
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
7205 }
7206
chen xud6b45bd2018-10-30 22:27:10 -07007207 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007208 public int getEmergencyNumberDbVersion(int subId) {
7209 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 final Phone phone = getPhone(subId);
7214 if (phone == null) {
7215 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7216 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7217 }
7218 return phone.getEmergencyNumberDbVersion();
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
7221 }
7222 }
7223
7224 @Override
7225 public void notifyOtaEmergencyNumberDbInstalled() {
7226 enforceModifyPermission();
7227
7228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 for (Phone phone: PhoneFactory.getPhones()) {
7231 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7232 if (tracker != null) {
7233 tracker.updateOtaEmergencyNumberDatabase();
7234 }
7235 }
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
7240
7241 @Override
7242 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7243 enforceActiveEmergencySessionPermission();
7244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 for (Phone phone: PhoneFactory.getPhones()) {
7248 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7249 if (tracker != null) {
7250 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7251 }
7252 }
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
7258 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007259 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7260 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7261 Phone phone = getPhone(subId);
7262 if (phone == null) {
7263 return null;
7264 }
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 UiccProfile profile = UiccController.getInstance()
7268 .getUiccProfileForPhone(phone.getPhoneId());
7269 if (profile != null) {
7270 return profile.getCertsFromCarrierPrivilegeAccessRules();
7271 }
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274 }
7275 return null;
7276 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007277
7278 /**
7279 * Enable or disable a modem stack.
7280 */
7281 @Override
7282 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7283 enforceModifyPermission();
7284
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 Phone phone = PhoneFactory.getPhone(slotIndex);
7288 if (phone == null) {
7289 return false;
7290 } else {
7291 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7292 }
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
7296 }
Michelecea4cf22018-12-21 15:00:11 -08007297
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007298 /**
7299 * Whether a modem stack is enabled or not.
7300 */
7301 @Override
7302 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7303 Phone phone = PhoneFactory.getPhone(slotIndex);
7304 if (phone == null) return false;
7305
7306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7307 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7308 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7309 }
7310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007313 try {
7314 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7315 } catch (NoSuchElementException ex) {
7316 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7317 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
7321 }
7322
Michelecea4cf22018-12-21 15:00:11 -08007323 @Override
Michele0ea7d782019-03-19 14:58:42 -07007324 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007325 enforceModifyPermission();
7326
7327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007330 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007331 .commit();
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
7335 }
7336
7337 @Override
Michele0ea7d782019-03-19 14:58:42 -07007338 @TelephonyManager.IsMultiSimSupportedResult
7339 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007341 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7342 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007343 }
Michelecea4cf22018-12-21 15:00:11 -08007344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
Michele0ea7d782019-03-19 14:58:42 -07007347 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007348 } finally {
7349 Binder.restoreCallingIdentity(identity);
7350 }
7351 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007352
Michele0ea7d782019-03-19 14:58:42 -07007353 @TelephonyManager.IsMultiSimSupportedResult
7354 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007355 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7356 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7357 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007358 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7359 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007360 }
7361 // Check if the hardware supports multisim functionality. If usage of multisim is not
7362 // supported by the modem, indicate that it is restricted.
7363 PhoneCapability staticCapability =
7364 mPhoneConfigurationManager.getStaticPhoneCapability();
7365 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007366 loge("isMultiSimSupportedInternal: no static configuration available");
7367 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007368 }
7369 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007370 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7371 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007372 }
7373 // Check if support of multiple SIMs is restricted by carrier
7374 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007375 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007376 }
7377
Michele0ea7d782019-03-19 14:58:42 -07007378 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007379 }
7380
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007381 /**
7382 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007383 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7384 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7385 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007386 * @param numOfSims number of active sims we want to switch to
7387 */
7388 @Override
7389 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007390 if (numOfSims == 1) {
7391 enforceModifyPermission();
7392 } else {
7393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7394 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7395 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007396 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007397
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007398 try {
Michele30b57b22019-03-01 12:01:14 -08007399 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007400 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007401 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7402 return;
7403 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007404 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007410 @Override
7411 public boolean isApplicationOnUicc(int subId, int appType) {
7412 enforceReadPrivilegedPermission("isApplicationOnUicc");
7413 Phone phone = getPhone(subId);
7414 if (phone == null) {
7415 return false;
7416 }
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 UiccCard uiccCard = phone.getUiccCard();
7420 if (uiccCard == null) {
7421 return false;
7422 }
7423 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7424 if (uiccProfile == null) {
7425 return false;
7426 }
7427 if (TelephonyManager.APPTYPE_SIM <= appType
7428 && appType <= TelephonyManager.APPTYPE_ISIM) {
7429 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7430 }
7431 return false;
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
7435 }
7436
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007437 /**
chen xub4baa772019-04-03 10:23:41 -07007438 * Get whether making changes to modem configurations will trigger reboot.
7439 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007440 */
7441 @Override
chen xub4baa772019-04-03 10:23:41 -07007442 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7444 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7445 return false;
7446 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 }
7454
Nathan Harold29f5f052019-02-15 13:41:57 -08007455 private void updateModemStateMetrics() {
7456 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7457 // TODO: check the state for each modem if the api is ready.
7458 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7459 }
7460
Pengquan Meng3889a572019-01-23 11:16:29 -08007461 @Override
7462 public int[] getSlotsMapping() {
7463 enforceReadPrivilegedPermission("getSlotsMapping");
7464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7468 // All logical slots should have a mapping to a physical slot.
7469 int[] logicalSlotsMapping = new int[phoneCount];
7470 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7471 for (int i = 0; i < slotInfos.length; i++) {
7472 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7473 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7474 }
7475 }
7476 return logicalSlotsMapping;
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479 }
7480 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007481
7482 /**
7483 * Get the IRadio HAL Version
7484 */
7485 @Override
7486 public int getRadioHalVersion() {
7487 Phone phone = getDefaultPhone();
7488 if (phone == null) return -1;
7489 HalVersion hv = phone.getHalVersion();
7490 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7491 return hv.major * 100 + hv.minor;
7492 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007493
7494 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007495 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7496 * corresponding network requests on a subId.
7497 *
7498 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007499 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007500 * 2) APN is un-metered for this subscription, or
7501 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7502 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7503 *
7504 * @return whether data is allowed for a apn type.
7505 *
7506 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007507 */
7508 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007509 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007510 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7511 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007512
7513 // Now that all security checks passes, perform the operation as ourselves.
7514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 Phone phone = getPhone(subId);
7517 if (phone == null) return false;
7518
Jack Yu41407ee2019-05-13 16:54:09 -07007519 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007520 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
7524 }
7525
7526 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007527 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007528 enforceReadPrivilegedPermission("isApnMetered");
7529
7530 // Now that all security checks passes, perform the operation as ourselves.
7531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 Phone phone = getPhone(subId);
7534 if (phone == null) return true; // By default return true.
7535
Jack Yu41407ee2019-05-13 16:54:09 -07007536 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
7540 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007541
7542 @Override
7543 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7544 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7545 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7546 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7547 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7548 }
7549 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7550 Intent intent = new Intent();
7551 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7552 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7553 // Bring up choose default SMS subscription dialog right now
7554 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7555 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7556 mApp.startActivity(intent);
7557 }
chen xud5ca2d52019-05-28 15:20:57 -07007558
7559 @Override
7560 public String getMmsUAProfUrl(int subId) {
7561 //TODO investigate if this API should require proper permission check in R b/133791609
7562 final long identity = Binder.clearCallingIdentity();
7563 try {
7564 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7565 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
7569 }
7570
7571 @Override
7572 public String getMmsUserAgent(int subId) {
7573 //TODO investigate if this API should require proper permission check in R b/133791609
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7577 .getString(com.android.internal.R.string.config_mms_user_agent);
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
7580 }
7581 }
Jack Yub07d4972019-05-28 16:12:25 -07007582
7583 @Override
7584 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7585 enforceModifyPermission();
7586
7587 // Now that all security checks passes, perform the operation as ourselves.
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 Phone phone = getPhone(subId);
7591 if (phone == null) return false;
7592
7593 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
7597 }
7598
7599 @Override
7600 public boolean isDataAllowedInVoiceCall(int subId) {
7601 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7602
7603 // Now that all security checks passes, perform the operation as ourselves.
7604 final long identity = Binder.clearCallingIdentity();
7605 try {
7606 Phone phone = getPhone(subId);
7607 if (phone == null) return false;
7608
7609 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007614
7615 /**
7616 * Updates whether conference event pacakge handling is enabled.
7617 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7618 * otherwise.
7619 */
7620 @Override
7621 public void setCepEnabled(boolean isCepEnabled) {
7622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7623
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7627 for (Phone phone : PhoneFactory.getPhones()) {
7628 Phone defaultPhone = phone.getImsPhone();
7629 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7630 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7631 ImsPhoneCallTracker imsPhoneCallTracker =
7632 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7633 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7634 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7635 + imsPhone.getMsisdn());
7636 }
7637 }
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
7641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007642}